Docker 在使用 getsentry/sentry-cli 时不起作用
Docker doesn't work when using getsentry/sentry-cli
我想将我的前端上传到 sentry,但我需要使用 docker
命令获取文件夹。但是当我使用 image: getsentry/sentry-cli
docker 不起作用,例如在 before_script
中,我收到 docker 不存在的错误
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
我该如何解决?
要实现你想要的,你需要使用一个单一的作业(具有相同的构建上下文)并指定docker:stable
作为工作 image
(连同 docker:stable-dind
作为 service
)。
此设置称为 docker-in-docker and this is the standard way to allow a GitLab CI script
to run docker
commands (see doc)。
因此,您可以像这样稍微调整 .gitlab-ci.yml
代码:
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
注意:git pull
命令是可选的(它们确保 Docker 将使用最新版本的图像)。
此外,您可能需要更改变量的定义 IMAGE
。
我想将我的前端上传到 sentry,但我需要使用 docker
命令获取文件夹。但是当我使用 image: getsentry/sentry-cli
docker 不起作用,例如在 before_script
中,我收到 docker 不存在的错误
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
我该如何解决?
要实现你想要的,你需要使用一个单一的作业(具有相同的构建上下文)并指定docker:stable
作为工作 image
(连同 docker:stable-dind
作为 service
)。
此设置称为 docker-in-docker and this is the standard way to allow a GitLab CI script
to run docker
commands (see doc)。
因此,您可以像这样稍微调整 .gitlab-ci.yml
代码:
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
注意:git pull
命令是可选的(它们确保 Docker 将使用最新版本的图像)。
此外,您可能需要更改变量的定义 IMAGE
。