-
Notifications
You must be signed in to change notification settings - Fork 31
193 lines (163 loc) · 6.06 KB
/
cd.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: CD
on:
push:
branches:
- master
- prod
tags:
- "v*.*.*"
jobs:
api-deploy:
name: API Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ secrets.AWS_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
mask-aws-account-id: true
- id: login-ecr
name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Set branch-level configuration
run: |
if [[ ${{ github.ref }} == "refs/heads/prod" ]]; then
echo "IMAGE_TAG=prod" >> $GITHUB_ENV
echo "CLUSTER_NAME=${{ vars.AWS_ECS_API_CLUSTER_PROD }}" >> $GITHUB_ENV
echo "SERVICE_NAME=${{ vars.AWS_ECS_API_SERVICE_PROD }}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
echo "CLUSTER_NAME=${{ vars.AWS_ECS_API_CLUSTER_STAGING }}" >> $GITHUB_ENV
echo "SERVICE_NAME=${{ vars.AWS_ECS_API_SERVICE_STAGING }}" >> $GITHUB_ENV
fi
- name: Check for existing image with GIT_SHA
env:
GIT_SHA: ${{ github.sha }}
REPO: ${{ vars.AWS_ECR_API_REPO }}
run: |
image_manifest=$(aws ecr batch-get-image --repository-name $REPO --image-ids imageTag=$GIT_SHA --query 'images[0].imageManifest')
echo "IMAGE_MANIFEST=$image_manifest" >> $GITHUB_ENV
- if: env.IMAGE_MANIFEST == 'null'
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- if: env.IMAGE_MANIFEST == 'null'
name: Build, tag, and push docker image to Amazon ECR
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha
context: .
file: ./packages/daimo-api/Dockerfile
platforms: linux/arm64
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ vars.AWS_ECR_API_REPO }}:${{ github.sha }}
${{ steps.login-ecr.outputs.registry }}/${{ vars.AWS_ECR_API_REPO }}:${{ env.IMAGE_TAG }}
- if: env.IMAGE_MANIFEST != 'null'
name: Add tag to existing image.
env:
REPO: ${{ vars.AWS_ECR_API_REPO }}
run: |
echo "Image exists with GIT_SHA tag, adding tag \"$IMAGE_TAG\" to it."
IMAGE_MANIFEST=$(echo $IMAGE_MANIFEST | jq -c -r)
set +e
output=$(aws ecr put-image --repository-name $REPO --image-tag $IMAGE_TAG --image-manifest "$IMAGE_MANIFEST" 2>&1)
status=$?
set -e
if [[ $status -ne 0 ]]; then
if [[ ! "$output" =~ "ImageAlreadyExistsException" ]]; then
echo $output
exit $status
else
echo "Image already tagged with \"$IMAGE_TAG.\""
fi
fi
- name: Deploy to ECS
run: aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --force-new-deployment > /dev/null
clippy-deploy:
if: github.ref == 'refs/heads/master'
name: Clippy Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ secrets.AWS_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
mask-aws-account-id: true
- id: login-ecr
name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build, tag, and push docker image to Amazon ECR
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha
context: .
file: ./apps/daimo-clippy/Dockerfile
platforms: linux/arm64
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ vars.AWS_ECR_CLIPPY_REPO }}:${{ github.sha }}
${{ steps.login-ecr.outputs.registry }}/${{ vars.AWS_ECR_CLIPPY_REPO }}:latest
- name: Update ECS Clippy Service
run: aws ecs update-service --cluster ${{ vars.AWS_ECS_INTERNAL_CLUSTER_PROD }} --service ${{ vars.AWS_ECS_INTERNAL_SERVICE_PROD }} --force-new-deployment
eas-deploy:
if: github.ref == 'refs/heads/master'
name: EAS Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Install dependencies
run: npm ci
- name: Setup Expo and EAS
uses: expo/expo-github-action@v8
with:
packager: npm
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: Build and publish update
run: npm run build:prod
working-directory: ./apps/daimo-mobile
# Only publish APK on tag (e.g. v1.0.0)
publish-apk:
if: startsWith(github.ref, 'refs/tags/v')
name: Publish APK
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Install dependencies
run: npm ci
- name: Setup Expo and EAS
uses: expo/expo-github-action@v8
with:
packager: npm
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: Build APK with EAS
run: eas build --platform android --profile preview --non-interactive
env:
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
- name: Download APK from EAS
run: |
eas artifact:download --platform android
working-directory: ./apps/daimo-mobile
- name: Publish APK to GitHub Releases
uses: softprops/action-gh-release@v2
with:
files: apps/daimo-mobile/*.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}