Skip to content

Commit

Permalink
Use a single Docker image (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Dec 5, 2023
1 parent 83f3f51 commit a3a0f4f
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 213 deletions.
18 changes: 3 additions & 15 deletions .github/workflows/actions/deploy-aks-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@ inputs:
environment_name:
description: 'The name of the environment'
required: true
api_docker_image:
description: 'The API Docker image to deploy to the environment'
required: true
cli_docker_image:
description: 'The CLI Docker image to deploy to the environment'
required: true
ui_docker_image:
description: 'The Support UI Docker image to deploy to the environment'
required: true
worker_docker_image:
description: 'The worker worker Docker image to deploy to the environment'
docker_image:
description: 'The Docker image to deploy to the environment'
required: true
azure_credentials:
description: 'JSON object containing a service principal that can deploy to the environment'
Expand All @@ -39,8 +30,5 @@ runs:
make ci ${{ inputs.environment_name }}_aks terraform-apply
env:
TF_VAR_azure_sp_credentials_json: ${{ inputs.azure_credentials }}
TF_VAR_api_docker_image: ${{ inputs.api_docker_image }}
TF_VAR_cli_docker_image: ${{ inputs.cli_docker_image }}
TF_VAR_ui_docker_image: ${{ inputs.ui_docker_image }}
TF_VAR_worker_docker_image: ${{ inputs.worker_docker_image }}
TF_VAR_docker_image: ${{ inputs.docker_image }}
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/backup-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: make install-konduit

- name: Dump database
run: bin/konduit.sh -k ${{ env.KEYVAULT_NAME }} -d trs trs-production-ui -- pg_dump -E utf8 --compress=1 --clean --if-exists --no-owner --verbose -f backup.sql.gz
run: bin/konduit.sh -k ${{ env.KEYVAULT_NAME }} -d trs trs-production-worker -- pg_dump -E utf8 --compress=1 --clean --if-exists --no-owner --verbose -f backup.sql.gz

- uses: DFE-Digital/github-actions/set-arm-environment-variables@master
with:
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@ name: Deploy dev environment
on:
workflow_call:
inputs:
api_docker_image:
type: string
required: true
cli_docker_image:
type: string
required: true
ui_docker_image:
type: string
required: true
worker_docker_image:
docker_image:
type: string
required: true

Expand All @@ -32,9 +23,6 @@ jobs:
id: deploy
with:
environment_name: dev
api_docker_image: ${{ inputs.api_docker_image }}
cli_docker_image: ${{ inputs.cli_docker_image }}
ui_docker_image: ${{ inputs.ui_docker_image }}
worker_docker_image: ${{ inputs.worker_docker_image }}
docker_image: ${{ inputs.docker_image }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}

17 changes: 3 additions & 14 deletions .github/workflows/deploy-preprod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ name: Deploy pre-production environment
on:
workflow_call:
inputs:
api_docker_image:
type: string
required: true
cli_docker_image:
type: string
required: true
ui_docker_image:
type: string
worker_docker_image:
docker_image:
type: string
required: true
workflow_dispatch:
Expand All @@ -20,7 +12,7 @@ concurrency: deploy_preprod
jobs:
package:
name: Package application
if: inputs.api_docker_image == ''
if: inputs.docker_image == ''
uses: ./.github/workflows/package.yml
secrets: inherit

Expand All @@ -40,8 +32,5 @@ jobs:
id: deploy
with:
environment_name: pre-production
api_docker_image: ${{ inputs.api_docker_image || needs.package.outputs.api_docker_image }}
cli_docker_image: ${{ inputs.cli_docker_image || needs.package.outputs.cli_docker_image }}
ui_docker_image: ${{ inputs.ui_docker_image || needs.package.outputs.ui_docker_image }}
worker_docker_image: ${{ inputs.worker_docker_image || needs.package.outputs.worker_docker_image }}
docker_image: ${{ inputs.docker_image || needs.package.outputs.docker_image }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
16 changes: 2 additions & 14 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@ name: Deploy production environment
on:
workflow_call:
inputs:
api_docker_image:
type: string
required: true
cli_docker_image:
type: string
required: true
ui_docker_image:
type: string
required: true
worker_docker_image:
docker_image:
type: string
required: true

Expand All @@ -32,8 +23,5 @@ jobs:
id: deploy
with:
environment_name: production
api_docker_image: ${{ inputs.api_docker_image }}
cli_docker_image: ${{ inputs.cli_docker_image }}
ui_docker_image: ${{ inputs.ui_docker_image }}
worker_docker_image: ${{ inputs.worker_docker_image }}
docker_image: ${{ inputs.docker_image }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
16 changes: 2 additions & 14 deletions .github/workflows/deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@ name: Deploy test environment
on:
workflow_call:
inputs:
api_docker_image:
type: string
required: true
cli_docker_image:
type: string
required: true
ui_docker_image:
type: string
required: true
worker_docker_image:
docker_image:
type: string
required: true

Expand All @@ -32,9 +23,6 @@ jobs:
id: deploy
with:
environment_name: test
api_docker_image: ${{ inputs.api_docker_image }}
cli_docker_image: ${{ inputs.cli_docker_image }}
ui_docker_image: ${{ inputs.ui_docker_image }}
worker_docker_image: ${{ inputs.worker_docker_image }}
docker_image: ${{ inputs.docker_image }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}

56 changes: 10 additions & 46 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ name: Package application
on:
workflow_call:
outputs:
api_docker_image:
value: ${{ jobs.package.outputs.api_image_tag }}
cli_docker_image:
value: ${{ jobs.package.outputs.cli_image_tag }}
ui_docker_image:
value: ${{ jobs.package.outputs.ui_image_tag }}
worker_docker_image:
value: ${{ jobs.package.outputs.worker_image_tag }}
docker_image:
value: ${{ jobs.package.outputs.image_tag }}

jobs:
package:
Expand All @@ -20,10 +14,7 @@ jobs:
CONTAINER_REGISTRY: ghcr.io

outputs:
api_image_tag: ${{ steps.image_tags.outputs.api_tag }}
cli_image_tag: ${{ steps.image_tags.outputs.cli_tag }}
ui_image_tag: ${{ steps.image_tags.outputs.ui_tag }}
worker_image_tag: ${{ steps.image_tags.outputs.worker_tag }}
image_tag: ${{ steps.image_tags.outputs.tag }}

steps:
- uses: actions/checkout@v4
Expand All @@ -32,13 +23,10 @@ jobs:

- uses: extractions/setup-just@v1

- name: Get Docker image tags
- name: Get Docker image tag
id: image_tags
run: |
echo "api_tag=$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):api-$GITHUB_SHA" >> $GITHUB_OUTPUT
echo "cli_tag=$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):cli-$GITHUB_SHA" >> $GITHUB_OUTPUT
echo "ui_tag=$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):ui-$GITHUB_SHA" >> $GITHUB_OUTPUT
echo "worker_tag=$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):worker-$GITHUB_SHA" >> $GITHUB_OUTPUT
echo "tag=$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):$GITHUB_SHA" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -49,35 +37,11 @@ jobs:

- name: Docker build & push
run: |
if skopeo inspect "docker://$API_TAG" >/dev/null 2>&1; then
echo "::notice::Skipping API build - tag already exists"
if skopeo inspect "docker://$TAG" >/dev/null 2>&1; then
echo "::notice::Skipping build - tag already exists"
else
just docker-build-api --build-arg GIT_SHA=$GITHUB_SHA --tag $API_TAG
docker push $API_TAG
fi
if skopeo inspect "docker://$CLI_TAG" >/dev/null 2>&1; then
echo "::notice::Skipping CLI build - tag already exists"
else
just docker-build-cli --tag $CLI_TAG
docker push $CLI_TAG
fi
if skopeo inspect "docker://$UI_TAG" >/dev/null 2>&1; then
echo "::notice::Skipping UI build - tag already exists"
else
just docker-build-ui --build-arg GIT_SHA=$GITHUB_SHA --tag $UI_TAG
docker push $UI_TAG
fi
if skopeo inspect "docker://$WORKER_TAG" >/dev/null 2>&1; then
echo "::notice::Skipping worker build - tag already exists"
else
just docker-build-worker --build-arg GIT_SHA=$GITHUB_SHA --tag $WORKER_TAG
docker push $WORKER_TAG
just docker-build --build-arg GIT_SHA=$GITHUB_SHA --tag $TAG
docker push $TAG
fi
env:
API_TAG: ${{ steps.image_tags.outputs.api_tag }}
CLI_TAG: ${{ steps.image_tags.outputs.cli_tag }}
UI_TAG: ${{ steps.image_tags.outputs.ui_tag }}
WORKER_TAG: ${{ steps.image_tags.outputs.worker_tag }}
TAG: ${{ steps.image_tags.outputs.tag }}
5 changes: 1 addition & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,5 @@ jobs:
needs: [build, validate_terraform, package]
uses: ./.github/workflows/deploy-dev.yml
with:
api_docker_image: ${{ needs.package.outputs.api_docker_image }}
cli_docker_image: ${{ needs.package.outputs.cli_docker_image }}
ui_docker_image: ${{ needs.package.outputs.ui_docker_image }}
worker_docker_image: ${{ needs.package.outputs.worker_docker_image }}
docker_image: ${{ needs.package.outputs.docker_image }}
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine3.18
ARG GIT_SHA
ENV SENTRY_RELEASE ${GIT_SHA}
ENV ASPNETCORE_HTTP_PORTS 80
COPY src/TeachingRecordSystem.Api/bin/Release/net8.0/publish/ App/
COPY src/TeachingRecordSystem.Cli/bin/Release/net8.0/publish/ TrsCli/
WORKDIR /App
COPY src/TeachingRecordSystem.Api/bin/Release/net8.0/publish/ Apps/Api/
COPY src/TeachingRecordSystem.Cli/bin/Release/net8.0/publish/ Apps/TrsCli/
COPY src/TeachingRecordSystem.SupportUi/bin/Release/net8.0/publish/ Apps/SupportUi/
COPY src/TeachingRecordSystem.Worker/bin/Release/net8.0/publish/ Apps/Worker/
WORKDIR /Apps

# Install Culture prerequisities
RUN apk add --no-cache \
Expand All @@ -16,12 +18,10 @@ RUN apk add --no-cache \
# Enable all cultures
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

# Install fonts for PDF generation
RUN apk --no-cache add msttcorefonts-installer fontconfig && \
update-ms-fonts && \
fc-cache -f
# Install Postgres client
RUN apk add postgresql14-client

ENV PATH="${PATH}:/TrsCli"
# Fix for invoking trscli
RUN apk add libc6-compat

ENTRYPOINT ["dotnet", "/App/TeachingRecordSystem.Api.dll"]
EXPOSE 80
ENV PATH="${PATH}:/Apps/TrsCli"
1 change: 1 addition & 0 deletions TeachingRecordSystem/TeachingRecordSystem.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
Dockerfile = Dockerfile
nuget.config = nuget.config
EndProjectSection
EndProject
Expand Down
5 changes: 0 additions & 5 deletions TeachingRecordSystem/src/TeachingRecordSystem.Cli/Dockerfile

This file was deleted.

19 changes: 0 additions & 19 deletions TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions TeachingRecordSystem/src/TeachingRecordSystem.Worker/Dockerfile

This file was deleted.

25 changes: 4 additions & 21 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,11 @@ watch-ui:
watch-worker:
@cd {{solution-root / "src" / "TeachingRecordSystem.Worker"}} && dotnet watch

# Build the API Docker image
docker-build-api *ARGS:
@cd {{solution-root / "src" / "TeachingRecordSystem.Api"}} && dotnet publish -c Release
@cd {{solution-root / "src" / "TeachingRecordSystem.Cli"}} && dotnet publish -c Release
@cd {{solution-root}} && docker build . -f {{"src" / "TeachingRecordSystem.Api" / "Dockerfile"}} {{ARGS}}

# Build the CLI Docker image
docker-build-cli *ARGS:
@cd {{solution-root / "src" / "TeachingRecordSystem.Cli"}} && dotnet publish -c Release
@cd {{solution-root}} && docker build . -f {{"src" / "TeachingRecordSystem.Cli" / "Dockerfile"}} {{ARGS}}

# Build the Support UI Docker image
docker-build-ui *ARGS:
# Build the Docker image
docker-build *ARGS:
npm install -g sass
@cd {{solution-root / "src" / "TeachingRecordSystem.SupportUi"}} && dotnet publish -c Release
@cd {{solution-root}} && docker build . -f {{"src" / "TeachingRecordSystem.SupportUi" / "Dockerfile"}} {{ARGS}}

# Build the worker Docker image
docker-build-worker *ARGS:
@cd {{solution-root / "src" / "TeachingRecordSystem.Worker"}} && dotnet publish -c Release
@cd {{solution-root / "src" / "TeachingRecordSystem.Cli"}} && dotnet publish -c Release
@cd {{solution-root}} && docker build . -f {{"src" / "TeachingRecordSystem.Worker" / "Dockerfile"}} {{ARGS}}
@cd {{solution-root}} && dotnet publish -c Release
@cd {{solution-root}} && docker build . {{ARGS}}

# Set a configuration entry in user secrets for running the apps
set-secret key value:
Expand Down
Loading

0 comments on commit a3a0f4f

Please sign in to comment.