Skip to content

Commit

Permalink
Switch to Azure Linux base image
Browse files Browse the repository at this point in the history
* Reduces the overall final image size by using Azure Linux
* Offers maximum compatibility with Azure infrastructure
* Uses arbitrary user instead of 'root'
  • Loading branch information
DrizzlyOwl committed Nov 15, 2024
1 parent e22cbe0 commit 864d9bd
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
# Stage 1
ARG ASPNET_IMAGE_TAG=8.0-bookworm-slim
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /build
# Set the major version of dotnet
ARG DOTNET_VERSION=8.0

ENV DEBIAN_FRONTEND=noninteractive
# Stage 1 - Build the app using the dotnet SDK
ARG DOTNET_VERSION
FROM "mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-azurelinux3.0" AS build
WORKDIR /build

COPY ./Dfe.Academies.External.Web/ ./Dfe.Academies.External.Web/
COPY ./script/web-docker-entrypoint.sh /app/docker-entrypoint.sh

# Mount GitHub Token as a Docker secret so that NuGet Feed can be accessed
RUN --mount=type=secret,id=github_token dotnet nuget add source --username USERNAME --password $(cat /run/secrets/github_token) --store-password-in-clear-text --name github "https://nuget.pkg.github.com/DFE-Digital/index.json"
RUN dotnet restore Dfe.Academies.External.Web
RUN dotnet build Dfe.Academies.External.Web --no-restore
RUN dotnet publish Dfe.Academies.External.Web -c Release -o /app --no-restore

COPY ./script/web-docker-entrypoint.sh /app/docker-entrypoint.sh
# Restore, build and publish the dotnet solution
RUN ["dotnet", "restore", "Dfe.Academies.External.Web"]
RUN ["dotnet", "build", "Dfe.Academies.External.Web", "--no-restore"]
RUN ["dotnet", "publish", "Dfe.Academies.External.Web", "--no-build", "-c", "Release", "-o", "/app"]

# Stage 2
ARG ASPNET_IMAGE_TAG
FROM "mcr.microsoft.com/dotnet/aspnet:${ASPNET_IMAGE_TAG}" AS final
LABEL org.opencontainers.image.source=https://github.com/DFE-Digital/Dfe.Academies.External
# Stage 2 - Build a runtime environment
ARG DOTNET_VERSION
FROM "mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-azurelinux3.0" AS final
WORKDIR /app
LABEL org.opencontainers.image.source="https://github.com/DFE-Digital/Dfe.Academies.External"

COPY --from=build /app /app
WORKDIR /app
RUN chmod +x ./docker-entrypoint.sh
RUN ["chmod", "+x", "./docker-entrypoint.sh"]

USER $APP_UID
ENV ASPNETCORE_HTTP_PORTS=80
EXPOSE 80/tcp

0 comments on commit 864d9bd

Please sign in to comment.