Skip to content

Commit 467429f

Browse files
TheOneFromNorwaytvararu
authored andcommitted
Standardizing conventions/setup
- Dashes instead of underline for github pipelines - Clear separation of concerns in account tf stack - Remove unnecessary `app_version` input
1 parent 70c5563 commit 467429f

File tree

7 files changed

+57
-62
lines changed

7 files changed

+57
-62
lines changed

.github/workflows/data-replication-pipeline.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ on:
2323
permissions: {}
2424

2525
env:
26-
aws-role: ${{ inputs.environment == 'production'
26+
aws_role: ${{ inputs.environment == 'production'
2727
&& 'arn:aws:iam::820242920762:role/GithubDeployDataReplicationInfrastructure'
2828
|| 'arn:aws:iam::393416225559:role/GithubDeployDataReplicationInfrastructure' }}
2929
aws_account_id: ${{ inputs.environment == 'production' && '820242920762' || '393416225559' }}
@@ -80,15 +80,13 @@ jobs:
8080
- name: Configure AWS Credentials
8181
uses: aws-actions/configure-aws-credentials@v5
8282
with:
83-
role-to-assume: ${{ env.aws-role }}
83+
role-to-assume: ${{ env.aws_role }}
8484
aws-region: eu-west-2
8585
- name: Setup python
8686
uses: actions/setup-python@v4
8787
with:
8888
python-version: 3.12.3
8989
cache: pip
90-
- name: Install Python dependencies
91-
run: python3 -m pip install -r script/requirements.txt
9290
- name: Get image digest
9391
id: get-image-digest
9492
run: |
@@ -145,7 +143,7 @@ jobs:
145143
- name: Configure AWS Credentials
146144
uses: aws-actions/configure-aws-credentials@v5
147145
with:
148-
role-to-assume: ${{ env.aws-role }}
146+
role-to-assume: ${{ env.aws_role }}
149147
aws-region: eu-west-2
150148
- name: Download data-replication task definition artifact
151149
uses: actions/download-artifact@v5

.github/workflows/deploy-application.yml

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
- production
1717
- sandbox-alpha
1818
- sandbox-beta
19-
server_types:
19+
server-types:
2020
description: Server types to deploy
2121
required: true
2222
type: choice
@@ -26,7 +26,7 @@ on:
2626
- good-job
2727
- sidekiq
2828
default: all
29-
git_sha_to_deploy:
29+
git-ref-to-deploy:
3030
description: The git commit SHA to deploy.
3131
required: false
3232
type: string
@@ -35,17 +35,13 @@ on:
3535
environment:
3636
required: true
3737
type: string
38-
server_types:
38+
server-types:
3939
required: true
4040
type: string
41-
git_sha_to_deploy:
41+
git-ref-to-deploy:
4242
description: The git commit SHA to deploy.
4343
required: true
4444
type: string
45-
app_version:
46-
description: The git ref to deploy (branch, tag, or commit SHA).
47-
required: false
48-
type: string
4945

5046
permissions: {}
5147

@@ -56,9 +52,9 @@ env:
5652
aws-role: ${{ inputs.environment == 'production'
5753
&& 'arn:aws:iam::820242920762:role/GithubDeployECSService'
5854
|| 'arn:aws:iam::393416225559:role/GithubDeployECSService' }}
59-
aws_account_id: ${{ inputs.environment == 'production' && '820242920762' || '393416225559' }}
60-
cluster_name: mavis-${{ inputs.environment }}
61-
app_version: ${{ inputs.app_version == '' && 'unknown' || inputs.app_version }}
55+
aws-account-id: ${{ inputs.environment == 'production' && '820242920762' || '393416225559' }}
56+
cluster-name: mavis-${{ inputs.environment }}
57+
app-version: ${{ inputs.git-ref-to-deploy == '' && 'unknown' || inputs.git-ref-to-deploy }}
6258

6359
jobs:
6460
prepare-deployment:
@@ -69,12 +65,13 @@ jobs:
6965
strategy:
7066
fail-fast: true
7167
matrix:
72-
service: ${{ inputs.server_types == 'all' && fromJSON('["web", "good-job", "sidekiq"]') || fromJSON(format('["{0}"]', inputs.server_types)) }}
68+
service: ${{ inputs.server-types == 'all' && fromJSON('["web", "good-job", "sidekiq"]') || fromJSON(format('["{0}"]', inputs.server-types)) }}
7369
steps:
7470
- name: Checkout code
7571
uses: actions/checkout@v5
72+
id: checkout-code
7673
with:
77-
ref: ${{ inputs.git_sha_to_deploy || github.sha }}
74+
ref: ${{ inputs.git-ref-to-deploy || github.sha }}
7875
- name: Configure AWS Credentials
7976
uses: aws-actions/configure-aws-credentials@v5
8077
with:
@@ -83,7 +80,7 @@ jobs:
8380
- name: Setup python
8481
uses: actions/setup-python@v4
8582
with:
86-
python-version: 3.12.3
83+
python-version: 3.13.7
8784
cache: pip
8885
- name: Install Python dependencies
8986
run: python3 -m pip install -r script/requirements.txt
@@ -92,7 +89,7 @@ jobs:
9289
run: |
9390
digest=$(aws ecr describe-images \
9491
--repository-name mavis/webapp \
95-
--image-ids imageTag=${{ inputs.git_sha_to_deploy || github.sha }} \
92+
--image-ids imageTag=${{ steps.checkout-code.outputs.commit }} \
9693
--query 'imageDetails[0].imageDigest' \
9794
--output text)
9895
echo "digest=$digest" >> $GITHUB_OUTPUT
@@ -111,13 +108,13 @@ jobs:
111108
with:
112109
task-definition-family: "mavis-${{ matrix.service }}-task-definition-${{ inputs.environment }}-template"
113110
container-name: "application"
114-
image: "${{ env.aws_account_id }}.dkr.ecr.eu-west-2.amazonaws.com/mavis/webapp@${{ steps.get-image-digest.outputs.digest }}"
111+
image: "${{ env.aws-account-id }}.dkr.ecr.eu-west-2.amazonaws.com/mavis/webapp@${{ steps.get-image-digest.outputs.digest }}"
115112
environment-variables: ${{ steps.parse-environment-variables.outputs.parsed_env_vars }}
116113
- name: Rename task definition file
117114
run: mv ${{ steps.create-task-definition.outputs.task-definition }} ${{ runner.temp }}/${{ matrix.service }}-task-definition.json
118115
- name: Populate SSM parameters for ${{ matrix.service }} service
119116
run: |
120-
python3 script/populate_ssm_parameters.py ${{ inputs.environment }} ${{ matrix.service }} --app-version ${{ env.app_version }}
117+
python3 script/populate_ssm_parameters.py ${{ inputs.environment }} ${{ matrix.service }} --app-version ${{ env.app-version }}
121118
- name: Upload artifact for ${{ matrix.service }} task definition
122119
uses: actions/upload-artifact@v4
123120
with:
@@ -135,8 +132,8 @@ jobs:
135132
deploy-web:
136133
name: Deploy web service
137134
runs-on: ubuntu-latest
138-
if: ${{ inputs.server_types == 'web' || inputs.server_types == 'all' }}
139-
needs: [prepare-deployment, approve-deployments]
135+
if: ${{ inputs.server-types == 'web' || inputs.server-types == 'all' }}
136+
needs: [ prepare-deployment, approve-deployments ]
140137
permissions:
141138
id-token: write
142139
steps:
@@ -148,7 +145,7 @@ jobs:
148145
- name: Checkout code
149146
uses: actions/checkout@v5
150147
- name: Download web task definition artifact
151-
uses: actions/download-artifact@v4
148+
uses: actions/download-artifact@v5
152149
with:
153150
path: ${{ runner.temp }}
154151
name: ${{ inputs.environment }}-web-task-definition
@@ -167,7 +164,7 @@ jobs:
167164
with:
168165
task-definition: ${{ runner.temp }}/web-task-definition.json
169166
codedeploy-appspec: config/templates/appspec.yaml
170-
cluster: ${{ env.cluster_name }}
167+
cluster: ${{ env.cluster-name }}
171168
service: mavis-${{ inputs.environment }}-web
172169
codedeploy-application: mavis-${{ inputs.environment }}
173170
codedeploy-deployment-group: blue-green-group-${{ inputs.environment }}
@@ -180,13 +177,13 @@ jobs:
180177
deploy-good-job:
181178
name: Deploy good-job service
182179
runs-on: ubuntu-latest
183-
if: ${{ inputs.server_types == 'good-job' || inputs.server_types == 'all' }}
184-
needs: [prepare-deployment, approve-deployments]
180+
if: ${{ inputs.server-types == 'good-job' || inputs.server-types == 'all' }}
181+
needs: [ prepare-deployment, approve-deployments ]
185182
permissions:
186183
id-token: write
187184
steps:
188185
- name: Configure AWS Credentials
189-
uses: aws-actions/configure-aws-credentials@v4
186+
uses: aws-actions/configure-aws-credentials@v5
190187
with:
191188
role-to-assume: ${{ env.aws-role }}
192189
aws-region: eu-west-2
@@ -204,16 +201,16 @@ jobs:
204201
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
205202
with:
206203
task-definition: ${{ runner.temp }}/good-job-task-definition.json
207-
cluster: ${{ env.cluster_name }}
204+
cluster: ${{ env.cluster-name }}
208205
service: mavis-${{ inputs.environment }}-good-job
209206
force-new-deployment: true
210207
wait-for-service-stability: true
211208

212209
create-sidekiq-deployment:
213210
name: Create sidekiq deployment
214211
runs-on: ubuntu-latest
215-
if: ${{ inputs.server_types == 'sidekiq' || inputs.server_types == 'all' }}
216-
needs: [prepare-deployment, approve-deployments]
212+
if: ${{ inputs.server-types == 'sidekiq' || inputs.server-types == 'all' }}
213+
needs: [ prepare-deployment, approve-deployments ]
217214
permissions:
218215
id-token: write
219216
steps:
@@ -223,7 +220,7 @@ jobs:
223220
role-to-assume: ${{ env.aws-role }}
224221
aws-region: eu-west-2
225222
- name: Download sidekiq task definition artifact
226-
uses: actions/download-artifact@v4
223+
uses: actions/download-artifact@v5
227224
with:
228225
path: ${{ runner.temp }}
229226
name: ${{ inputs.environment }}-sidekiq-task-definition
@@ -236,7 +233,7 @@ jobs:
236233
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
237234
with:
238235
task-definition: ${{ runner.temp }}/sidekiq-task-definition.json
239-
cluster: ${{ env.cluster_name }}
236+
cluster: ${{ env.cluster-name }}
240237
service: mavis-${{ inputs.environment }}-sidekiq
241238
force-new-deployment: true
242239
wait-for-service-stability: true

.github/workflows/deploy-infrastructure.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
description: Deployment environment
99
required: true
1010
type: string
11-
git_ref_to_deploy:
11+
git-ref-to-deploy:
1212
required: true
1313
type: string
1414
workflow_dispatch:
@@ -17,7 +17,7 @@ on:
1717
description: Deployment environment
1818
required: true
1919
type: string
20-
git_ref_to_deploy:
20+
git-ref-to-deploy:
2121
description: The git commit SHA to deploy.
2222
required: false
2323
type: string
@@ -28,12 +28,10 @@ concurrency:
2828
group: deploy-infrastructure-${{ inputs.environment }}
2929

3030
env:
31-
aws_role: ${{ inputs.environment == 'production'
31+
aws-role: ${{ inputs.environment == 'production'
3232
&& 'arn:aws:iam::820242920762:role/GithubDeployMavisAndInfrastructure'
3333
|| 'arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure' }}
34-
aws_account_id: ${{ inputs.environment == 'production'
35-
&& '820242920762' || '393416225559' }}
36-
git_ref_to_deploy: ${{ inputs.git_ref_to_deploy || github.ref_name }}
34+
git-ref-to-deploy: ${{ inputs.git-ref-to-deploy || github.ref_name }}
3735

3836
defaults:
3937
run:
@@ -49,11 +47,11 @@ jobs:
4947
- name: Checkout code
5048
uses: actions/checkout@v5
5149
with:
52-
ref: ${{ env.git_ref_to_deploy }}
50+
ref: ${{ env.git-ref-to-deploy }}
5351
- name: Configure AWS Credentials
5452
uses: aws-actions/configure-aws-credentials@v5
5553
with:
56-
role-to-assume: ${{ env.aws_role }}
54+
role-to-assume: ${{ env.aws-role }}
5755
aws-region: eu-west-2
5856
- name: Install terraform
5957
uses: hashicorp/setup-terraform@v3
@@ -92,11 +90,11 @@ jobs:
9290
- name: Checkout code
9391
uses: actions/checkout@v5
9492
with:
95-
ref: ${{ env.git_ref_to_deploy }}
93+
ref: ${{ env.git-ref-to-deploy }}
9694
- name: Configure AWS Credentials
9795
uses: aws-actions/configure-aws-credentials@v5
9896
with:
99-
role-to-assume: ${{ env.aws_role }}
97+
role-to-assume: ${{ env.aws-role }}
10098
aws-region: eu-west-2
10199
- name: Download artifact
102100
uses: actions/download-artifact@v5

.github/workflows/deploy.yml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Deploy
2-
run-name: Deploy ${{ inputs.git_ref_to_deploy || github.ref_name }} to ${{ inputs.environment }}
2+
run-name: Deploy ${{ inputs.git-ref-to-deploy || github.ref_name }} to ${{ inputs.environment }}
33

44
concurrency:
55
group: deploy-${{ inputs.environment }}
@@ -10,12 +10,12 @@ on:
1010
environment:
1111
required: true
1212
type: string
13-
server_types:
13+
server-types:
1414
required: true
1515
type: string
1616
workflow_dispatch:
1717
inputs:
18-
git_ref_to_deploy:
18+
git-ref-to-deploy:
1919
description:
2020
| # Use blank unicode character (U+2800) to force line-break
2121
Use code from: ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
@@ -33,7 +33,7 @@ on:
3333
- production
3434
- sandbox-alpha
3535
- sandbox-beta
36-
server_types:
36+
server-types:
3737
description: Server types to deploy
3838
required: true
3939
type: choice
@@ -46,7 +46,7 @@ on:
4646
default: all
4747

4848
env:
49-
account_id: ${{ inputs.environment == 'production' && '820242920762' || '393416225559' }}
49+
account-id: ${{ inputs.environment == 'production' && '820242920762' || '393416225559' }}
5050

5151
jobs:
5252
validate-inputs:
@@ -56,8 +56,8 @@ jobs:
5656
- name: Validate inputs
5757
run: |
5858
if [[ "${{ inputs.environment }}" == "preview" || "${{ inputs.environment }}" == "production" ]]; then
59-
if [[ -z "${{ inputs.git_ref_to_deploy }}" ]]; then
60-
echo "Error: git_ref_to_deploy is required for preview and production environments."
59+
if [[ -z "${{ inputs.git-ref-to-deploy }}" ]]; then
60+
echo "Error: git-ref-to-deploy is required for preview and production environments."
6161
exit 1
6262
fi
6363
fi
@@ -71,7 +71,7 @@ jobs:
7171
- name: Checkout code
7272
uses: actions/checkout@v5
7373
with:
74-
ref: ${{ inputs.git_ref_to_deploy || github.sha }}
74+
ref: ${{ inputs.git-ref-to-deploy || github.sha }}
7575
- name: Get git sha
7676
id: get-git-sha
7777
run: echo "git-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
@@ -98,13 +98,13 @@ jobs:
9898
- name: Configure AWS Credentials
9999
uses: aws-actions/configure-aws-credentials@v5
100100
with:
101-
role-to-assume: arn:aws:iam::${{ env.account_id }}:role/GithubDeployMavisAndInfrastructure
101+
role-to-assume: arn:aws:iam::${{ env.account-id }}:role/GithubDeployMavisAndInfrastructure
102102
aws-region: eu-west-2
103103
- name: Compare permissions
104104
id: compare-permissions
105105
run: |
106106
source ./scripts/validate-github-actions-policy.sh
107-
validate_policies arn:aws:iam::${{ env.account_id }}:policy/DeployMavisResources ./account/resources/iam_policy_DeployMavisResources.json
107+
validate_policies arn:aws:iam::${{ env.account-id }}:policy/DeployMavisResources ./account/resources/iam_policy_DeployMavisResources.json
108108
exit $?
109109
update-permissions:
110110
runs-on: ubuntu-latest
@@ -124,10 +124,10 @@ jobs:
124124
- name: Configure AWS Credentials
125125
uses: aws-actions/configure-aws-credentials@v5
126126
with:
127-
role-to-assume: arn:aws:iam::${{ env.account_id }}:role/GithubDeployMavisAndInfrastructure
127+
role-to-assume: arn:aws:iam::${{ env.account-id }}:role/GithubDeployMavisAndInfrastructure
128128
aws-region: eu-west-2
129129
- name: Update IAM policy
130-
run: ./scripts/update-github-actions-policy.sh arn:aws:iam::${{ env.account_id }}:policy/DeployMavisResources ./account/resources/iam_policy_DeployMavisResources.json
130+
run: ./scripts/update-github-actions-policy.sh arn:aws:iam::${{ env.account-id }}:policy/DeployMavisResources ./account/resources/iam_policy_DeployMavisResources.json
131131
deploy-infrastructure:
132132
permissions:
133133
id-token: write
@@ -144,15 +144,14 @@ jobs:
144144
uses: ./.github/workflows/deploy-infrastructure.yml
145145
with:
146146
environment: ${{ inputs.environment }}
147-
git_ref_to_deploy: ${{ inputs.git_ref_to_deploy || github.ref_name }}
147+
git-ref-to-deploy: ${{ inputs.git-ref-to-deploy || github.ref_name }}
148148
deploy-application:
149149
permissions:
150150
id-token: write
151151
needs: [deploy-infrastructure, determine-git-sha]
152-
if: ${{ !cancelled() && inputs.server_types != 'none' && needs.deploy-infrastructure.result == 'success' }}
152+
if: ${{ !cancelled() && inputs.server-types != 'none' && needs.deploy-infrastructure.result == 'success' }}
153153
uses: ./.github/workflows/deploy-application.yml
154154
with:
155155
environment: ${{ inputs.environment }}
156-
server_types: ${{ inputs.server_types }}
157-
git_sha_to_deploy: ${{ needs.determine-git-sha.outputs.git-sha }}
158-
app_version: ${{ inputs.git_ref_to_deploy }}
156+
server-types: ${{ inputs.server-types }}
157+
git-ref-to-deploy: ${{ inputs.git-ref-to-deploy || github.ref_name }}

.github/workflows/refresh-data-replication.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ jobs:
147147
"-var-file=env/${{ inputs.environment }}.tfvars"
148148
"-var=allowed_egress_cidr_blocks=$CIDR_BLOCKS"
149149
"-out=${{ runner.temp }}/tfplan"
150+
"-replace" "aws_rds_cluster.cluster"
150151
)
151152
152153
if [ "${{ env.REPLACE_DB_CLUSTER }}" = "true" ]; then

0 commit comments

Comments
 (0)