-
Notifications
You must be signed in to change notification settings - Fork 14
173 lines (161 loc) · 6.09 KB
/
rdev-update-for-pr.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Create/Update rdev for PR
on:
pull_request:
branches-ignore:
- prod
types:
- opened
- synchronize
- reopened
env:
# Force using BuildKit instead of normal Docker, required so that metadata
# is written/read to allow us to use layers of previous builds as cache.
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_REPO: ${{ secrets.ECR_REPO }}/
STACK_NAME: pr-${{ github.event.number }}
permissions:
id-token: write
issues: write
pull-requests: write
contents: write
jobs:
get_previous_image_digests:
runs-on: ubuntu-22.04
outputs:
ecr_repos: ${{ steps.get_digests.outputs.ecr_repos }}
image_digests: ${{ steps.get_digests.outputs.image_digests }}
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 1800
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ secrets.ECR_REPO }}
- name: Get previous image digests for each repo
id: get_digests
run: |
ECR_REPOS=(corpora-frontend corpora-backend corpora-backend-de corpora-backend-wmg \
corpora-upload-failures corpora-upload-success \
dataset-submissions corpora-upload wmg-processing cellguide-pipeline)
IMAGE_DIGESTS=()
for ecr_repo in "${ECR_REPOS[@]}"; do
IMAGE_DIGESTS+=(`aws ecr list-images --repository-name $ecr_repo --filter tagStatus=TAGGED \
| jq -r --arg STACK_NAME ${STACK_NAME} '[.imageIds[] \
| select(.imageTag==$STACK_NAME)][0].imageDigest'`)
done
echo "ECR_REPOS=${ECR_REPOS[@]}" >> $GITHUB_OUTPUT
echo "IMAGE_DIGESTS=${IMAGE_DIGESTS[@]}" >> $GITHUB_OUTPUT
build_images:
uses: ./.github/workflows/build-images.yml
secrets: inherit
seed-wmg-cellguide-rdev:
runs-on: ubuntu-22.04
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 1800
- name: Checkout Repository
uses: actions/checkout@v2
- name: Grant Execute Permission to Bash Script
run: |
chmod +x ./scripts/populate_rdev_with_cellguide_data.sh ./scripts/populate_rdev_with_wmg_data.sh
- name: Seed cell guide data
run: |
./scripts/populate_rdev_with_cellguide_data.sh ${{ env.STACK_NAME }}
- name: Seed WMG data
run: |
./scripts/populate_rdev_with_wmg_data.sh ${{ env.STACK_NAME }}
deploy-rdev:
runs-on: ubuntu-22.04
concurrency:
group: pr-${{ github.event.number }}-happy
cancel-in-progress: false
needs:
- build_images
- get_previous_image_digests
- seed-wmg-cellguide-rdev
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ secrets.ECR_REPO }}
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Update deployment
uses: chanzuckerberg/github-actions/.github/actions/deploy-happy-stack@deploy-happy-stack-v1.7.2
with:
tfe-token: ${{ secrets.TFE_TOKEN }}
stack-name: ${{ env.STACK_NAME }}
tag: ${{ needs.build_images.outputs.image_tag }}
happy_version: "0.110.1"
delete-previous-images:
runs-on: ubuntu-22.04
needs:
- get_previous_image_digests
- deploy-rdev
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 2700
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ secrets.ECR_REPO }}
- name: Delete previous images
run: |
ECR_REPOS=(${{ needs.get_previous_image_digests.outputs.ecr_repos }})
IMAGE_DIGESTS=(${{ needs.get_previous_image_digests.outputs.image_digests }})
for ((i = 0; i < ${#ECR_REPOS[@]}; ++i)); do
if [ ${IMAGE_DIGESTS[$i]} == "null" ]; then
continue
fi
aws ecr batch-delete-image --repository-name ${ECR_REPOS[$i]} --image-ids imageDigest=${IMAGE_DIGESTS[$i]}
done
summarize:
runs-on: ubuntu-22.04
if: github.event.action == 'opened'
steps:
- name: Summerize deployment
id: summary
run: |
summary="## Deployment Summary"
summary+="\n- backend_url: https://${{ env.STACK_NAME }}-backend.rdev.single-cell.czi.technology"
summary+="\n- backend_de_url: https://${{ env.STACK_NAME }}-backend-de.rdev.single-cell.czi.technology"
summary+="\n- backend_wmg_url: https://${{ env.STACK_NAME }}-backend-wmg.rdev.single-cell.czi.technology"
summary+="\n- frontend_url: https://${{ env.STACK_NAME }}-frontend.rdev.single-cell.czi.technology"
summary+="\n- delete_db_task_definition_arn: arn:aws:ecs:us-west-2:***:task-definition/dp-rdev-${{ env.STACK_NAME}}-deletion:1"
summary+="\n- migrate_db_task_definition_arn: arn:aws:ecs:us-west-2:***:task-definition/dp-rdev-${{ env.STACK_NAME}}-migration:1"
echo "SUMMARY=$summary" >> $GITHUB_OUTPUT
- name: Post Comment
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "${{ steps.summary.outputs.summary}}"
})
rdev-tests:
uses: ./.github/workflows/rdev-tests.yml
secrets: inherit
needs:
- deploy-rdev