Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 7dfe337

Browse files
authored
Merge pull request #137 from communitiesuk/FS-3718
FS-3718 - Amend workflow to deploy automatically
2 parents c3f754e + ba8155c commit 7dfe337

File tree

4 files changed

+166
-71
lines changed

4 files changed

+166
-71
lines changed

.github/workflows/copilot_deploy.yml

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Deploy to AWS
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
environment:
6+
description: Which AWS Account to use
7+
type: choice
8+
required: true
9+
options:
10+
- dev
11+
- test
12+
- uat
13+
- production
14+
run_performance_tests:
15+
required: false
16+
default: false
17+
type: boolean
18+
description: Run performance tests
19+
run_e2e_tests:
20+
required: false
21+
default: true
22+
type: boolean
23+
description: Run e2e tests
24+
push:
25+
# Ignore README markdown
26+
# Only automatically deploy when something in the app or tests folder has changed
27+
paths:
28+
- '!**/README.md'
29+
- 'app/**'
30+
- 'tests/**'
31+
32+
jobs:
33+
paketo_build:
34+
permissions:
35+
packages: write
36+
uses: communitiesuk/funding-service-design-workflows/.github/workflows/package.yml@main
37+
with:
38+
version_to_build: $(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
39+
owner: ${{ github.repository_owner }}
40+
application: funding-service-design-account-store
41+
pre_deploy_tests:
42+
secrets:
43+
E2E_PAT: ${{secrets.E2E_PAT}}
44+
uses: communitiesuk/funding-service-design-workflows/.github/workflows/pre-deploy.yml@main
45+
with:
46+
# Note - no db-name, so defaults to postgres_db
47+
postgres_unit_testing: true
48+
49+
dev_copilot_deploy:
50+
if: inputs.environment == 'dev' || inputs.environment == ''
51+
needs: [pre_deploy_tests, paketo_build]
52+
concurrency: deploy-dev
53+
secrets:
54+
AWS_ACCOUNT: ${{ secrets.AWS_ACCOUNT }}
55+
uses: ./.github/workflows/environment.yml
56+
permissions:
57+
id-token: write # This is required for requesting the JWT
58+
contents: read # This is required for actions/checkout
59+
with:
60+
workspace: 'dev'
61+
62+
test_copilot_deploy:
63+
if: inputs.environment == 'test' || inputs.environment == ''
64+
needs: [pre_deploy_tests, paketo_build]
65+
concurrency: deploy-test
66+
secrets:
67+
AWS_ACCOUNT: ${{ secrets.AWS_ACCOUNT }}
68+
uses: ./.github/workflows/environment.yml
69+
permissions:
70+
id-token: write # This is required for requesting the JWT
71+
contents: read # This is required for actions/checkout
72+
with:
73+
workspace: 'test'
74+
75+
# Allow the capability to override UAT with another branch, but ideally uat and production should be in sync as much as possible
76+
uat_copilot_deploy:
77+
if: inputs.environment == 'uat' || inputs.environment == ''
78+
needs: [pre_deploy_tests, paketo_build]
79+
concurrency: deploy-uat
80+
secrets:
81+
AWS_ACCOUNT: ${{ secrets.AWS_ACCOUNT }}
82+
uses: ./.github/workflows/environment.yml
83+
permissions:
84+
id-token: write # This is required for requesting the JWT
85+
contents: read # This is required for actions/checkout
86+
with:
87+
workspace: 'uat'
88+
89+
# Only run this if the branch being deployed is main
90+
production_copilot_deploy:
91+
if: (inputs.environment == 'production' || inputs.environment == '') && github.ref == 'refs/heads/main'
92+
needs: [pre_deploy_tests, paketo_build]
93+
concurrency: deploy-production
94+
secrets:
95+
AWS_ACCOUNT: ${{ secrets.AWS_ACCOUNT }}
96+
uses: ./.github/workflows/environment.yml
97+
permissions:
98+
id-token: write # This is required for requesting the JWT
99+
contents: read # This is required for actions/checkout
100+
with:
101+
workspace: 'production'
102+
103+
# Can we realistically run E2E at this stage, or just plump for application on the grounds it checks account-store is operational?
104+
post_deploy_tests:
105+
needs: test_copilot_deploy
106+
secrets:
107+
E2E_PAT: ${{secrets.E2E_PAT}}
108+
uses: communitiesuk/funding-service-design-workflows/.github/workflows/post-deploy.yml@main
109+
with:
110+
run_performance_tests: ${{ inputs.run_performance_tests }}
111+
run_e2e_tests: ${{ inputs.run_e2e_tests }}
112+
app_name: application

.github/workflows/deploy.yml

+1-71
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@ name: Deploy to Gov PaaS
33
on:
44
workflow_dispatch:
55
inputs:
6-
environment:
7-
description: Which AWS Account to use
8-
type: choice
9-
required: true
10-
options:
11-
- test
12-
- uat
13-
copilot:
14-
description: Whether to deploy to AWS?
15-
type: boolean
16-
required: false
17-
default: false
186
deploy_to_dev:
197
required: false
208
default: false
@@ -26,7 +14,7 @@ on:
2614

2715
jobs:
2816
test_and_deploy:
29-
if: ${{ github.actor != 'dependabot[bot]' && !github.event.inputs.copilot }}
17+
if: ${{ github.actor != 'dependabot[bot]' }}
3018
uses: communitiesuk/funding-service-design-workflows/.github/workflows/deploy.yml@main
3119
with:
3220
app_name: ${{ github.event.repository.name }}
@@ -43,61 +31,3 @@ jobs:
4331
CF_USER: ${{secrets.CF_USERNAME}}
4432
CF_PASSWORD: ${{secrets.CF_PASSWORD}}
4533
E2E_PAT: ${{secrets.E2E_PAT}}
46-
paketo_build:
47-
permissions:
48-
packages: write
49-
uses: communitiesuk/funding-service-design-workflows/.github/workflows/package.yml@main
50-
with:
51-
version_to_build: $(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
52-
owner: ${{ github.repository_owner }}
53-
application: funding-service-design-account-store
54-
pre_deploy_tests:
55-
if: ${{ github.event.inputs.copilot }}
56-
secrets:
57-
E2E_PAT: ${{secrets.E2E_PAT}}
58-
uses: communitiesuk/funding-service-design-workflows/.github/workflows/pre-deploy.yml@main
59-
with:
60-
db_name: fsd_account_store_test
61-
postgres_unit_testing: true
62-
copilot_build:
63-
if: ${{ github.event.inputs.copilot }}
64-
needs: [pre_deploy_tests, paketo_build]
65-
concurrency: deploy-${{ inputs.environment || 'test' }}
66-
permissions:
67-
id-token: write # This is required for requesting the JWT
68-
contents: read # This is required for actions/checkout
69-
runs-on: ubuntu-latest
70-
environment: ${{ inputs.environment || 'test' }}
71-
steps:
72-
- name: Git clone the repository
73-
uses: actions/checkout@v3
74-
75-
- name: Get current date
76-
id: currentdatetime
77-
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
78-
79-
- name: configure aws credentials
80-
uses: aws-actions/configure-aws-credentials@v2
81-
with:
82-
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/GithubCopilotDeploy
83-
role-session-name: ACCOUNT_STORE_COPILOT_${{ steps.currentdatetime.outputs.datetime }}
84-
aws-region: eu-west-2
85-
86-
- name: Install AWS Copilot CLI
87-
run: |
88-
curl -Lo aws-copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x aws-copilot && sudo mv aws-copilot /usr/local/bin/copilot
89-
90-
- name: Inject Git SHA into manifest
91-
run: |
92-
yq -i '.variables.GITHUB_SHA = "${{ github.sha }}"' copilot/fsd-account-store/manifest.yml
93-
94-
- name: Inject replacement image into manifest
95-
run: |
96-
yq -i '.image.location = "ghcr.io/communitiesuk/funding-service-design-account-store:${{ github.ref_name == 'main' && 'latest' || github.ref_name }}"' copilot/fsd-account-store/manifest.yml
97-
98-
- name: Run database migrations
99-
run: scripts/migration-task-script.py ${{ inputs.environment || 'test' }}
100-
101-
- name: Copilot deploy
102-
run: |
103-
copilot deploy --env ${{ inputs.environment || 'test' }}

.github/workflows/environment.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Environment Deployment
2+
on:
3+
workflow_call:
4+
inputs:
5+
workspace:
6+
required: true
7+
type: string
8+
secrets:
9+
AWS_ACCOUNT:
10+
required: true
11+
12+
jobs:
13+
copilot_deploy:
14+
permissions:
15+
id-token: write # This is required for requesting the JWT
16+
contents: read # This is required for actions/checkout
17+
runs-on: ubuntu-latest
18+
environment: ${{ inputs.workspace }}
19+
steps:
20+
- name: Git clone the repository
21+
uses: actions/checkout@v3
22+
23+
- name: Get current date
24+
id: currentdatetime
25+
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
26+
27+
- name: configure aws credentials
28+
uses: aws-actions/configure-aws-credentials@v2
29+
with:
30+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/GithubCopilotDeploy
31+
role-session-name: ACCOUNT_STORE_${{ inputs.workspace }}_COPILOT_${{ steps.currentdatetime.outputs.datetime }}
32+
aws-region: eu-west-2
33+
34+
- name: Install AWS Copilot CLI
35+
run: |
36+
curl -Lo aws-copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x aws-copilot && sudo mv aws-copilot /usr/local/bin/copilot
37+
38+
- name: Inject Git SHA into manifest
39+
run: |
40+
yq -i '.variables.GITHUB_SHA = "${{ github.sha }}"' copilot/fsd-account-store/manifest.yml
41+
42+
- name: Inject replacement image into manifest
43+
run: |
44+
yq -i '.image.location = "ghcr.io/communitiesuk/funding-service-design-account-store:${{ github.ref_name == 'main' && 'latest' || github.ref_name }}"' copilot/fsd-account-store/manifest.yml
45+
46+
- name: Copilot ${{ inputs.workspace }} deploy
47+
id: deploy_build
48+
run: |
49+
copilot svc deploy --env ${{ inputs.workspace }}

copilot/fsd-account-store/addons/fsd-account-store-cluster.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ Mappings:
2121
"DBMinCapacity": 0.5 # AllowedValues: from 0.5 through 128
2222
"DBMaxCapacity": 8 # AllowedValues: from 0.5 through 128
2323
BastionMap:
24+
dev:
25+
"SecurityGroup": "sg-0b6c7aabb95bf14a9"
2426
test:
2527
"SecurityGroup": "sg-0cf75a004dbade7b8"
28+
uat:
29+
"SecurityGroup": "sg-04017abfef2079894"
2630

2731
Resources:
2832
fsdaccountstoreclusterDBSubnetGroup:

0 commit comments

Comments
 (0)