-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy initContainer for Entity Framework migrations (#1367)
* Multistage build for Docker InitContainer * Updated Container App module to v1.12.0 * Update Docker Build CI workflow to test initContainer * Build but do not deploy the initContainer * Correctly handle appsettings overrides * Move appsettings into ConcernsCaseWork dir
- Loading branch information
1 parent
8615aa4
commit e6f96ba
Showing
12 changed files
with
145 additions
and
143 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 |
---|---|---|
|
@@ -77,10 +77,24 @@ jobs: | |
deploy-image: | ||
name: Deploy '${{ needs.set-env.outputs.branch }}' to ${{ needs.set-env.outputs.environment }} | ||
needs: [ set-env ] | ||
uses: DFE-Digital/deploy-azure-container-apps-action/.github/workflows/[email protected] | ||
strategy: | ||
matrix: | ||
stage: [ | ||
"final", | ||
"initcontainer" | ||
] | ||
include: | ||
- stage: "final" | ||
tag-prefix: "" | ||
- stage: "initcontainer" | ||
tag-prefix: "init-" | ||
uses: DFE-Digital/deploy-azure-container-apps-action/.github/workflows/[email protected] | ||
with: | ||
docker-image-name: 'amsd-app' | ||
docker-build-target: ${{ matrix.stage }} | ||
docker-build-file-name: './Dockerfile' | ||
docker-tag-prefix: ${{ matrix.tag-prefix }} | ||
import-without-deploy: ${{ matrix.stage == 'initcontainer' }} | ||
environment: ${{ needs.set-env.outputs.environment }} | ||
annotate-release: true | ||
docker-build-args: | | ||
|
This file was deleted.
Oops, something went wrong.
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,12 +1,22 @@ | ||
name: Scan Docker image | ||
name: Run Docker tests | ||
|
||
on: | ||
push: | ||
branches: main | ||
pull_request: | ||
paths: | ||
- Dockerfile | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
scan: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
stage: [ | ||
"final", | ||
"initcontainer" | ||
] | ||
outputs: | ||
image: ${{ steps.build.outputs.imageid }} | ||
steps: | ||
|
@@ -16,23 +26,24 @@ jobs: | |
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build docker image | ||
- name: Build Docker image | ||
uses: docker/build-push-action@v6 | ||
id: build | ||
with: | ||
secrets: github_token=${{ secrets.GITHUB_TOKEN }} | ||
load: true | ||
cache-from: type=gha | ||
cache-to: type=gha | ||
target: ${{ matrix.stage }} | ||
push: false | ||
|
||
- name: Export docker image as tar | ||
run: docker save -o ${{ github.ref_name }}.tar ${{ steps.build.outputs.imageid }} | ||
run: docker save -o ${{ matrix.stage }}.tar ${{ steps.build.outputs.imageid }} | ||
|
||
- name: Scan Docker image for CVEs | ||
uses: aquasecurity/[email protected] | ||
with: | ||
input: ${{ github.ref_name }}.tar | ||
input: ${{ matrix.stage }}.tar | ||
format: 'sarif' | ||
output: 'trivy-results.sarif' | ||
limit-severities-for-sarif: true | ||
|
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,63 +1,64 @@ | ||
# Stage 1 | ||
ARG ASPNET_SDK_TAG=8.0 | ||
ARG ASPNET_IMAGE_TAG=8.0-bookworm-slim | ||
ARG NODEJS_IMAGE_TAG=20.15-bullseye | ||
ARG COMMIT_SHA=not-set | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS publish | ||
|
||
# ============================================== | ||
# Base SDK | ||
# ============================================== | ||
FROM "mcr.microsoft.com/dotnet/sdk:${ASPNET_SDK_TAG}" AS builder | ||
ARG COMMIT_SHA | ||
|
||
WORKDIR /build | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
COPY ConcernsCaseWork/. . | ||
|
||
RUN dotnet restore ConcernsCaseWork | ||
RUN dotnet build ConcernsCaseWork "/p:customBuildMessage=Manifest commit SHA... ${COMMIT_SHA};" -c Release | ||
|
||
RUN dotnet new tool-manifest | ||
RUN dotnet tool install dotnet-ef | ||
|
||
RUN mkdir -p /app/SQL | ||
RUN dotnet ef migrations script --output /app/SQL/DbMigrationScript.sql --idempotent -p /build/ConcernsCaseWork.Data | ||
RUN touch /app/SQL/DbMigrationScript.sql /app/SQL/DbMigrationScriptOutput.txt | ||
|
||
RUN dotnet publish ConcernsCaseWork -c Release -o /app --no-build | ||
WORKDIR /app | ||
COPY ./script/set-appsettings-release-tag.sh set-appsettings-release-tag.sh | ||
RUN chmod +x ./set-appsettings-release-tag.sh | ||
RUN echo "Setting appsettings releasetag=${COMMIT_SHA}" | ||
RUN ./set-appsettings-release-tag.sh "$COMMIT_SHA" | ||
RUN rm ./set-appsettings-release-tag.sh | ||
|
||
COPY ./script/web-docker-entrypoint.sh /app/docker-entrypoint.sh | ||
COPY ./script/set-appsettings-release-tag.sh /app/set-appsettings-release-tag.sh | ||
|
||
# Stage 2 - Build assets | ||
FROM node:${NODEJS_IMAGE_TAG} as build | ||
COPY --from=publish /app /app | ||
# ============================================== | ||
# Entity Framework: Migration Builder | ||
# ============================================== | ||
FROM builder AS efbuilder | ||
WORKDIR /build | ||
ENV PATH=$PATH:/root/.dotnet/tools | ||
RUN dotnet tool install --global dotnet-ef | ||
RUN mkdir /sql | ||
RUN dotnet ef migrations bundle -r linux-x64 --configuration Release -p ConcernsCaseWork.Data --no-build -o /sql/migratedb | ||
|
||
# ============================================== | ||
# Entity Framework: Migration Runner | ||
# ============================================== | ||
FROM "mcr.microsoft.com/dotnet/aspnet:${ASPNET_IMAGE_TAG}" AS initcontainer | ||
WORKDIR /sql | ||
COPY --from=efbuilder /sql /sql | ||
COPY --from=builder /app/appsettings* /ConcernsCaseWork/ | ||
|
||
# ============================================== | ||
# Front End Builder | ||
# ============================================== | ||
FROM node:${NODEJS_IMAGE_TAG} AS frontend | ||
COPY --from=builder /app/wwwroot /app/wwwroot | ||
WORKDIR /app/wwwroot | ||
RUN npm install | ||
RUN npm run build | ||
|
||
# Stage 3 - Final | ||
# ============================================== | ||
# Application | ||
# ============================================== | ||
FROM "mcr.microsoft.com/dotnet/aspnet:${ASPNET_IMAGE_TAG}" AS final | ||
LABEL org.opencontainers.image.source=https://github.com/DFE-Digital/record-concerns-support-trusts | ||
|
||
ARG COMMIT_SHA | ||
|
||
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 -y msodbcsql18 | ||
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools18 | ||
|
||
COPY --from=build /app /app | ||
COPY --from=builder /app /app | ||
COPY --from=frontend /app/wwwroot /app/wwwroot | ||
COPY ./script/web-docker-entrypoint.sh /app/docker-entrypoint.sh | ||
WORKDIR /app | ||
RUN chown -R app:app /app | ||
RUN chmod +x ./docker-entrypoint.sh | ||
RUN chmod +x ./set-appsettings-release-tag.sh | ||
RUN echo "Setting appsettings releasetag=${COMMIT_SHA}" | ||
RUN ./set-appsettings-release-tag.sh "$COMMIT_SHA" | ||
|
||
RUN chown app:app ./SQL/ -R | ||
USER app | ||
EXPOSE 8080/tcp |
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
set -e | ||
set -o pipefail | ||
|
||
apt-get update && apt-get install jq -y | ||
|
||
RELEASE_TAG="$1" | ||
|
||
APP_SETTINGS_FILES=( | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.