-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #692 from DFE-Digital/docker-initcontainer
Docker initcontainer
- Loading branch information
Showing
11 changed files
with
146 additions
and
40 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
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 |
---|---|---|
|
@@ -16,14 +16,18 @@ on: | |
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.inputs.environment }} | ||
|
||
env: | ||
IMAGE_NAME: fiat-app | ||
|
||
jobs: | ||
set-env: | ||
name: Determine environment | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
environment: ${{ steps.var.outputs.environment }} | ||
branch: ${{ steps.var.outputs.branch }} | ||
release: ${{steps.var.outputs.release}} | ||
release: ${{ steps.var.outputs.release }} | ||
image-name: ${{ steps.var.outputs.image-name }} | ||
steps: | ||
- if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | ||
name: Get branch name for push/dispatch event | ||
|
@@ -47,6 +51,7 @@ jobs: | |
echo "environment=${ENVIRONMENT,,}" >> $GITHUB_OUTPUT | ||
echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT | ||
echo "release=${RELEASE,,}" >> $GITHUB_OUTPUT | ||
echo "image-name=${{ env.IMAGE_NAME }}" >> $GITHUB_OUTPUT | ||
create-tag: | ||
if: needs.set-env.outputs.environment == 'production' | ||
|
@@ -80,32 +85,79 @@ jobs: | |
core.setFailed(error.message); | ||
} | ||
deploy-image: | ||
build: | ||
name: Build | ||
needs: [ set-env ] | ||
permissions: | ||
id-token: write | ||
contents: read | ||
packages: write | ||
name: Deploy to environment | ||
needs: [ set-env ] | ||
uses: DFE-Digital/deploy-azure-container-apps-action/.github/workflows/[email protected] | ||
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-" | ||
with: | ||
docker-image-name: 'fiat-app' | ||
environment: ${{ needs.set-env.outputs.environment }} | ||
docker-image-name: ${{ needs.set-env.outputs.image-name }} | ||
docker-build-file-name: 'docker/Dockerfile' | ||
docker-build-target: ${{ matrix.stage }} | ||
docker-tag-prefix: ${{ matrix.tag-prefix }} | ||
|
||
import: | ||
name: Import | ||
needs: [ set-env, build ] | ||
permissions: | ||
id-token: write | ||
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-" | ||
with: | ||
environment: ${{ needs.set-env.outputs.environment }} | ||
annotate-release: true | ||
docker-image-name: ${{ needs.set-env.outputs.image-name }} | ||
docker-tag-prefix: ${{ matrix.tag-prefix }} | ||
secrets: | ||
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
azure-acr-client-id: ${{ secrets.ACR_CLIENT_ID }} | ||
azure-acr-name: ${{ secrets.ACR_NAME }} | ||
|
||
deploy: | ||
name: Deploy | ||
needs: [ set-env, import ] | ||
permissions: | ||
id-token: write | ||
uses: DFE-Digital/deploy-azure-container-apps-action/.github/workflows/[email protected] | ||
with: | ||
environment: ${{ needs.set-env.outputs.environment }} | ||
docker-image-name: ${{ needs.set-env.outputs.image-name }} | ||
annotate-release: true | ||
secrets: | ||
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
azure-acr-name: ${{ secrets.ACR_NAME }} | ||
azure-aca-client-id: ${{ secrets.ACA_CLIENT_ID }} | ||
azure-aca-name: ${{ secrets.ACA_CONTAINERAPP_NAME }} | ||
azure-aca-resource-group: ${{ secrets.ACA_RESOURCE_GROUP }} | ||
|
||
run-automated-ui-tests: | ||
name: Run automated UI tests | ||
uses: ./.github/workflows/test-automated-ui.yml | ||
needs: [ deploy-image, set-env ] | ||
needs: [ deploy, set-env ] | ||
if: ${{ needs.set-env.outputs.environment == 'development' }} | ||
with: | ||
environment: ${{ needs.set-env.outputs.environment }} | ||
|
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
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 |
---|---|---|
|
@@ -2,11 +2,17 @@ name: Scan Docker image | |
|
||
on: | ||
push: | ||
branches: main | ||
branches: [ main ] | ||
|
||
jobs: | ||
scan: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
stage: [ | ||
"final", | ||
"initcontainer" | ||
] | ||
outputs: | ||
image: ${{ steps.build.outputs.imageid }} | ||
steps: | ||
|
@@ -25,15 +31,16 @@ jobs: | |
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 }}-${{ github.ref_name }}.tar ${{ steps.build.outputs.imageid }} | ||
|
||
- name: Scan Docker image for CVEs | ||
uses: aquasecurity/[email protected] | ||
with: | ||
input: ${{ github.ref_name }}.tar | ||
input: ${{ matrix.stage }}-${{ github.ref_name }}.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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# exit on failures | ||
set -e | ||
set -o pipefail | ||
|
||
# Apply migrations to FIAT db | ||
ConnectionStrings__DefaultConnection=${ConnectionStrings__DefaultConnection:?} | ||
|
||
declare -A mssqlconn | ||
|
||
for keyvaluepair in $(echo "$ConnectionStrings__DefaultConnection" | sed "s/ //g; s/;/ /g") | ||
do | ||
IFS=" " read -r -a ARR <<< "${keyvaluepair//=/ }" | ||
mssqlconn[${ARR[0]}]=${ARR[1]} | ||
done | ||
|
||
echo "Running FIAT database migrations ..." | ||
until /opt/mssql-tools/bin/sqlcmd -S "${mssqlconn[Server]}" -U "${mssqlconn[UserId]}" -P "${mssqlconn[Password]}" -d "${mssqlconn[Database]}" -C -I -i /app/sql/FiatDbMigrationScript.sql -o /app/sql/FiatDbMigrationScriptOutput.txt | ||
do | ||
cat /app/sql/FiatDbMigrationScriptOutput.txt | ||
echo "Retrying FIAT database migrations ..." | ||
sleep 5 | ||
done | ||
|
||
echo "Done!" |
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
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
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
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
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