Skip to content
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
69 changes: 45 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
# Set the major version of dotnet
ARG DOTNET_VERSION=8.0
ARG DOTNET_VERSION=8.0

# Stage 1 - Build the app using the dotnet SDK
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-azurelinux3.0 AS build
# ============================================================
# Stage 1 - Build + Install Playwright (Ubuntu SDK)
# ============================================================
# Use Ubuntu-based .NET SDK for Playwright install
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build
WORKDIR /build
ARG CI
ENV CI=${CI}

# 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"
# Install Playwright CLI
RUN dotnet tool install --global Microsoft.Playwright.CLI
ENV PATH="${PATH}:/root/.dotnet/tools"

# Copy the application code
# Copy solution
COPY ./src/ ./src/
COPY Directory.Build.props ./
COPY DfE.ExternalApplications.Api.sln ./

# Build and publish the dotnet solution
RUN dotnet restore DfE.ExternalApplications.Api.sln && \
dotnet build ./src/DfE.ExternalApplications.Api --no-restore -c Release && \
dotnet publish ./src/DfE.ExternalApplications.Api --no-build -o /app
# Restore + build
RUN dotnet restore DfE.ExternalApplications.Api.sln
RUN dotnet build ./src/DfE.ExternalApplications.Api --configuration Release --no-restore

# ==============================================
# Entity Framework: Migration Builder
# ==============================================
# Install Playwright browsers + OS dependencies using Ubuntu (works)
RUN playwright install --with-deps

# Publish final output
RUN dotnet publish ./src/DfE.ExternalApplications.Api --configuration Release --no-build -o /app


# ============================================================
# Stage 2 - EF Migration Builder
# ============================================================
FROM build AS efbuilder
WORKDIR /build
ARG DOTNET_EF_TAG=8.0.8
ARG PROJECT_NAME="DfE.ExternalApplications.Api"

ENV PATH=$PATH:/root/.dotnet/tools
RUN dotnet tool install --global dotnet-ef --version 8.*
Expand All @@ -36,23 +43,37 @@ RUN dotnet ef migrations bundle -r linux-x64 \
--project ./src/DfE.ExternalApplications.Api \
--no-build -o /sql/migratedb

# ==============================================
# Entity Framework: Migration Runner
# ==============================================

# ============================================================
# Stage 3 - Init Container
# ============================================================
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-azurelinux3.0 AS initcontainer
WORKDIR /sql

COPY --from=efbuilder /sql /sql
COPY --from=build /app/appsettings* /sql/
COPY --from=build /app/appsettings* /DfE.ExternalApplications.Api/

# Stage 3 - Build a runtime environment

# ============================================================
# Stage 4 - Final Runtime (Azure Linux) + Playwright browsers
# ============================================================
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-azurelinux3.0 AS final

WORKDIR /app
LABEL org.opencontainers.image.source="https://github.com/DFE-Digital/external-applications-api"
LABEL org.opencontainers.image.description="External Applications - Api"

# Copy published API
COPY --from=build /app /app
COPY ./script/api-docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh

# Copy Playwright installed browsers + driver
COPY --from=build /root/.cache/ms-playwright /root/.cache/ms-playwright
COPY --from=build /root/.dotnet/tools /root/.dotnet/tools
ENV PATH="${PATH}:/root/.dotnet/tools"

# Entrypoint script
COPY script/api-docker-entrypoint.sh /app/docker-entrypoint.sh
RUN sed -i 's/\r$//' /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

USER $APP_UID
ENTRYPOINT ["/app/docker-entrypoint.sh"]
9 changes: 4 additions & 5 deletions script/api-docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

# exit on failures
#!/bin/sh
set -e
set -o pipefail

exec "$@"
echo "Starting External Applications API..."

exec /usr/bin/dotnet /app/DfE.ExternalApplications.Api.dll