Cross compile docker for arm and arm64

This commit is contained in:
Jonas Leder 2022-02-21 09:51:38 +01:00
parent bc986d7547
commit ccfb317317

View file

@ -1,13 +1,12 @@
docker-build:
# Use the official docker image.
image: docker:latest
image: gitlab.jonasled.de/jonasled/buildx-docker:latest
stage: build
services:
- docker:dind
before_script:
- docker context create build
- docker buildx create build --use
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
@ -17,10 +16,9 @@ docker-build:
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
- docker buildx build --platform linux/amd64,linux/arm,linux/arm64 --push --tag "$CI_REGISTRY_IMAGE${tag}" .
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile
- Dockerfile