Compare commits

..

5 commits

Author SHA1 Message Date
010941fcc7 more typos 2021-07-23 23:01:50 -07:00
84f7822a13 typo 2021-07-23 23:00:27 -07:00
48ef238ceb Allow platform to be selected in image name 2021-07-23 22:45:18 -07:00
Finn
6cb8b5de22 Merge branch 'docker-buildx' into 'main'
cross compile docker image with docker buildx

See merge request signald/infrastructure!2
2021-07-22 07:52:08 +00:00
1092e92e19 cross compile docker images with docker buildx 2021-07-22 00:11:15 -07:00
5 changed files with 77 additions and 141 deletions

View file

@ -1,15 +1,14 @@
variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_DRIVER: overlay2
services:
- docker:20.10.0-dind
- docker:dind
.build: &build
image: docker:20.10.0
image: docker:latest
stage: build
script:
- NAME=${NAME:-${CI_JOB_NAME}}
- DOCKERFILE=${DOCKERFILE:-${CI_JOB_NAME}.Dockerfile}
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}"
- docker build -f "${DOCKERFILE}" -t "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_SHA:0:8}" .
- docker tag "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_SHA:0:8}" "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}"
@ -17,6 +16,26 @@ services:
- 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
.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}"
- export platform_sanatized=$(echo ${PLATFORM:6} | sed 's#/#-#g')
script:
- docker buildx build --platform "${PLATFORM}" -f "${DOCKERFILE}" -t "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_SHA:0:8}" -t "${CI_REGISTRY_IMAGE}/${NAME}-${platform_sanatized}:${CI_COMMIT_SHA:0:8}" -t "${CI_REGISTRY_IMAGE}/${NAME}:${CI_COMMIT_REF_SLUG}" -t "${CI_REGISTRY_IMAGE}/${NAME}-${platform_sanatized}:${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" -t "${CI_REGISTRY_IMAGE}/${NAME}-${platform_sanatized}:latest" --push . ; fi
parallel:
matrix:
- PLATFORM:
- linux/amd64
- linux/arm64/v8
- linux/arm/v7
signal-server:
image: docker:20.10.0
stage: build
@ -33,7 +52,19 @@ signal-server:
allow_failure: true
freebsd-cross-build:
<<: *build
image: docker:20.10.0
stage: build
script:
- apk add git
- git clone https://github.com/wezm/freebsd-cross-build.git
- cd freebsd-cross-build
- echo "RUN apt-get update && apt-get install -y git" >> Dockerfile
- VERSION=$(git rev-parse --short=8 HEAD)
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- docker build -t ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:${VERSION} .
- docker push ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:${VERSION}
- if [[ "${CI_COMMIT_REF_SLUG}" == "main" ]]; then docker tag ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:${VERSION} ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:latest && docker push ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:latest; fi
- echo "docker pull ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME}:${VERSION}"
test-helper:
<<: *build
@ -42,22 +73,20 @@ test-helper:
NAME: "test-helper"
allow_failure: true
builder-image:x86:
signal-cross-builder:
<<: *build
variables:
DOCKERFILE: "signald-builder.Dockerfile"
NAME: "signald-builder-x86"
DOCKERFILE: "signald-cross-builder.Dockerfile"
NAME: "signald-cross-builder"
builder-image:aarch64:
<<: *build
tags: [arm-docker-builder]
variables:
DOCKERFILE: "signald-builder.Dockerfile"
NAME: "signald-builder-arm"
builder-image-alpine:aarch64:
<<: *build
tags: [arm-docker-builder]
builder-image-alpine:
<<: *docker-multiarch-image
variables:
DOCKERFILE: "signald-builder-alpine.Dockerfile"
NAME: "signald-builder-alpine-arm"
signald-builder:
<<: *docker-multiarch-image
variables:
DOCKERFILE: "signald-builder.Dockerfile"
NAME: "signald-builder"

View file

@ -1,15 +0,0 @@
#!/bin/sh
set -e
cd "$1"
BROKEN_LINKS=$(find . -xtype l)
for link in $BROKEN_LINKS; do
src=$(readlink "$link")
if echo "$src" | grep -q '^\.\./\.\./lib/'; then
# Relink without relative part
new_src=$(echo "$src" | sed 's!^\.\./\.\./lib/!!')
ln -vsf "$new_src" "$link"
fi
done

View file

@ -1,105 +0,0 @@
# This is heavily based on https://github.com/wezm/freebsd-cross-build but has been modified to work well with gitlab-ci
FROM debian:10-slim AS build
# TODO: Add ARG for FreeBSD version/image?
# TODO: Add ARG for parallism?
RUN mkdir /freebsd
WORKDIR /freebsd
RUN apt-get -y update && \
apt-get -y install build-essential m4 bison flex libtool automake autoconf autogen pkg-config curl
RUN curl -OL 'http://ftp.swin.edu.au/freebsd/releases/amd64/12.1-RELEASE/base.txz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/binutils/binutils-2.32.tar.xz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/gmp/gmp-6.1.2.tar.xz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/mpfr/mpfr-4.0.2.tar.xz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/mpc/mpc-1.1.0.tar.gz'
RUN curl -OL 'http://ftp.swin.edu.au/gnu/gcc/gcc-6.4.0/gcc-6.4.0.tar.xz'
RUN mkdir -p /src/base /freebsd/x86_64-pc-freebsd12 && \
tar -C /src/base -Jxf base.txz
# Populate the path that gcc will look in for headers and libs
RUN mv /src/base/usr/include /freebsd/x86_64-pc-freebsd12 && \
mv /src/base/usr/lib /freebsd/x86_64-pc-freebsd12 && \
mv /src/base/lib/* /freebsd/x86_64-pc-freebsd12/lib
# These libraries are actually linker scripts (grep -lr ldscript usr)
# https://sourceware.org/binutils/docs/ld/Scripts.html
# Adjust the paths to match their new locations
RUN sed -i'' \
-e 's!/usr/lib/!/freebsd/x86_64-pc-freebsd12/lib/!g' \
-e 's!/lib/libc.so.7!/freebsd/x86_64-pc-freebsd12/lib/libc.so.7!g' \
/freebsd/x86_64-pc-freebsd12/lib/libc.so && \
sed -i'' \
's!/usr/lib/!/freebsd/x86_64-pc-freebsd12/lib/!g' \
/freebsd/x86_64-pc-freebsd12/lib/libc++.so
# Fix symlinks broken by moving libraries
COPY fix-links /src
RUN /src/fix-links /freebsd/x86_64-pc-freebsd12/lib
RUN tar -C /src -Jxf binutils-2.32.tar.xz && \
tar -C /src -Jxf gcc-6.4.0.tar.xz && \
tar -C /src -Jxf gmp-6.1.2.tar.xz && \
tar -C /src -zxf mpc-1.1.0.tar.gz && \
tar -C /src -Jxf mpfr-4.0.2.tar.xz
# Build toolchain
RUN cd /src/binutils-2.32 && \
./configure --enable-libssp --enable-ld --target=x86_64-pc-freebsd12 --prefix=/freebsd && \
make -j7 && \
make install
RUN cd /src/gmp-6.1.2 && \
./configure --prefix=/freebsd --enable-shared --enable-static \
--enable-mpbsd --enable-fft --enable-cxx --host=x86_64-pc-freebsd12 && \
make -j7 && \
make install
RUN cd /src/mpfr-4.0.2 && \
./configure --prefix=/freebsd --with-gnu-ld --enable-static \
--enable-shared --with-gmp=/freebsd --host=x86_64-pc-freebsd12 && \
make -j7 && \
make install
RUN cd /src/mpc-1.1.0/ && \
./configure --prefix=/freebsd --with-gnu-ld \
--enable-static --enable-shared --with-gmp=/freebsd \
--with-mpfr=/freebsd --host=x86_64-pc-freebsd12 &&\
make -j7 && \
make install
RUN mkdir -p /src/gcc-6.4.0/build && \
cd /src/gcc-6.4.0/build && \
../configure --without-headers --with-gnu-as --with-gnu-ld --disable-nls \
--enable-languages=c,c++ --enable-libssp --enable-ld \
--disable-libitm --disable-libquadmath --target=x86_64-pc-freebsd12 \
--prefix=/freebsd --with-gmp=/freebsd \
--with-mpc=/freebsd --with-mpfr=/freebsd --disable-libgomp && \
LD_LIBRARY_PATH=/freebsd/lib make -j7 && \
make install
# Now copy the toolchain to a fresh image
FROM debian:10-slim
COPY --from=build /freebsd /freebsd
env LD_LIBRARY_PATH /freebsd/lib
env PATH /freebsd/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env CC x86_64-pc-freebsd12-gcc
env CPP x86_64-pc-freebsd12-cpp
env AS x86_64-pc-freebsd12-as
env LD x86_64-pc-freebsd12-ld
env AR x86_64-pc-freebsd12-ar
env RANLIB x86_64-pc-freebsd12-ranlib
env HOST x86_64-pc-freebsd12
# A host compiler is needed to link Rust build scripts even when cross compiling:
RUN apt-get update -y && apt-get install -y curl build-essential git
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --target x86_64-unknown-freebsd
RUN mkdir -p /rust/project /rust/target
WORKDIR /rust/project
VOLUME /rust/project
ENV PATH /root/.cargo/bin:/freebsd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Required for the openssl-sys crate:
ENV OPENSSL_DIR /freebsd/x86_64-pc-freebsd12/

View file

@ -1,6 +1,6 @@
FROM debian:latest
RUN dpkg --add-architecture armhf && dpkg --add-architecture arm64
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 \
gpg \
dpkg-dev \
@ -16,8 +16,6 @@ RUN apt-get update && apt-get install -y \
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

View 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