Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): Add multiarch support for AMD64, ARM and ARM64 #1

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .build/Build.Docker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ partial class Build : NukeBuild

private string DockerImageTag => $"{DockerImage}:{DockerTag}";

private string[] DockerImagePlatforms => ["linux/amd64", "linux/arm", "linux/arm64"];

Target BuildImage => _ => _
.DependsOn(Test)
.DependsOn(Format)
Expand All @@ -22,6 +24,7 @@ partial class Build : NukeBuild
.SetPath(".")
.SetFile("Dockerfile")
.SetTag(this.DockerImageTag)
.SetPlatform(string.Join(",", this.DockerImagePlatforms))
.AddCacheFrom("type=gha")
.AddCacheTo("type=gha,mode=max")
.AddLabel("org.opencontainers.image.source=https://github.com/maxnatamo/fetcharr")
Expand Down
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# syntax=docker/dockerfile:1.9-labs

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build-env
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build-env
WORKDIR /app
EXPOSE 5000

ARG TARGETARCH

COPY --parents ./src/*.props ./src/**/*.csproj ./
RUN dotnet restore src/API/src/Fetcharr.API.csproj
RUN dotnet restore src/API/src/Fetcharr.API.csproj -a $TARGETARCH

COPY . .
RUN dotnet publish src/API/src/Fetcharr.API.csproj --no-restore -o /app
RUN dotnet publish src/API/src/Fetcharr.API.csproj -a $TARGETARCH --no-restore -o /out

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
WORKDIR /app
Expand All @@ -17,11 +19,11 @@ ENV FETCHARR_BASE_DIR="/app/fetcharr" \
FETCHARR_CONFIG_DIR="/config"

RUN set -ex; \
mkdir -p /config && chown 1000:1000 /config;
mkdir -p /config && chown $APP_UID /config;

COPY --from=build-env --chown=1000:1000 /app /app/fetcharr
COPY --from=build-env --chown=$APP_UID /out /app/fetcharr

USER 1000:1000
USER $APP_UID
VOLUME /config

ENTRYPOINT ["dotnet", "/app/fetcharr/Fetcharr.API.dll"]