diff --git a/.build/Build.Docker.cs b/.build/Build.Docker.cs index 6afc831..8b437e4 100644 --- a/.build/Build.Docker.cs +++ b/.build/Build.Docker.cs @@ -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) @@ -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") diff --git a/Dockerfile b/Dockerfile index 6aabf68..184b052 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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"] \ No newline at end of file