cross compile docker images with docker buildx
This commit is contained in:
parent
5d198e21ff
commit
1092e92e19
3 changed files with 63 additions and 18 deletions
|
@ -1,11 +1,12 @@
|
||||||
variables:
|
variables:
|
||||||
DOCKER_TLS_CERTDIR: "/certs"
|
DOCKER_TLS_CERTDIR: "/certs"
|
||||||
|
DOCKER_DRIVER: overlay2
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker:20.10.0-dind
|
- docker:dind
|
||||||
|
|
||||||
.build: &build
|
.build: &build
|
||||||
image: docker:20.10.0
|
image: docker:latest
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}"
|
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}"
|
||||||
|
@ -15,6 +16,25 @@ services:
|
||||||
- docker push "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}"
|
- docker push "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}"
|
||||||
- if [[ "${CI_COMMIT_REF_SLUG}" == "main" ]]; then docker tag "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}" "${CI_REGISTRY_IMAGE}/${NAME}:latest" && docker push "${CI_REGISTRY_IMAGE}/${NAME}:latest"; fi
|
- if [[ "${CI_COMMIT_REF_SLUG}" == "main" ]]; then docker tag "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}" "${CI_REGISTRY_IMAGE}/${NAME}:latest" && docker push "${CI_REGISTRY_IMAGE}/${NAME}:latest"; fi
|
||||||
|
|
||||||
|
.docker-multiarch-image: &docker-multiarch-image
|
||||||
|
image: jdrouet/docker-with-buildx:stable
|
||||||
|
stage: build
|
||||||
|
tags: [docker-builder]
|
||||||
|
before_script: # per recommendations from https://github.com/docker/buildx/issues/495#issuecomment-754200673
|
||||||
|
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
||||||
|
- docker buildx create --name cibuilder --driver docker-container --use
|
||||||
|
- docker buildx inspect --bootstrap
|
||||||
|
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}"
|
||||||
|
script:
|
||||||
|
- docker buildx build --platform "${PLATFORM}" -f "${DOCKERFILE}" -t "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_SHA:0:8}" -t "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}" --push .
|
||||||
|
- if [[ "${CI_COMMIT_REF_SLUG}" == "main" ]]; then docker buildx build --platform "${PLATFORM}" -f "${DOCKERFILE}" -t "${CI_REGISTRY_IMAGE}/${NAME}:latest" --push . ; fi
|
||||||
|
parallel:
|
||||||
|
matrix:
|
||||||
|
- PLATFORM:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64/v8
|
||||||
|
- linux/arm/v7
|
||||||
|
|
||||||
signal-server:
|
signal-server:
|
||||||
image: docker:20.10.0
|
image: docker:20.10.0
|
||||||
stage: build
|
stage: build
|
||||||
|
@ -52,22 +72,20 @@ test-helper:
|
||||||
NAME: "test-helper"
|
NAME: "test-helper"
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
builder-image:x86:
|
signal-cross-builder:
|
||||||
<<: *build
|
<<: *build
|
||||||
variables:
|
variables:
|
||||||
DOCKERFILE: "signald-builder.Dockerfile"
|
DOCKERFILE: "signald-cross-builder.Dockerfile"
|
||||||
NAME: "signald-builder-x86"
|
NAME: "signald-cross-builder"
|
||||||
|
|
||||||
builder-image:aarch64:
|
builder-image-alpine:
|
||||||
<<: *build
|
<<: *docker-multiarch-image
|
||||||
tags: [arm-docker-builder]
|
|
||||||
variables:
|
|
||||||
DOCKERFILE: "signald-builder.Dockerfile"
|
|
||||||
NAME: "signald-builder-arm"
|
|
||||||
|
|
||||||
builder-image-alpine:aarch64:
|
|
||||||
<<: *build
|
|
||||||
tags: [arm-docker-builder]
|
|
||||||
variables:
|
variables:
|
||||||
DOCKERFILE: "signald-builder-alpine.Dockerfile"
|
DOCKERFILE: "signald-builder-alpine.Dockerfile"
|
||||||
NAME: "signald-builder-alpine-arm"
|
NAME: "signald-builder-alpine-arm"
|
||||||
|
|
||||||
|
signald-builder:
|
||||||
|
<<: *docker-multiarch-image
|
||||||
|
variables:
|
||||||
|
DOCKERFILE: "signald-builder.Dockerfile"
|
||||||
|
NAME: "signald-builder"
|
|
@ -1,6 +1,6 @@
|
||||||
FROM debian:latest
|
FROM debian:latest
|
||||||
RUN dpkg --add-architecture armhf && dpkg --add-architecture arm64
|
|
||||||
ADD apt-signing-key.asc /tmp/apt-signing-key.asc
|
ADD apt-signing-key.asc /tmp/apt-signing-key.asc
|
||||||
|
RUN for p in dpkg-split dpkg-deb tar rm; do ln -s /usr/bin/$p /usr/sbin/$p; done
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
gpg \
|
gpg \
|
||||||
dpkg-dev \
|
dpkg-dev \
|
||||||
|
@ -16,8 +16,6 @@ RUN apt-get update && apt-get install -y \
|
||||||
jq \
|
jq \
|
||||||
aptly \
|
aptly \
|
||||||
build-essential \
|
build-essential \
|
||||||
crossbuild-essential-armhf \
|
|
||||||
crossbuild-essential-arm64 \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY deb-scripts/release-deb.sh /usr/bin/release-deb
|
COPY deb-scripts/release-deb.sh /usr/bin/release-deb
|
||||||
|
|
29
signald-cross-builder.Dockerfile
Normal file
29
signald-cross-builder.Dockerfile
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
FROM debian:latest
|
||||||
|
RUN dpkg --add-architecture armhf && dpkg --add-architecture arm64
|
||||||
|
ADD apt-signing-key.asc /tmp/apt-signing-key.asc
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
gpg \
|
||||||
|
dpkg-dev \
|
||||||
|
apt-utils \
|
||||||
|
wget \
|
||||||
|
dh-make \
|
||||||
|
debhelper \
|
||||||
|
javahelper \
|
||||||
|
gradle \
|
||||||
|
default-jdk-headless \
|
||||||
|
git-buildpackage \
|
||||||
|
gradle-debian-helper \
|
||||||
|
jq \
|
||||||
|
aptly \
|
||||||
|
build-essential \
|
||||||
|
crossbuild-essential-armhf \
|
||||||
|
crossbuild-essential-arm64 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY deb-scripts/release-deb.sh /usr/bin/release-deb
|
||||||
|
COPY deb-scripts/get-component.sh /usr/bin/get-component
|
||||||
|
COPY deb-scripts/repo-cron.sh /usr/bin/repo-cron
|
||||||
|
|
||||||
|
RUN adduser signald
|
||||||
|
USER signald
|
||||||
|
RUN gpg --no-default-keyring --keyring trustedkeys.gpg --import /tmp/apt-signing-key.asc
|
Loading…
Reference in a new issue