0

我想用 buildx 构建一个多架构映像。这是我的 GitLab CI 管道。第一步我构建代码库:最新图像。此映像具有困难的构建过程,但最终仅包含静态文件。我想在构建 $CI_REGISTRY_IMAGE/nginx:latest 和 $CI_REGISTRY_IMAGE/php:latest 图像时使用这些文件。

当我使用简单的 docker build 时,它的工作正常:

# Part of ./.deploy/nginx/Dockerfile
COPY --from=codebase /app/public /app/public

但是,当我使用 buildx 时出现错误。

我该如何解决这个问题?

Dockerfile:5
--------------------
   3 |     COPY app.conf /etc/nginx/conf.d/default.conf
   4 |     COPY nginx.conf /etc/nginx/nginx.conf
   5 | >>> COPY --from=codebase /app/public /app/public
   6 |     WORKDIR /app
   7 |     
--------------------
error: failed to solve: rpc error: code = Unknown desc = failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

.gitlab-ci.yml

stages:
  - buildx
  - deploy-images

buildx:
  image: docker:19.03-git
  stage: buildx
  variables:
    GIT_STRATEGY: none
    DOCKER_TLS_CERTDIR: ''
    DOCKER_DRIVER: overlay2
  artifacts:
    paths:
      - buildx
    expire_in: 1 hour
  services:
    - docker:19.03-dind
  script:
    - export DOCKER_BUILDKIT=1
    - git clone git://github.com/docker/buildx ./docker-buildx
    - docker build --platform=local -o . ./docker-buildx

deploy-images:
  stage: deploy-images
  image: docker:19.03.5
  services:
    - name: docker:19.03.5-dind
      command: ["--experimental"]
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
    CI_BUILD_ARCHS: "linux/amd64,linux/arm64"
  before_script:
    - mkdir -p ~/.docker/cli-plugins
    - mv buildx ~/.docker/cli-plugins/docker-buildx
    - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    - docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
    - docker buildx create --use --name mybuilder
  script:
    - docker buildx build --platform "$CI_BUILD_ARCHS" -f ./.deploy/codebase/Dockerfile -t codebase:latest .
    - docker buildx build --platform "$CI_BUILD_ARCHS" --push -t $CI_REGISTRY_IMAGE/nginx:latest ./.deploy/nginx/.
    - docker buildx build --platform "$CI_BUILD_ARCHS" --push -t $CI_REGISTRY_IMAGE/php:latest ./.deploy/php/.
  only:
    - master

./.deploy/nginx/Dockerfile

FROM nginx:alpine
COPY app.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=codebase /app/public /app/public
WORKDIR /app
4

0 回答 0