使用 Kaniko 在 GitLab CI 上构建以下 Dockerfile,导致错误error pushing image: failed to push to destination eu.gcr.io/stritzke-enterprises/eliah-speech-server:latest: Get https://eu.gcr.io/...: exit status 1
如果我从 Dockerfile 中删除第一个FROM
,RUN
和COPY --from
语句,则会按预期构建和推送 Docker 映像。如果我在本地机器上使用 Docker 执行 Kaniko 构建,一切都会按预期工作。我使用相同的 GCE 服务帐户凭据执行其他 Kaniko 构建并推送到相同的 GitLab CI 运行器上。
基于 GitLab CI 的 Kaniko 构建出了什么问题?
Dockerfile
FROM alpine:latest as alpine
RUN apk add -U --no-cache ca-certificates
FROM scratch
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY binaries/speech-server /speech-server
EXPOSE 8080
ENTRYPOINT ["/speech-server"]
CMD ["serve", "-t", "$GOOGLE_ACCESS_TOKEN"]
GitLab CI 构建阶段
buildDockerImage:
stage: buildImage
dependencies:
- build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
variables:
GOOGLE_APPLICATION_CREDENTIALS: /secret.json
script:
- echo "$GCR_SERVICE_ACCOUNT_KEY" > /secret.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $DOCKER_IMAGE:latest -v debug
only:
- branches
except:
- master