From 17aa625d3b115103efa30bb98b83ee1fc54230c4 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne <1822826+pipex@users.noreply.github.com> Date: Thu, 9 Mar 2023 21:16:49 -0300 Subject: [PATCH] Use single-arch in dockerfile This is necessary since the builder no longer passes the platform flag to the build. This would lead to dockerfiles that are mixing multi and single arch stages to pull the wrong architecture images, particularly when trying to build images in emulated builds (e.g. armv7hf built on aarch64). Moving the full build to single-arch solves this as the docker engine is capable of chosing the right architecture from the manifest. Once some of the builder issues are fixed, we should move to #2141 Relates-to: balena-io/balena-builder#1010 Change-type: patch --- Dockerfile.template | 26 +++++++++++++++----------- sync/init.ts | 23 +---------------------- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/Dockerfile.template b/Dockerfile.template index 575b26e7..5819b2ef 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -1,24 +1,28 @@ ARG ARCH=%%BALENA_ARCH%% - -# Used by livepush to support multi arch images in older -# balenaOS with buggy platform support -# see https://github.com/balena-os/balena-engine/issues/269 -ARG PREFIX=library ARG FATRW_VERSION=0.2.9 + +FROM arm32v6/alpine:3.16 as alpine-rpi +FROM arm32v7/alpine:3.16 as alpine-armv7hf +FROM arm64v8/alpine:3.16 as alpine-aarch64 +FROM amd64/alpine:3.16 as alpine-amd64 +FROM i386/alpine:3.16 as alpine-i386 + +FROM arm32v6/alpine:3.11 as procmail-rpi +FROM arm32v7/alpine:3.11 as procmail-armv7hf +FROM arm64v8/alpine:3.11 as procmail-aarch64 +FROM amd64/alpine:3.11 as procmail-amd64 +FROM i386/alpine:3.11 as procmail-i386 + ################################################### # Build the supervisor dependencies ################################################### FROM balenalib/${ARCH}-alpine-node:16-run as build-base ARG ARCH -ARG PREFIX ARG FATRW_VERSION ARG FATRW_ARCHIVE="fatrw-${ARCH}.tar.gz" ARG FATRW_LOCATION="https://github.com/balena-os/fatrw/releases/download/v${FATRW_VERSION}/${FATRW_ARCHIVE}" -# Sanity check to prevent a prefix for a non-official docker image being -# inserted. Only 'library' and 'arm32v6' are allowed right now -RUN for allowed in "library" "arm32v6"; do [ "${PREFIX}" = "${allowed}" ] && break; done WORKDIR /usr/src/app @@ -63,7 +67,7 @@ RUN /setup-journal.sh # Extra dependencies. This uses alpine 3.11 as the # procmail package was removed on 3.12 ################################################### -FROM ${PREFIX}/alpine:3.11 as extra +FROM procmail-${ARCH} as extra RUN apk add --update --no-cache procmail @@ -71,7 +75,7 @@ RUN apk add --update --no-cache procmail # Image with the final production dependencies. # This image will also be be used for testing ################################################### -FROM ${PREFIX}/alpine:3.16 as runtime-base +FROM alpine-${ARCH} as runtime-base WORKDIR /usr/src/app diff --git a/sync/init.ts b/sync/init.ts index a047b11a..5cc68163 100644 --- a/sync/init.ts +++ b/sync/init.ts @@ -14,27 +14,6 @@ interface Opts { arch?: string; } -function getPathPrefix(arch: string) { - switch (arch) { - /** - * Proper paths are - * - armv6 - arm32v6 - * - armv7hf - arm32v7 - * - aarch64 - arm64v8 - * - amd64 - amd64 - * - i386 - i386 - * - * We only set the prefix for v6 images since rpi devices are - * the only ones that seem to have the issue - * https://github.com/balena-os/balena-engine/issues/269 - */ - case 'rpi': - return 'arm32v6'; - default: - return 'library'; - } -} - export async function initDevice(opts: Opts) { const arch = opts.arch ?? (await device.getDeviceArch(opts.docker)); const image = `${opts.imageName}:${opts.imageTag}`; @@ -42,7 +21,7 @@ export async function initDevice(opts: Opts) { const buildCache = await device.readBuildCache(opts.address); const stageImages = await device.performBuild(opts.docker, opts.dockerfile, { - buildargs: { ARCH: arch, PREFIX: getPathPrefix(arch) }, + buildargs: { ARCH: arch }, t: image, labels: { 'io.balena.livepush-image': '1', 'io.balena.architecture': arch }, cachefrom: (await device.getCacheFrom(opts.docker))