generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (89 loc) · 4.97 KB
/
resume-resources.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Resume AWS Resources
on:
#schedule:
# - cron: "0 15 * * 1-5" # Runs every weekday (Monday to Friday) at 7AM PST
workflow_dispatch:
permissions:
id-token: write # This is required for requesting the JWT
contents: write # This is required for actions/checkout
jobs:
stack-prefix:
name: Stack Prefix
uses: ./.github/workflows/.stack-prefix.yml
resume-resources-dev:
name: Resume Resources Dev
needs: [stack-prefix]
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
role-session-name: gha-resume-resources
aws-region: ca-central-1
- name: Resume AWS Resources
shell: bash
run: |
DB_CLUSTER_STATUS=$(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-dev --query 'DBClusters[0].Status' --output text)
if [ "$DB_CLUSTER_STATUS" = "stopped" ]; then
aws rds start-db-cluster --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-dev --no-cli-pager --output json
# wait for the cluster to be available
attempt=1
max_attempts=20
until [[ $(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-dev --query 'DBClusters[0].Status' --output text) == "available" ]] || [[ $attempt -gt $max_attempts ]]
do
echo "Waiting for DB cluster to be available... Attempt $attempt of $max_attempts"
sleep 60
((attempt++))
done
if [[ $attempt -gt $max_attempts ]]; then
echo "Timeout waiting for DB cluster to become available"
exit 1
fi
echo "DB cluster is now available"
else
echo "DB cluster is not in a stopped state. Current state: $DB_CLUSTER_STATUS"
fi
aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev/${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev-service --scalable-dimension ecs:service:DesiredCount --min-capacity 1 --max-capacity 2 --no-cli-pager --output json
aws ecs update-service --cluster ecs-cluster-${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev --service ${{ needs.stack-prefix.outputs.stack_prefix }}-node-api-dev-service --desired-count 1 --no-cli-pager --output json
resume-resources-test:
name: Resume Resources Test
environment: test
needs: [stack-prefix]
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
role-session-name: gha-resume-resources
aws-region: ca-central-1
- name: Resume AWS Resources
shell: bash
run: |
DB_CLUSTER_STATUS=$(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-test --query 'DBClusters[0].Status' --output text)
if [ "$DB_CLUSTER_STATUS" = "stopped" ]; then
aws rds start-db-cluster --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-test --no-cli-pager --output json
# wait for the cluster to be available
attempt=1
max_attempts=20
until [[ $(aws rds describe-db-clusters --db-cluster-identifier ${{ needs.stack-prefix.outputs.stack_prefix }}-aurora-test --query 'DBClusters[0].Status' --output text) == "available" ]] || [[ $attempt -gt $max_attempts ]]
do
echo "Waiting for DB cluster to be available... Attempt $attempt of $max_attempts"
sleep 60
((attempt++))
done
if [[ $attempt -gt $max_attempts ]]; then
echo "Timeout waiting for DB cluster to become available"
exit 1
fi
echo "DB cluster is now available"
else
echo "DB cluster is not in a stopped state. Current state: $DB_CLUSTER_STATUS"
fi
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
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