-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to Azure Linux base image (#956)
- Reduces the overall final image size by using Azure - Offers maximum compatibility with Azure infrastructure - Uses arbitrary user instead of 'root' - Supported by Microsoft
- Loading branch information
1 parent
f49df38
commit 80d93d4
Showing
6 changed files
with
66 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,36 @@ | ||
# Stage 1 | ||
ARG ASPNET_IMAGE_TAG=8.0-bookworm-slim | ||
ARG DOTNET_SDK_IMAGE_TAG=8.0 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_SDK_IMAGE_TAG} AS publish | ||
# Set the major version of dotnet | ||
ARG DOTNET_VERSION=8.0 | ||
|
||
# Build the app using the dotnet SDK | ||
FROM "mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-azurelinux3.0" AS build | ||
WORKDIR /build | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
COPY Dfe.ManageFreeSchoolProjects/. . | ||
|
||
RUN dotnet restore Dfe.ManageFreeSchoolProjects.API | ||
RUN dotnet build Dfe.ManageFreeSchoolProjects.API -c Release | ||
|
||
RUN dotnet new tool-manifest | ||
RUN dotnet tool install dotnet-ef --version 7.0.13 | ||
|
||
RUN mkdir -p /app/SQL | ||
RUN dotnet ef migrations script --output /app/SQL/DbMigrationScript.sql --idempotent -p /build/Dfe.ManageFreeSchoolProjects.Data | ||
RUN touch /app/SQL/DbMigrationScript.sql | ||
|
||
RUN dotnet publish Dfe.ManageFreeSchoolProjects.API -c Release -o /app --no-build | ||
|
||
COPY ./script/api-docker-entrypoint.sh /app/docker-entrypoint.sh | ||
|
||
# Stage 3 - Final | ||
FROM "mcr.microsoft.com/dotnet/aspnet:${ASPNET_IMAGE_TAG}" AS final | ||
LABEL org.opencontainers.image.source=https://github.com/DFE-Digital/manage-free-school-projects | ||
LABEL org.opencontainers.image.description="Manage Free School Projects - API" | ||
|
||
ENV ASPNETCORE_HTTP_PORTS=80 | ||
|
||
RUN apt-get update | ||
RUN apt-get install unixodbc curl gnupg jq -y | ||
RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg | ||
RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc | ||
RUN curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list | ||
RUN apt-get update | ||
RUN ACCEPT_EULA=Y apt-get install msodbcsql18 mssql-tools18 -y | ||
|
||
COPY --from=publish /app /app | ||
COPY ./Dfe.ManageFreeSchoolProjects/ /build | ||
RUN ["dotnet", "restore", "Dfe.ManageFreeSchoolProjects.API"] | ||
RUN ["dotnet", "build", "Dfe.ManageFreeSchoolProjects.API", "--no-restore", "-c", "Release"] | ||
RUN ["dotnet", "publish", "Dfe.ManageFreeSchoolProjects.API", "--no-build", "-o", "/app"] | ||
|
||
RUN ["dotnet", "new", "tool-manifest"] | ||
RUN ["dotnet", "tool", "install", "dotnet-ef", "--version", "8.0.11"] | ||
RUN ["mkdir", "-p", "/app/SQL"] | ||
RUN ["dotnet", "restore", "Dfe.ManageFreeSchoolProjects.Data"] | ||
RUN ["dotnet", "build", "Dfe.ManageFreeSchoolProjects.Data", "--no-restore"] | ||
RUN ["dotnet", "ef", "migrations", "script", "--output", "/app/SQL/DbMigrationScript.sql", "--idempotent", "-p", "/build/Dfe.ManageFreeSchoolProjects.Data", "--no-build"] | ||
RUN ["touch", "/app/SQL/DbMigrationScript.sql"] | ||
|
||
# Install SQL tools to allow migrations to be run | ||
FROM "mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-azurelinux3.0" AS base | ||
RUN curl "https://packages.microsoft.com/config/rhel/9/prod.repo" | tee /etc/yum.repos.d/mssql-release.repo | ||
ENV ACCEPT_EULA=Y | ||
RUN ["tdnf", "update"] | ||
RUN ["tdnf", "install", "-y", "mssql-tools18"] | ||
RUN ["tdnf", "clean", "all"] | ||
|
||
# Build a runtime environment | ||
FROM base AS runtime | ||
WORKDIR /app | ||
RUN chmod +x ./docker-entrypoint.sh | ||
|
||
EXPOSE 80/tcp | ||
LABEL org.opencontainers.image.source="https://github.com/DFE-Digital/manage-free-school-projects" | ||
LABEL org.opencontainers.image.description="Manage Free School Projects - API" | ||
COPY --from=build /app /app | ||
COPY ./script/api-docker-entrypoint.sh /app/docker-entrypoint.sh | ||
RUN ["chmod", "+x", "/app/docker-entrypoint.sh"] | ||
USER $APP_UID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,30 @@ | ||
# Stage 1 | ||
ARG ASPNET_IMAGE_TAG=8.0-bookworm-slim | ||
ARG DOTNET_SDK_IMAGE_TAG=8.0 | ||
ARG NODEJS_IMAGE_TAG=20.15-bullseye | ||
# Set the major version of dotnet | ||
ARG DOTNET_VERSION=8.0 | ||
# Set the major version of nodejs | ||
ARG NODEJS_VERSION_MAJOR=22 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_SDK_IMAGE_TAG} AS publish | ||
|
||
WORKDIR /build | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
COPY Dfe.ManageFreeSchoolProjects/. . | ||
|
||
RUN dotnet restore Dfe.ManageFreeSchoolProjects | ||
RUN dotnet build Dfe.ManageFreeSchoolProjects -c Release | ||
RUN dotnet publish Dfe.ManageFreeSchoolProjects -c Release -o /app --no-build | ||
|
||
COPY ./script/web-docker-entrypoint.sh /app/docker-entrypoint.sh | ||
|
||
# Stage 2 - Build assets | ||
FROM node:${NODEJS_IMAGE_TAG} as build | ||
COPY --from=publish /app /app | ||
WORKDIR /app/wwwroot | ||
# Build frontend assets using node js | ||
FROM "node:${NODEJS_VERSION_MAJOR}-bullseye-slim" AS assets | ||
WORKDIR /app | ||
COPY ./Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects/wwwroot /app | ||
RUN npm install | ||
RUN npm run build | ||
|
||
# Stage 3 - Final | ||
FROM "mcr.microsoft.com/dotnet/aspnet:${ASPNET_IMAGE_TAG}" AS final | ||
LABEL org.opencontainers.image.source=https://github.com/DFE-Digital/manage-free-school-projects | ||
LABEL org.opencontainers.image.description="Manage Free School Projects - App" | ||
|
||
ARG COMMIT_SHA | ||
ENV ASPNETCORE_HTTP_PORTS=80 | ||
|
||
RUN apt-get update | ||
RUN apt-get install unixodbc curl gnupg jq -y | ||
RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg | ||
RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc | ||
RUN curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list | ||
RUN apt-get update | ||
RUN ACCEPT_EULA=Y apt-get install msodbcsql18 mssql-tools18 -y | ||
# Build the app using the dotnet SDK | ||
FROM "mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-azurelinux3.0" AS build | ||
WORKDIR /build | ||
COPY ./Dfe.ManageFreeSchoolProjects/ /build | ||
RUN ["dotnet", "restore", "Dfe.ManageFreeSchoolProjects"] | ||
RUN ["dotnet", "build", "Dfe.ManageFreeSchoolProjects", "--no-restore", "-c", "Release"] | ||
RUN ["dotnet", "publish", "Dfe.ManageFreeSchoolProjects", "--no-build", "-o", "/app"] | ||
|
||
COPY --from=build /app /app | ||
# Build a runtime environment | ||
FROM "mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-azurelinux3.0" AS runtime | ||
WORKDIR /app | ||
RUN chmod +x ./docker-entrypoint.sh | ||
|
||
EXPOSE 80/tcp | ||
LABEL org.opencontainers.image.source="https://github.com/DFE-Digital/manage-free-school-projects" | ||
LABEL org.opencontainers.image.description="Manage Free School Projects - App" | ||
COPY --from=build /app /app | ||
COPY --from=assets /app /app/wwwroot | ||
COPY ./script/web-docker-entrypoint.sh /app/docker-entrypoint.sh | ||
RUN ["chmod", "+x", "/app/docker-entrypoint.sh"] | ||
USER $APP_UID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters