From 0c690da27ba893633b3fb32d7d83f24ade8b7a20 Mon Sep 17 00:00:00 2001 From: Evelyn Gurschler Date: Mon, 24 Jun 2024 12:37:26 +0200 Subject: [PATCH] fix(image-build): change from emulation to cross-compile (#37) 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 9de7170..adcc973 100644 --- a/.github/workflows/migrations-docker.yml +++ b/.github/workflows/migrations-docker.yml @@ -61,9 +61,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.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 5fbb413..08668b9 100644 --- a/.github/workflows/processes-worker-docker.yml +++ b/.github/workflows/processes-worker-docker.yml @@ -60,9 +60,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.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 e73b081..ea6436a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -113,9 +113,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.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 eb078ad..f13a50c 100644 --- a/.github/workflows/service-docker.yml +++ b/.github/workflows/service-docker.yml @@ -60,9 +60,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.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 84f9fec..0e5ec7e 100644 --- a/docker/Dockerfile-dim-migrations +++ b/docker/Dockerfile-dim-migrations @@ -18,9 +18,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 @@ -28,7 +27,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 5de31ad..6703460 100644 --- a/docker/Dockerfile-dim-processes-worker +++ b/docker/Dockerfile-dim-processes-worker @@ -18,9 +18,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/ @@ -28,7 +27,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 960da98..21ab67b 100644 --- a/docker/Dockerfile-dim-service +++ b/docker/Dockerfile-dim-service @@ -18,20 +18,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