Skip to content

Commit

Permalink
Add worker app (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Dec 4, 2023
1 parent 5ddc080 commit f116d04
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/actions/deploy-aks-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
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'
required: true
azure_credentials:
description: 'JSON object containing a service principal that can deploy to the environment'
required: true
Expand All @@ -39,4 +42,5 @@ runs:
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 }}
shell: bash
4 changes: 4 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
ui_docker_image:
type: string
required: true
worker_docker_image:
type: string
required: true

concurrency: deploy_dev
jobs:
Expand All @@ -32,5 +35,6 @@ jobs:
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 }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}

3 changes: 3 additions & 0 deletions .github/workflows/deploy-preprod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
required: true
ui_docker_image:
type: string
worker_docker_image:
type: string
required: true
workflow_dispatch:

Expand Down Expand Up @@ -41,4 +43,5 @@ jobs:
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 }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
4 changes: 4 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
ui_docker_image:
type: string
required: true
worker_docker_image:
type: string
required: true

concurrency: deploy_prod
jobs:
Expand All @@ -32,4 +35,5 @@ jobs:
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 }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
4 changes: 4 additions & 0 deletions .github/workflows/deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
ui_docker_image:
type: string
required: true
worker_docker_image:
type: string
required: true

concurrency: deploy_test
jobs:
Expand All @@ -32,5 +35,6 @@ jobs:
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 }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}

3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
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 }}
secrets: inherit

deploy_preprod:
Expand All @@ -68,6 +69,7 @@ jobs:
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 }}
secrets: inherit

deploy_prod:
Expand All @@ -79,4 +81,5 @@ jobs:
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 }}
secrets: inherit
12 changes: 12 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
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 }}

jobs:
package:
Expand All @@ -21,6 +23,7 @@ jobs:
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 }}

steps:
- uses: actions/checkout@v4
Expand All @@ -35,6 +38,7 @@ jobs:
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
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand Down Expand Up @@ -65,7 +69,15 @@ jobs:
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
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 }}
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,5 @@ jobs:
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 }}
secrets: inherit
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ terraform-destroy: terraform-init

deploy-azure-resources: set-azure-account # make dev deploy-azure-resources CONFIRM_DEPLOY=1
$(if $(CONFIRM_DEPLOY), , $(error can only run with CONFIRM_DEPLOY))
az deployment sub create -l "${REGION}" --template-uri "https://raw.githubusercontent.com/DFE-Digital/tra-shared-services/main/azure/resourcedeploy.json" --parameters "resourceGroupName=${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-rg" 'tags=${RG_TAGS}' "tfStorageAccountName=${RESOURCE_NAME_PREFIX}${SERVICE_SHORT}tfstate${ENV_SHORT}" "tfStorageContainerName=${SERVICE_SHORT}-tfstate" "dbBackupStorageAccountName=${AZURE_BACKUP_STORAGE_ACCOUNT_NAME}" "dbBackupStorageContainerName=${AZURE_BACKUP_STORAGE_CONTAINER_NAME}" "keyVaultNames=['${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-api-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-inf-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-ui-kv']"
az deployment sub create -l "${REGION}" --template-uri "https://raw.githubusercontent.com/DFE-Digital/tra-shared-services/main/azure/resourcedeploy.json" --parameters "resourceGroupName=${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-rg" 'tags=${RG_TAGS}' "tfStorageAccountName=${RESOURCE_NAME_PREFIX}${SERVICE_SHORT}tfstate${ENV_SHORT}" "tfStorageContainerName=${SERVICE_SHORT}-tfstate" "dbBackupStorageAccountName=${AZURE_BACKUP_STORAGE_ACCOUNT_NAME}" "dbBackupStorageContainerName=${AZURE_BACKUP_STORAGE_CONTAINER_NAME}" "keyVaultNames=['${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-api-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-inf-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-ui-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-worker-kv']"

validate-azure-resources: set-azure-account # make dev validate-azure-resources
az deployment sub create -l "${REGION}" --template-uri "https://raw.githubusercontent.com/DFE-Digital/tra-shared-services/main/azure/resourcedeploy.json" --parameters "resourceGroupName=${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-rg" 'tags=${RG_TAGS}' "tfStorageAccountName=${RESOURCE_NAME_PREFIX}${SERVICE_SHORT}tfstate${ENV_SHORT}" "tfStorageContainerName=${SERVICE_SHORT}-tfstate" "dbBackupStorageAccountName=${AZURE_BACKUP_STORAGE_ACCOUNT_NAME}" "dbBackupStorageContainerName=${AZURE_BACKUP_STORAGE_CONTAINER_NAME}" "keyVaultNames=['${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-api-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-inf-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-ui-kv']" --what-if
az deployment sub create -l "${REGION}" --template-uri "https://raw.githubusercontent.com/DFE-Digital/tra-shared-services/main/azure/resourcedeploy.json" --parameters "resourceGroupName=${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-rg" 'tags=${RG_TAGS}' "tfStorageAccountName=${RESOURCE_NAME_PREFIX}${SERVICE_SHORT}tfstate${ENV_SHORT}" "tfStorageContainerName=${SERVICE_SHORT}-tfstate" "dbBackupStorageAccountName=${AZURE_BACKUP_STORAGE_ACCOUNT_NAME}" "dbBackupStorageContainerName=${AZURE_BACKUP_STORAGE_CONTAINER_NAME}" "keyVaultNames=['${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-api-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-inf-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-ui-kv', '${RESOURCE_NAME_PREFIX}-${SERVICE_SHORT}-${ENV_SHORT}-worker-kv']" --what-if


domains-init: bin/terrafile set-azure-pd-subscription ## make [env] domains-init - terraform init for environment dns/afd resources
Expand Down
15 changes: 15 additions & 0 deletions TeachingRecordSystem/TeachingRecordSystem.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeachingRecordSystem.Suppor
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FormFlow", "lib\formflow\src\FormFlow\FormFlow.csproj", "{DA3F55CA-6B95-4A85-A3D6-2997C3149A63}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeachingRecordSystem.Worker", "src\TeachingRecordSystem.Worker\TeachingRecordSystem.Worker.csproj", "{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -178,6 +180,18 @@ Global
{DA3F55CA-6B95-4A85-A3D6-2997C3149A63}.Release|x64.Build.0 = Release|Any CPU
{DA3F55CA-6B95-4A85-A3D6-2997C3149A63}.Release|x86.ActiveCfg = Release|Any CPU
{DA3F55CA-6B95-4A85-A3D6-2997C3149A63}.Release|x86.Build.0 = Release|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Debug|x64.ActiveCfg = Debug|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Debug|x64.Build.0 = Debug|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Debug|x86.ActiveCfg = Debug|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Debug|x86.Build.0 = Debug|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Release|Any CPU.Build.0 = Release|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Release|x64.ActiveCfg = Release|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Release|x64.Build.0 = Release|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Release|x86.ActiveCfg = Release|Any CPU
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -194,6 +208,7 @@ Global
{EB46905A-F7B4-4BDC-B376-6091264D6303} = {91DCFC76-6636-4AC1-B81C-7F8AE1F22116}
{407EB5A5-8B4F-4F7D-80BA-E39AB6AD013C} = {91DCFC76-6636-4AC1-B81C-7F8AE1F22116}
{DA3F55CA-6B95-4A85-A3D6-2997C3149A63} = {837E2941-F1CC-41EF-A652-B605101B2E84}
{E7D4BCFD-E610-41E2-B209-0BE13799C7A8} = {837E2941-F1CC-41EF-A652-B605101B2E84}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61D239F9-888B-4D01-84BC-9276C92383EA}
Expand Down
18 changes: 18 additions & 0 deletions TeachingRecordSystem/src/TeachingRecordSystem.Worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine3.18
ARG GIT_SHA
ENV GitSha ${GIT_SHA}
COPY src/TeachingRecordSystem.Worker/bin/Release/net7.0/publish/ App/
COPY src/TeachingRecordSystem.Cli/bin/Release/net7.0/publish/ TrsCli/
WORKDIR /App

# Install Culture prerequisities
RUN apk add --no-cache \
tzdata \
icu-data-full \
icu-libs

# Enable all cultures
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

ENTRYPOINT ["dotnet", "/App/TeachingRecordSystem.Worker.dll"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);

var host = builder.Build();
await host.RunAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<UserSecretsId>TeachingRecordSystemWorker</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TeachingRecordSystem.Core\TeachingRecordSystem.Core.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ docker-build-ui *ARGS:
@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}}

# Set a configuration entry in user secrets for the API project
set-api-secret key value:
@cd {{solution-root / "src" / "TeachingRecordSystem.Api"}} && dotnet user-secrets set "{{key}}" "{{value}}"
Expand Down
41 changes: 41 additions & 0 deletions terraform/aks/app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,44 @@ module "ui_application" {
probe_path = "/health"
replicas = var.ui_replicas
}

module "worker_application_configuration" {
source = "git::https://github.com/DFE-Digital/terraform-modules.git//aks/application_configuration?ref=testing"

namespace = var.namespace
environment = var.environment_name
azure_resource_prefix = var.azure_resource_prefix
service_short = var.service_short_name
config_short = var.environment_short_name
secret_key_vault_short = "worker"

config_variables = {
PlatformEnvironment = var.environment_name
}

secret_variables = {
ConnectionStrings__DefaultConnection = module.postgres.dotnet_connection_string
StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=${azurerm_storage_account.app_storage.name};AccountKey=${azurerm_storage_account.app_storage.primary_access_key}"
}
}

module "worker_application" {
source = "git::https://github.com/DFE-Digital/terraform-modules.git//aks/application?ref=testing"
depends_on = [kubernetes_job.migrations, kubernetes_job.reporting_migrations]

name = "worker"
is_web = false

namespace = var.namespace
environment = var.environment_name
service_name = var.service_name

cluster_configuration_map = module.cluster_data.configuration_map

kubernetes_config_map_name = module.worker_application_configuration.kubernetes_config_map_name
kubernetes_secret_name = module.worker_application_configuration.kubernetes_secret_name

docker_image = var.worker_docker_image
replicas = var.worker_replicas
max_memory = var.worker_max_memory
}
14 changes: 14 additions & 0 deletions terraform/aks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ variable "ui_docker_image" {
type = string
}

variable "worker_docker_image" {
type = string
}

variable "deploy_dqt_reporting_server" {
type = bool
default = false
Expand Down Expand Up @@ -90,6 +94,16 @@ variable "ui_replicas" {
default = 1
}

variable "worker_replicas" {
type = number
default = 1
}

variable "worker_max_memory" {
type = string
default = "1Gi"
}

variable "postgres_flexible_server_sku" {
type = string
default = "B_Standard_B1ms"
Expand Down
1 change: 1 addition & 0 deletions terraform/aks/workspace_variables/production.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"api_replicas": 2,
"api_max_memory": "2Gi",
"ui_replicas": 2,
"worker_max_memory": "2Gi",
"postgres_flexible_server_sku": "GP_Standard_D2ds_v4",
"postgres_enable_high_availability": true,
"redis_capacity": 1,
Expand Down

0 comments on commit f116d04

Please sign in to comment.