user122222
user122222

Reputation: 2419

Docker doesn't work when using getsentry/sentry-cli

I want to upload my frontend to sentry, but I need to get the folder using docker commands. However when I use image: getsentry/sentry-cli docker doesn't works and e.g. in before_script I get error that docker doesn't exist

sentry_job:
  stage: sentry_job
  image: getsentry/sentry-cli
  services:
    - docker:18-dind
  before_script:
    - docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" registry.gitlab.cz
  script:
   # script...
.   # Get the dist folder from the image
- mkdir frontend_dist
- docker run --rm -v $PWD/frontend_dist:/mounted --entrypoint="" $IMAGE /bin/sh -c "cp /frontend/dist /mounted"
- ls frontend_dist

  tags:
    - dind

How do I fix that?

Upvotes: 1

Views: 868

Answers (1)

ErikMD
ErikMD

Reputation: 14723

To achieve what you want, you need to use a single job (to have the same build context) and specify docker:stable as the job image (along with docker:stable-dind as a service).

This setup is called docker-in-docker and this is the standard way to allow a GitLab CI script to run docker commands (see doc).

Thus, you could slightly adapt your .gitlab-ci.yml code like this:

sentry_job:
  stage: sentry_job
  image: docker:stable
  services:
    - docker:stable-dind
  variables:
    IMAGE: "${CI_REGISTRY_IMAGE}:latest"
  before_script:
    - docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" registry.gitlab.cz
  script:
    - git pull "$IMAGE"
    - mkdir -v frontend_dist
    - docker run --rm -v "$PWD/frontend_dist:/mounted" --entrypoint="" "$IMAGE" /bin/sh -c "cp -v /frontend/dist /mounted"
    - ls frontend_dist
    - git pull getsentry/sentry-cli
    - docker run --rm -v "$PWD/frontend_dist:/work" getsentry/sentry-cli
  tags:
    - dind

Note: the git pull commands are optional (they ensure Docker will use the latest version of the images).

Also, you may need to change the definition of variable IMAGE.

Upvotes: 1

Related Questions