Skip to content

Commit 5253b17

Browse files
mishraompCopilot
andauthored
feat: release (#82)
* feat: prod release * chore: fix the external action call * good catch Co-authored-by: Copilot <[email protected]> * good catch Co-authored-by: Copilot <[email protected]> * good catch Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 52c8398 commit 5253b17

File tree

10 files changed

+258
-6
lines changed

10 files changed

+258
-6
lines changed

.github/workflows/merge.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ jobs:
4343
tag: ${{ needs.vars.outputs.pr }}
4444
app_env: dev
4545
secrets: inherit
46+
retag-images-dev:
47+
name: Retag Images Dev
48+
needs: [deploy_stack_dev, vars]
49+
runs-on: ubuntu-24.04
50+
steps:
51+
- name: retag
52+
uses: shrink/actions-docker-registry-tag@f04afd0559f66b288586792eb150f45136a927fa # v4
53+
with:
54+
registry: ghcr.io
55+
repository: ${{ github.repository }}
56+
target: ${{ needs.vars.outputs.pr }}
57+
tags: |
58+
dev
59+
4660
e2e:
4761
name: E2E Tests
4862
needs: [deploy_stack_dev]
@@ -59,6 +73,19 @@ jobs:
5973
tag: ${{ needs.vars.outputs.pr }}
6074
app_env: test
6175
secrets: inherit
76+
retag-images-test:
77+
name: Retag Images Test
78+
needs: [deploy_stack_test, vars]
79+
runs-on: ubuntu-24.04
80+
steps:
81+
- name: retag
82+
uses: shrink/actions-docker-registry-tag@f04afd0559f66b288586792eb150f45136a927fa # v4
83+
with:
84+
registry: ghcr.io
85+
repository: ${{ github.repository }}
86+
target: ${{ needs.vars.outputs.pr }}
87+
tags: |
88+
test
6289
pause-resources:
6390
name: Pause Resources # This job pauses resources for the merged PR which is needed if the resources were not paused, this is to save money, remove it after cloning.
6491
needs: [deploy_stack_test]

.github/workflows/pause-resources.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,46 @@ jobs:
9393
aws rds stop-db-cluster --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-test --no-cli-pager --output json
9494
else
9595
echo "DB cluster is not in an available state. Current state: $DB_CLUSTER_STATUS"
96+
fi
97+
pause-resources-test:
98+
pause-resources-prod:
99+
name: Pause Resources PROD
100+
environment: prod
101+
needs: [stack-prefix]
102+
runs-on: ubuntu-24.04
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v4
106+
- name: Configure AWS Credentials
107+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
108+
with:
109+
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
110+
role-session-name: gha-pause-resources
111+
aws-region: ca-central-1
112+
- name: Pause AWS Resources
113+
shell: bash
114+
run: |
115+
DB_CLUSTER_STATUS=$(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-prod --query 'DBClusters[0].Status' --output text 2>/dev/null || echo "false")
116+
if [ "$DB_CLUSTER_STATUS" = "false" ]; then
117+
echo "skipping pause operation, DB cluster does not exist"
118+
exit 0
119+
fi
120+
CLUSTER_NAME="ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-prod"
121+
SERVICE_NAME="${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-prod-service"
122+
CLUSTER_EXISTS=$(aws ecs describe-clusters --clusters $CLUSTER_NAME --query 'clusters[0].status' --output text)
123+
if [ "$CLUSTER_EXISTS" = "ACTIVE" ]; then
124+
SERVICE_EXISTS=$(aws ecs describe-services --cluster $CLUSTER_NAME --services $SERVICE_NAME --query 'services[0].status' --output text)
125+
if [ "$SERVICE_EXISTS" = "ACTIVE" ]; then
126+
aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/$CLUSTER_NAME/$SERVICE_NAME --scalable-dimension ecs:service:DesiredCount --min-capacity 0 --max-capacity 0 --no-cli-pager --output json
127+
else
128+
echo "ECS service $SERVICE_NAME does not exist in cluster $CLUSTER_NAME."
129+
fi
130+
else
131+
echo "ECS cluster $CLUSTER_NAME does not exist."
132+
fi
133+
DB_CLUSTER_STATUS=$(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-prod --query 'DBClusters[0].Status' --output text)
134+
if [ "$DB_CLUSTER_STATUS" = "available" ]; then
135+
aws rds stop-db-cluster --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-prod --no-cli-pager --output json
136+
else
137+
echo "DB cluster is not in an available state. Current state: $DB_CLUSTER_STATUS"
96138
fi

.github/workflows/release.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: PROD
2+
on:
3+
workflow_dispatch:
4+
5+
permissions:
6+
id-token: write # This is required for requesting the JWT
7+
contents: write # This is required for actions/checkout
8+
packages: write
9+
jobs:
10+
vars:
11+
name: Vars
12+
runs-on: ubuntu-24.04
13+
outputs:
14+
tag: ${{ steps.changelog.outputs.tag }}
15+
version: ${{ steps.changelog.outputs.version }}
16+
clean_changelog: ${{ steps.changelog.outputs.clean_changelog }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Conventional Changelog Update
20+
uses: TriPSs/conventional-changelog-action@v6
21+
id: changelog
22+
continue-on-error: true
23+
with:
24+
github-token: ${{ github.token }}
25+
output-file: "CHANGELOG.md"
26+
skip-version-file: "true"
27+
skip-commit: "true"
28+
git-push: "true"
29+
retag-images:
30+
name: Retag Images
31+
needs: [vars]
32+
runs-on: ubuntu-24.04
33+
steps:
34+
- name: retag
35+
uses: shrink/actions-docker-registry-tag@f04afd0559f66b288586792eb150f45136a927fa # v4
36+
with:
37+
registry: ghcr.io
38+
repository: ${{ github.repository }}
39+
target: test # this is the tag of the containers to deploy
40+
tags: |
41+
prod
42+
${{ needs.vars.outputs.version}}
43+
resume-resources:
44+
name: Resume Resources # This job resumes resources for the merged PR which is needed if the resources were paused.
45+
needs: [vars]
46+
uses: ./.github/workflows/resume-resources.yml
47+
secrets: inherit
48+
deploy:
49+
name: Deploy Stack
50+
needs: [vars, resume-resources, retag-images]
51+
uses: ./.github/workflows/.deploy_stack.yml
52+
secrets: inherit
53+
with:
54+
environment_name: dev # since we only have one namespace dev, update this to PROD
55+
command: apply
56+
tag: ${{ needs.vars.outputs.version}} # this is the tag of the containers to deploy
57+
app_env: prod
58+
release:
59+
name: Github Release
60+
runs-on: ubuntu-24.04
61+
needs: [vars, deploy]
62+
if: ${{ needs.vars.outputs.tag != '' }}
63+
steps:
64+
- name: Create Release
65+
uses: softprops/action-gh-release@v2
66+
if: ${{ needs.vars.outputs.tag != ''}}
67+
continue-on-error: true
68+
env:
69+
GITHUB_TOKEN: ${{ github.token }}
70+
with:
71+
token: ${{ github.token }}
72+
tag_name: ${{ needs.vars.outputs.tag }}
73+
name: ${{ needs.vars.outputs.tag }}
74+
body: ${{ needs.vars.outputs.clean_changelog }}
75+
pause-resources:
76+
name: Pause Resources # This job pauses resources for the merged PR which is needed if the resources were not paused, this is to save money, remove it after cloning.
77+
needs: [release]
78+
uses: ./.github/workflows/pause-resources.yml
79+
secrets: inherit

.github/workflows/resume-resources.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,49 @@ jobs:
103103
fi
104104
aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test/${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test-service --scalable-dimension ecs:service:DesiredCount --min-capacity 1 --max-capacity 2 --no-cli-pager --output json
105105
aws ecs update-service --cluster ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test --service ${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-test-service --desired-count 1 --no-cli-pager --output json
106+
resume-resources-prod:
107+
name: Resume Resources PROD
108+
environment: prod
109+
needs: [stack-prefix]
110+
runs-on: ubuntu-24.04
111+
steps:
112+
- name: Checkout
113+
uses: actions/checkout@v4
114+
- name: Configure AWS Credentials
115+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
116+
with:
117+
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
118+
role-session-name: gha-resume-resources
119+
aws-region: ca-central-1
120+
- name: Resume AWS Resources
121+
shell: bash
122+
run: |
123+
# check if resources exist first
124+
DB_CLUSTER_STATUS=$(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-prod --query 'DBClusters[0].Status' --output text 2>/dev/null || echo "false")
125+
if [ "$DB_CLUSTER_STATUS" = "false" ]; then
126+
echo "skipping pause operation, DB cluster does not exist"
127+
exit 0
128+
fi
129+
if [ "$DB_CLUSTER_STATUS" = "stopped" ]; then
130+
aws rds start-db-cluster --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-prod --no-cli-pager --output json
131+
# wait for the cluster to be available
132+
attempt=1
133+
max_attempts=20
134+
until [[ $(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-prod --query 'DBClusters[0].Status' --output text) == "available" ]] || [[ $attempt -gt $max_attempts ]]
135+
do
136+
echo "Waiting for DB cluster to be available... Attempt $attempt of $max_attempts"
137+
sleep 60
138+
((attempt++))
139+
done
140+
141+
if [[ $attempt -gt $max_attempts ]]; then
142+
echo "Timeout waiting for DB cluster to become available"
143+
exit 1
144+
fi
145+
echo "DB cluster is now available"
146+
else
147+
echo "DB cluster is not in a stopped state. Current state: $DB_CLUSTER_STATUS"
148+
fi
149+
aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-prod/${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-prod-service --scalable-dimension ecs:service:DesiredCount --min-capacity 1 --max-capacity 2 --no-cli-pager --output json
150+
aws ecs update-service --cluster ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-prod --service ${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-prod-service --desired-count 1 --no-cli-pager --output json
106151

terraform/api/prod/terragrunt.hcl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
include {
2+
path = find_in_parent_folders()
3+
}
4+
locals {
5+
app_env = get_env("app_env")
6+
flyway_image = get_env("flyway_image")
7+
api_image = get_env("api_image")
8+
target_env = get_env("target_env")
9+
10+
}
11+
12+
# Include the common terragrunt configuration for all modules
13+
generate "prod_tfvars" {
14+
path = "prod.auto.tfvars"
15+
if_exists = "overwrite"
16+
disable_signature = true
17+
contents = <<-EOF
18+
target_env = "prod"
19+
flyway_image="${local.flyway_image}"
20+
api_image="${local.api_image}"
21+
app_env="${local.app_env}"
22+
EOF
23+
}

terraform/api/test/terragrunt.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ locals {
1010
}
1111

1212
# Include the common terragrunt configuration for all modules
13-
generate "dev_tfvars" {
14-
path = "dev.auto.tfvars"
13+
generate "test_tfvars" {
14+
path = "test.auto.tfvars"
1515
if_exists = "overwrite"
1616
disable_signature = true
1717
contents = <<-EOF
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
include {
2+
path = find_in_parent_folders()
3+
}
4+
locals {
5+
app_env = get_env("app_env")
6+
}
7+
8+
# Include the common terragrunt configuration for all modules
9+
generate "prod_tfvars" {
10+
path = "prod.auto.tfvars"
11+
if_exists = "overwrite"
12+
disable_signature = true
13+
contents = <<-EOF
14+
target_env = "prod"
15+
backup_retention_period=1
16+
ha_enabled=false
17+
EOF
18+
}

terraform/database/test/terragrunt.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ locals {
66
}
77

88
# Include the common terragrunt configuration for all modules
9-
generate "dev_tfvars" {
10-
path = "dev.auto.tfvars"
9+
generate "test_tfvars" {
10+
path = "test.auto.tfvars"
1111
if_exists = "overwrite"
1212
disable_signature = true
1313
contents = <<-EOF
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
include {
2+
path = find_in_parent_folders()
3+
}
4+
locals {
5+
app_env = get_env("app_env")
6+
target_env = get_env("target_env")
7+
8+
}
9+
10+
# Include the common terragrunt configuration for all modules
11+
generate "prod_tfvars" {
12+
path = "prod.auto.tfvars"
13+
if_exists = "overwrite"
14+
disable_signature = true
15+
contents = <<-EOF
16+
target_env = "prod"
17+
EOF
18+
}

terraform/frontend/test/terragrunt.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ locals {
88
}
99

1010
# Include the common terragrunt configuration for all modules
11-
generate "dev_tfvars" {
12-
path = "dev.auto.tfvars"
11+
generate "test_tfvars" {
12+
path = "test.auto.tfvars"
1313
if_exists = "overwrite"
1414
disable_signature = true
1515
contents = <<-EOF

0 commit comments

Comments
 (0)