gpt4 book ai didi

GitLab CI - 尝试使用 docker buildx 为 ARM64 构建

转载 作者:行者123 更新时间:2023-12-02 23:13:26 24 4
gpt4 key购买 nike

尝试将 docker buildx 与 GitLabs 共享运行程序结合使用来构建可在我的 Raspberry Pi 上运行的 Docker 镜像。作业失败,提示 git 不在 PATH 中,但 git 安装在 image: docker:stable-git 中。任何已知的修复或更好的方法来构建 ARM64 兼容的图像,而无需在 Raspberry Pi 本身上构建? (由于 CPU 使用率,RPi 在其上构建时变得不可用)

deploy:
image: docker:stable-git
stage: deploy
services:
- docker:dind
before_script:
- export DOCKER_BUILDKIT=1
- export DOCKER_CLI_EXPERIMENTAL=enabled
- docker build --platform=local -o . git://github.com/docker/buildx
- mv buildx ~/.docker/cli-plugins/docker-buildx
script:
- docker buildx build --platform linux/amd64,linux/arm64 -t $CI_REGISTRY_IMAGE .
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE
$ export DOCKER_BUILDKIT=1
$ export DOCKER_CLI_EXPERIMENTAL=enabled
$ docker build --platform=local -o . git://github.com/docker/buildx
#1 [internal] load git source git://github.com/docker/buildx
#1 ERROR: failed to init repo at /var/lib/docker/overlay2/xxx/diff: exec: "git": executable file not found in $PATH
------
> [internal] load git source git://github.com/docker/buildx:
------
failed to solve with frontend dockerfile.v0: failed to resolve dockerfile: failed to build LLB: failed to load cache key: failed to init repo at /var/lib/docker/overlay2/xxx/diff: exec: "git": executable file not found in $PATH
ERROR: Job failed: exit code 1

最佳答案

问题似乎是由于 git 未安装在 docker:dind 中而导致构建失败

能够通过克隆 Docker/BuildX 解决该问题在一个单独的阶段,在其上运行 docker build,然后使用工件将其导出到部署阶段。

buildx:
image: docker:19.03-git
stage: buildx
variables:
GIT_STRATEGY: none
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:
image: docker:19.03
stage: deploy
services:
- name: docker:19.03-dind
command: ["--experimental"]
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
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker buildx create --use --name mybuilder
- docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --push -t $CI_REGISTRY_IMAGE .

由于 GitLab 对免费帐户所做的更改以及 j0nl1 发布的评论,我决定用有关在 CircleCI 中使用 BuildX 的信息更新我的答案。和 Yajo

您可以下载 BuildX 二进制文件并通过执行以下操作在 CircleCI 作业中使用它

jobs:
build-and-push:
executor: docker/machine
steps:
- checkout
- run:
name: Remove old installation
command: |
sudo systemctl stop docker.service
sudo apt remove docker-ce docker-ce-cli containerd.io
- docker/install-docker:
install-dir: /usr/bin
- run:
name: Restart docker daemon with experimental features
command: |
sudo bash -c 'echo "{\"experimental\":true}" > /etc/docker/daemon.json'
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
$SUDO systemctl unmask docker.service
$SUDO systemctl unmask docker.socket
$SUDO systemctl start docker.service
- run:
name: Install buildx
command: |
BUILDX_VERSION="v0.4.1"

curl -sSLo docker-buildx "https://github.com/docker/buildx/releases/download/$BUILDX_VERSION/buildx-$BUILDX_VERSION.linux-amd64"
chmod a+x docker-buildx
mkdir -p ~/.docker/cli-plugins
mv docker-buildx ~/.docker/cli-plugins/docker-buildx

docker version
docker buildx install
- docker/check:
registry: $DOCKER_REGISTRY
- run:
name: Create buildx profile
command: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use --name mybuilder
- docker/build:
registry: $DOCKER_REGISTRY
image: username/repo
tag: latest
extra_build_args: --platform linux/amd64,linux/arm64,linux/arm/v7 --push

关于GitLab CI - 尝试使用 docker buildx 为 ARM64 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58600986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com