Skip to content

Commit

Permalink
fix(image-build): change from emulation to cross-compile (#162)
Browse files Browse the repository at this point in the history
for building multi-platform images
eclipse-tractusx/portal-backend#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
  • Loading branch information
evegufy authored Jun 24, 2024
1 parent 6df52f6 commit 075316a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 22 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/migrations-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,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
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,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
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release_candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,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
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/service-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,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
Expand Down
7 changes: 3 additions & 4 deletions docker/Dockerfile-policy-hub-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
# 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 NOTICE.md DEPENDENCIES /
COPY /src/database /src/database
WORKDIR /src/database/PolicyHub.Migrations
RUN dotnet publish "PolicyHub.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 .
Expand Down
12 changes: 6 additions & 6 deletions docker/Dockerfile-policy-hub-service
Original file line number Diff line number Diff line change
Expand Up @@ -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 NOTICE.md DEPENDENCIES /
COPY src/ src/
WORKDIR /src/hub/PolicyHub.Service
RUN dotnet publish "PolicyHub.Service.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
Expand Down

0 comments on commit 075316a

Please sign in to comment.