From 5cb10d526e7fce789aacccfd0a697ea5f0332552 Mon Sep 17 00:00:00 2001 From: Mirza Krak Date: Mon, 24 Jun 2019 15:05:37 +0000 Subject: [PATCH] parameterize target architecture when creating Docker container So far the assumption has been that we are targeting an arm (32-bit), when we are compiling the Mender client during docker container build. To be able to support other platfors we need to parameterize this, and this commit adds support for arm64. Changelog: Title Signed-off-by: Mirza Krak --- Dockerfile | 22 ++++++++++++++++++---- docker-build | 12 +++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index b19fa37..5b5e49b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,9 @@ RUN apt-get update && apt-get install -y \ # to download mender-artifact wget \ # to download mender-convert and U-Boot sources - git + git \ +# for arm64 support + gcc-aarch64-linux-gnu # Disable sanity checks made by mtools. These checks reject copy/paste operations on converted disk images. RUN echo "mtools_skip_check=1" >> $HOME/.mtoolsrc @@ -61,13 +63,25 @@ RUN go get -d github.com/mendersoftware/mender WORKDIR $GOPATH/src/github.com/mendersoftware/mender RUN git checkout $MENDER_CLIENT_VERSION -ENV CC "arm-buildroot-linux-gnueabihf-gcc" +# Toolchain configuration +ARG toolchain_host +RUN test -n "$toolchain_host" || (echo "Argument 'toolchain_host' is mandatory." && exit 1) +ENV TOOLCHAIN_HOST=${toolchain_host} + +ARG go_flags +RUN test -n "$go_flags" || (echo "Argument 'go_flags' is mandatory." && exit 1) +ENV GO_FLAGS=$go_flags + +RUN test -n "$mender_client_version" || (echo "Argument 'mender_client_version' is mandatory." && exit 1) +ENV MENDER_CLIENT_VERSION=$mender_client_version + +ENV CC "${TOOLCHAIN_HOST}-gcc" # Build liblzma from source RUN wget -q https://tukaani.org/xz/xz-5.2.4.tar.gz \ && tar -C /root -xzf xz-5.2.4.tar.gz \ && cd /root/xz-5.2.4 \ - && ./configure --host=arm-buildroot-linux-gnueabihf --prefix=/root/xz-5.2.4/install \ + && ./configure --host=${TOOLCHAIN_HOST} --prefix=/root/xz-5.2.4/install \ && make \ && make install @@ -79,7 +93,7 @@ RUN env CGO_ENABLED=1 \ CGO_LDFLAGS="-L${LIBLZMA_INSTALL_PATH}/lib" \ CC=$CC \ GOOS=linux \ - GOARM=6 GOARCH=arm make build + ${GO_FLAGS} make build # allow us to keep original PATH variables when sudoing RUN echo "Defaults secure_path=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:$PATH\"" > /etc/sudoers.d/secure_path_override diff --git a/docker-build b/docker-build index 0f4a272..a939bce 100755 --- a/docker-build +++ b/docker-build @@ -6,4 +6,14 @@ IMAGE_NAME=mender-convert MENDER_CLIENT_VERSION="2.0.0" -docker build . -t ${IMAGE_NAME} --build-arg mender_client_version=${MENDER_CLIENT_VERSION} +DOCKER_ARGS="--build-arg mender_client_version=${MENDER_CLIENT_VERSION}" + +if [ "$1" = "arm64" ]; then + DOCKER_ARGS="${DOCKER_ARGS} --build-arg toolchain_host=aarch64-linux-gnu" + DOCKER_ARGS="${DOCKER_ARGS} --build-arg go_flags=GOARCH=arm64" +else + DOCKER_ARGS="${DOCKER_ARGS} --build-arg toolchain_host=arm-buildroot-linux-gnueabihf" + DOCKER_ARGS="${DOCKER_ARGS} --build-arg go_flags=\"GOARM=6 GOARCH=arm\"" +fi + +eval docker build . -t ${IMAGE_NAME} ${DOCKER_ARGS}