apk cache in gitlab cicd

137 views Asked by At

I have organized my cicd steps via multiple jobs and to provide files necessary in later jobs or to speed up repeated jobs I cache most of the created files inside the job.

While for most things this works as expected I fail with alpine apk caching.

My .gitlab-ci.yml looks the following and is based on https://gist.github.com/Himura2la/dc054311c96d2737f11dbef6880b61b8:

stages:
- prepare
- build

.job_template: &job_config
  variables:
    APK_CACHE_DIR: $CI_PROJECT_DIR/.cache/apk
    APK_PACKAGES:
      bash
  cache:
    key: $CI_COMMIT_REF_SLUG
    paths:
      - $APK_CACHE_DIR
  image: alpine

prepare_alpine_cache:
  <<: *job_config
  stage: prepare
  script:
    - apk update --cache-dir $APK_CACHE_DIR
    - apk add --cache-dir $APK_CACHE_DIR $APK_PACKAGES

do_stuff1:
  <<: *job_config
  stage: build
  script:
    - /bin/bash .gitlab-ci.d/do_stuff1.sh

do_stuff2:
  <<: *job_config
  stage: build
  script:
    - /bin/bash .gitlab-ci.d/do_stuff2.sh

which results in following error:

WARNING: .cache/apk: no matching files. Ensure that the artifact path is relative to the working directory (/builds/my-group/my-project)

I checked the working directory and couldn't find the .cache dir.

Reading https://wiki.alpinelinux.org/wiki/Alpine_Package_Keeper#Local_Cache doesn't help me either since on the Docker Image setup-apkcache is not found.

How to cache the packages between jobs? I've done similar with ubuntu images in the past, but don't want to stick with ubuntu for obvious reasons.

1

There are 1 answers

3
Muravyev Maxim On

You have to create cache folder, please add mkdir -p $APK_CACHE_DIR to prepare_alpine_cache stage.