From 102cc31db2cedc540ee36829aa844b72e8be0ed3 Mon Sep 17 00:00:00 2001 From: Evelyn Gurschler Date: Mon, 24 Jun 2024 13:10:50 +0200 Subject: [PATCH] fix(image-build): change from emulation to cross-compile (#57) for building multi-platform images https://github.com/eclipse-tractusx/portal-backend/issues/802 https://docs.docker.com/build/building/multi-platform https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support also improve dockerfiles by removing unnecessary base stage and aligning environment variables --- .github/workflows/migrations-docker.yml | 3 --- .github/workflows/processes-worker-docker.yml | 3 --- .github/workflows/release.yml | 3 --- .github/workflows/service-docker.yml | 3 --- docker/Dockerfile-dim-migrations | 7 +++---- docker/Dockerfile-dim-processes-worker | 7 +++---- docker/Dockerfile-dim-service | 12 ++++++------ 7 files changed, 12 insertions(+), 26 deletions(-) diff --git a/.github/workflows/migrations-docker.yml b/.github/workflows/migrations-docker.yml index f3621bf..39ce46b 100644 --- a/.github/workflows/migrations-docker.yml +++ b/.github/workflows/migrations-docker.yml @@ -60,9 +60,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0 - - name: Set up QEMU - uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 - - name: Docker meta id: meta uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 diff --git a/.github/workflows/processes-worker-docker.yml b/.github/workflows/processes-worker-docker.yml index 2fb43d8..d2b6621 100644 --- a/.github/workflows/processes-worker-docker.yml +++ b/.github/workflows/processes-worker-docker.yml @@ -59,9 +59,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0 - - name: Set up QEMU - uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 - - name: Docker meta id: meta uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b4e79f5..afe1a91 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -111,9 +111,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0 - - name: Set up QEMU - uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 - # Create SemVer or ref tags dependent of trigger event - name: Docker meta id: meta diff --git a/.github/workflows/service-docker.yml b/.github/workflows/service-docker.yml index dceea94..ca3f82b 100644 --- a/.github/workflows/service-docker.yml +++ b/.github/workflows/service-docker.yml @@ -59,9 +59,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0 - - name: Set up QEMU - uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 - - name: Docker meta id: meta uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 diff --git a/docker/Dockerfile-dim-migrations b/docker/Dockerfile-dim-migrations index 441b063..be0f747 100644 --- a/docker/Dockerfile-dim-migrations +++ b/docker/Dockerfile-dim-migrations @@ -17,9 +17,8 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### -FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine AS base - -FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine-amd64 AS publish +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS publish +ARG TARGETARCH WORKDIR / COPY LICENSE / COPY /src/database /src/database @@ -27,7 +26,7 @@ COPY /src/processes/Processes.Worker.Library /src/processes/Processes.Worker.Lib WORKDIR /src/database/Dim.Migrations RUN dotnet publish "Dim.Migrations.csproj" -c Release -o /migrations/publish -FROM base AS final +FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine ENV COMPlus_EnableDiagnostics=0 WORKDIR /migrations COPY --from=publish /migrations/publish . diff --git a/docker/Dockerfile-dim-processes-worker b/docker/Dockerfile-dim-processes-worker index 43336bf..d80a649 100644 --- a/docker/Dockerfile-dim-processes-worker +++ b/docker/Dockerfile-dim-processes-worker @@ -17,9 +17,8 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### -FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine AS base - -FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine-amd64 AS publish +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS publish +ARG TARGETARCH WORKDIR / COPY LICENSE / COPY src/ src/ @@ -27,7 +26,7 @@ RUN dotnet restore "src/processes/Processes.Worker/Processes.Worker.csproj" WORKDIR /src/processes/Processes.Worker RUN dotnet publish "Processes.Worker.csproj" -c Release -o /app/publish -FROM base AS final +FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine ENV COMPlus_EnableDiagnostics=0 WORKDIR /app COPY --from=publish /app/publish . diff --git a/docker/Dockerfile-dim-service b/docker/Dockerfile-dim-service index 8ecb76c..5d6b69c 100644 --- a/docker/Dockerfile-dim-service +++ b/docker/Dockerfile-dim-service @@ -17,20 +17,20 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### -FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base - -FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine-amd64 AS publish +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS publish +ARG TARGETARCH WORKDIR / COPY LICENSE / COPY src/ src/ WORKDIR /src/web/Dim.Web RUN dotnet publish "Dim.Web.csproj" -c Release -o /app/publish -FROM base AS final -ENV COMPlus_EnableDiagnostics=0 +FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine +ENV \ + COMPlus_EnableDiagnostics=0 \ + ASPNETCORE_URLS=http://+:8080 WORKDIR /app COPY --from=publish /app/publish . -ENV ASPNETCORE_URLS http://+:8080 EXPOSE 8080 RUN chown -R 1000:3000 /app USER 1000:3000