Skip to content

Commit

Permalink
Add devops for new Person API (#551)
Browse files Browse the repository at this point in the history
* Basic dockerfile for serving the Person API

* Custom entrypoint script that does not run any EF migrations

* Add new Person Api Dockerfile to build test

* Add new Project to .NET CI tests

* Fix: target correct project during build

* CI: Test both Dockerfiles
  • Loading branch information
DrizzlyOwl authored Aug 6, 2024
1 parent 2e2ad31 commit d5b4427
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/continuous-integration-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ on:
paths:
- 'Dfe.Academies.*/**'
- 'TramsDataApi*/**'
- 'PersonsApi*/**'
- '!Dfe.Academies.Performance/**'
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened ]
paths:
- 'Dfe.Academies.*/**'
- 'TramsDataApi*/**'
- 'PersonsApi*/**'
- '!Dfe.Academies.Performance/**'

env:
Expand Down Expand Up @@ -73,15 +75,15 @@ jobs:

- name: Install dotnet reportgenerator
run: dotnet tool install --global dotnet-reportgenerator-globaltool

- name: Add nuget package source
run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/DFE-Digital/index.json"

- name: Restore tools for tests
run: dotnet tool restore

- name: Restore dependencies
run: dotnet restore TramsDataApi.sln
run: dotnet restore

- name: Build, Test and Analyze
env:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ on:
pull_request:
paths:
- Dockerfile
- Dockerfile.PersonsApi
types: [opened, synchronize]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
image: [
"Dockerfile",
"Dockerfile.PersonsApi"
]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -19,5 +26,6 @@ jobs:
- name: Build docker image
uses: docker/build-push-action@v6
with:
file: './${{ matrix.image }}'
secrets: github_token=${{ secrets.GITHUB_TOKEN }}
push: false
33 changes: 33 additions & 0 deletions Dockerfile.PersonsApi
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build
WORKDIR /build

ENV DEBIAN_FRONTEND=noninteractive

COPY . .

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 build -c Release PersonsApi
RUN dotnet publish PersonsApi -c Release -o /app --no-restore

RUN dotnet new tool-manifest
RUN dotnet tool install dotnet-ef --version 8.0.7
ENV PATH="$PATH:/root/.dotnet/tools"

ARG ASPNET_IMAGE_TAG
FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim AS final

RUN apt-get update
RUN apt-get install unixodbc curl gnupg -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/config/debian/12/prod.list | tee /etc/apt/sources.list.d/msprod.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install msodbcsql18 mssql-tools18 -y

COPY --from=build /app /app

WORKDIR /app
COPY ./script/personsapi.docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh

ENV ASPNETCORE_HTTP_PORTS 80
EXPOSE 80/tcp
7 changes: 7 additions & 0 deletions script/personsapi.docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# exit on failures
set -e
set -o pipefail

exec "$@"

0 comments on commit d5b4427

Please sign in to comment.