Search code examples
gitlab-cialpine-linuxpython-black

GitLab CI image: alpine "apk: command not found" error


I'm trying to follow this tutorial to enable formatting checks using black in GitLab CI.

To make things simpler, I've transferred the code from .lint-ci.yml over to .gitlab-ci.yml. The tag of the shared runner that I'm using is gitlab-ci. I'm getting the following error when the pipeline gets run:

bash: line 80: apk: command not found
ERROR: Job failed: exit status 1

Obviously, that's getting thrown for the apk --no-cache add py3-pip python3-dev gcc linux-headers musl-dev libffi-dev openssl-dev git line.

Here's the .gitlab-ci.yml file:

formatter:
  stage: build
  tags:
    - gitlab-ci
  image: alpine
  only:
    - branches
  before_script:
    - apk --no-cache add py3-pip python3-dev gcc linux-headers musl-dev libffi-dev openssl-dev git
    - pip install black
  script:
    - black . --check
  allow_failure: false

Can someone help me solve this issue?

As requested by @slauth, here's the full output of the job:

Running with gitlab-runner 11.6.1 (id1)
  on gitlab-ci -CzBAN4M
Using Shell executor...
Running on gitserver...
Fetching changes...
HEAD is now at id2 a
From http://gitserver....
Checking out id3 as gitlabci...
Skipping Git submodules setup
$ apk --no-cache add py3-pip python3-dev gcc linux-headers musl-dev libffi-dev openssl-dev git
bash: line 80: apk: command not found
ERROR: Job failed: exit status 1

Solution

  • Your runner is using the "Shell" executor which does not support the image: configuration, see this compatibility chart.