From 68631ff1a66e97639ec8b834425b02a4bd9ef24c Mon Sep 17 00:00:00 2001 From: Remco Ros Date: Sun, 28 Jul 2024 10:00:52 +0000 Subject: [PATCH] fix multi-platform build --- Dockerfile | 13 +++++++++---- Makefile | 11 ----------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index c08031a..5f56044 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,9 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine as build +# QEMU crashes when building arm64 container, so we use this pattern to create a multi-platform build: +# https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/ +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build + +# implicitly set by docker build +ARG TARGETARCH # install nodejs/npm to build cc-implementation RUN apk update && apk add --no-cache nodejs npm @@ -13,11 +18,11 @@ RUN \ npm install && \ npm run build -# compile PushTX app +# compile PushTX app for target architecture (arm64/amd64) RUN \ cd /app/PushTX && \ - dotnet restore && \ - dotnet publish -c Release -o out + dotnet restore -a $TARGETARCH && \ + dotnet publish -a $TARGETARCH --no-restore -c Release -o out # start from aspnet runtime FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine diff --git a/Makefile b/Makefile index bbde676..3ddbef7 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,6 @@ PKG_VERSION := $(shell yq e ".version" manifest.yaml) TS_FILES := $(shell find ./scripts -name \*.ts) SOURCES := $(shell find ./src ! -path "*/obj/*" ! -path "*/bin/*" ! -path "*/node_modules/*") -# sha256 hashes can be found in https://github.com/mikefarah/yq/releases/download/v4.40.7/checksums-bsd -YQ_VERSION := 4.40.7 -YQ_SHA_AMD64 := 4f13ee9303a49f7e8f61e7d9c87402e07cc920ae8dfaaa8c10d7ea1b8f9f48ed -YQ_SHA_ARM64 := a84f2c8f105b70cd348c3bf14048aeb1665c2e7314cbe9aaff15479f268b8412 - .DELETE_ON_ERROR: all: verify @@ -46,9 +41,6 @@ ifeq ($(ARCH),x86_64) else mkdir -p docker-images docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) \ - --build-arg PLATFORM=arm64 \ - --build-arg YQ_VERSION=$(YQ_VERSION) \ - --build-arg YQ_SHA=$(YQ_SHA_ARM64) \ --platform=linux/arm64 -o type=docker,dest=docker-images/aarch64.tar . endif @@ -57,9 +49,6 @@ ifeq ($(ARCH),aarch64) else mkdir -p docker-images docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) \ - --build-arg PLATFORM=amd64 \ - --build-arg YQ_VERSION=$(YQ_VERSION) \ - --build-arg YQ_SHA=$(YQ_SHA_AMD64) \ --platform=linux/amd64 -o type=docker,dest=docker-images/x86_64.tar . endif