Skip to content

Commit

Permalink
#512: Enable multi-platform docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
Velociraptor45 committed Sep 6, 2024
1 parent dbaecd4 commit 25aac2c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ jobs:
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
Expand All @@ -104,6 +112,7 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
context: ./Api
file: ./Api/Dockerfile
push: true
Expand All @@ -119,6 +128,14 @@ jobs:
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
Expand All @@ -128,6 +145,7 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
context: ./Frontend
file: ./Frontend/Dockerfile
push: true
Expand Down
12 changes: 8 additions & 4 deletions Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build
################## BUILD ##################
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build
ARG TARGETARCH
WORKDIR /src
COPY . .
RUN dotnet restore "Xipona.Api.WebApp/Xipona.Api.WebApp.csproj"
RUN dotnet restore "Xipona.Api.WebApp/Xipona.Api.WebApp.csproj" -a $TARGETARCH
COPY . .
RUN dotnet build "Xipona.Api.WebApp/Xipona.Api.WebApp.csproj" -c Release -o /app/build
RUN dotnet build "Xipona.Api.WebApp/Xipona.Api.WebApp.csproj" -c Release -o /app/build -a $TARGETARCH

################# PUBLISH #################
FROM build AS publish
RUN dotnet publish "Xipona.Api.WebApp/Xipona.Api.WebApp.csproj" -c Release -o /app/publish
RUN dotnet publish "Xipona.Api.WebApp/Xipona.Api.WebApp.csproj" -c Release -o /app/publish --no-restore --sc false -a $TARGETARCH

################## FINAL ##################
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
Expand Down
9 changes: 5 additions & 4 deletions Frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
################## BUILD ##################
FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build
ARG TARGETARCH
WORKDIR /src
COPY . .
RUN dotnet restore "Xipona.Frontend.WebApp/Xipona.Frontend.WebApp.csproj"
RUN dotnet build "Xipona.Frontend.WebApp/Xipona.Frontend.WebApp.csproj" -c Release -o /app/build
RUN dotnet restore "Xipona.Frontend.WebApp/Xipona.Frontend.WebApp.csproj" -a $TARGETARCH
RUN dotnet build "Xipona.Frontend.WebApp/Xipona.Frontend.WebApp.csproj" -c Release -o /app/build -a $TARGETARCH

################# PUBLISH #################
FROM build AS publish
RUN dotnet publish "Xipona.Frontend.WebApp/Xipona.Frontend.WebApp.csproj" -c Release -o /app/publish
RUN dotnet publish "Xipona.Frontend.WebApp/Xipona.Frontend.WebApp.csproj" -c Release -o /app/publish --no-restore -a $TARGETARCH

################## FINAL ##################
FROM nginxinc/nginx-unprivileged:1.25 AS final
Expand Down

0 comments on commit 25aac2c

Please sign in to comment.