-
Notifications
You must be signed in to change notification settings - Fork 20
131 lines (115 loc) · 4.93 KB
/
upgrade.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
on:
push:
branches:
- 'staging'
- 'dev'
- 'testnet'
- 'mainnet'
name: Upgrade Relayer Clusters
jobs:
build-and-push-ecr:
runs-on: buildjet-16vcpu-ubuntu-2204-arm
outputs:
image: ${{ steps.login-ecr.outputs.registry }}/relayer-${{ github.ref_name }}:${{ github.sha }}
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "us-east-2"
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3
- name: Build, tag, and push image to Amazon ECR
id: docker-build-push
uses: docker/build-push-action@v5
env:
IMAGE: ${{ steps.login-ecr.outputs.registry }}/relayer-${{ github.ref_name }}
CARGO_FEATURES: ${{ github.ref_name == 'dev' && 'dev-metrics' || 'default' }}
with:
platforms: linux/arm64
context: .
file: ./docker/release/Dockerfile
build-args: |
CARGO_FEATURES=${{ env.CARGO_FEATURES }}
push: true
tags: ${{ env.IMAGE }}:${{ github.sha }},${{ env.IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
setup-cluster-names:
runs-on: ubuntu-latest
outputs:
cluster_names: ${{ steps.gen-cluster-names.outputs.cluster_names }}
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- id: gen-cluster-names
run: >-
if [[ "${{ github.ref_name }}" == "staging" ]]; then
NUM_CLUSTERS=${{ vars.NUM_CLUSTERS_STAGING }}
NUM_SINGLENODE_CLUSTERS=${{ vars.NUM_SINGLENODE_CLUSTERS_STAGING }}
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
NUM_CLUSTERS=${{ vars.NUM_CLUSTERS_DEV }}
NUM_SINGLENODE_CLUSTERS=${{ vars.NUM_SINGLENODE_CLUSTERS_DEV }}
elif [[ "${{ github.ref_name }}" == "testnet" ]]; then
NUM_CLUSTERS=${{ vars.NUM_CLUSTERS_TESTNET }}
NUM_SINGLENODE_CLUSTERS=${{ vars.NUM_SINGLENODE_CLUSTERS_TESTNET }}
elif [[ "${{ github.ref_name }}" == "mainnet" ]]; then
NUM_CLUSTERS=${{ vars.NUM_CLUSTERS_MAINNET }}
NUM_SINGLENODE_CLUSTERS=${{ vars.NUM_SINGLENODE_CLUSTERS_MAINNET }}
else
echo "Unsupported branch. Defaulting to 1 cluster."
NUM_CLUSTERS=1
NUM_SINGLENODE_CLUSTERS=0
fi
names=$(python -c "import json;
cluster_names = [ \"${{ github.ref_name }}-cluster\" + str(i) for i in range($NUM_CLUSTERS)];
cluster_names.extend([ \"${{ github.ref_name }}-sn-cluster\" + str(i) for i in range($NUM_SINGLENODE_CLUSTERS)]);
print(json.dumps(cluster_names))")
echo "cluster_names={ \"cluster\": $names }" >> $GITHUB_OUTPUT
upgrade-relayer-clusters:
runs-on: ubuntu-latest
needs: [build-and-push-ecr, setup-cluster-names]
strategy:
matrix: ${{fromJson(needs.setup-cluster-names.outputs.cluster_names)}}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "us-east-2"
- name: Get the existing task definitions
id: fetch-task-def
run: |
aws ecs describe-task-definition --task-definition "${{ matrix.cluster }}-task-def" --query 'taskDefinition' > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: update-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: relayer-node
image: ${{ needs.build-and-push-ecr.outputs.image }}
- name: Deploy Amazon ECS task definition
id: ecs-deploy
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.update-task-def.outputs.task-definition }}
service: ${{ matrix.cluster }}-service
cluster: ${{ matrix.cluster }}
wait-for-service-stability: true
- name: Check for rollback
id: check-rollback
run: |
CURRENT_TASK_DEF_ARN=$(aws ecs describe-services --cluster ${{ matrix.cluster }} --services ${{ matrix.cluster }}-service --query services[0].deployments[0].taskDefinition | jq -r ".")
NEW_TASK_DEF_ARN=${{ steps.ecs-deploy.outputs.task-definition-arn }}
if [ "$CURRENT_TASK_DEF_ARN" != "$NEW_TASK_DEF_ARN" ]; then
echo "Deployment rolled back."
exit 1
fi