-
Notifications
You must be signed in to change notification settings - Fork 1
211 lines (196 loc) · 8.78 KB
/
Copy pathdeploy-aws.yml
File metadata and controls
211 lines (196 loc) · 8.78 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
name: Deploy to AWS
run-name: ${{ (inputs.ref && format('[{0}] {1}', inputs.ref, inputs.commit_message)) || (github.event_name == 'repository_dispatch' && format('[{0}] {1}', github.event.client_payload.ref, github.event.client_payload.commit_message)) || format('Deploy to AWS ({0})', github.ref_name) }}
on:
push:
branches:
- otr-dev
- otr-prod
pull_request:
workflow_dispatch:
inputs:
environment:
description: "Environment to deploy to"
required: true
type: choice
options:
- otr-dev
- otr-prod
repository_dispatch:
types: [deploy-otr-prod]
workflow_call:
inputs:
ref:
description: "Branch/ref to deploy"
required: true
type: string
commit_hash:
description: "Commit hash being deployed"
required: true
type: string
commit_message:
description: "Commit message"
required: true
type: string
triggered_by:
description: "What triggered this deployment"
required: true
type: string
permissions:
contents: read
packages: write
jobs:
push_to_registry:
runs-on: ubuntu-latest
outputs:
digest: ${{ steps.digest.outputs.digest }}
steps:
- name: Display deployment info
if: inputs.ref || github.event_name == 'repository_dispatch'
run: |
echo "🚀 **Deployment triggered by sync workflow**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Details:**" >> $GITHUB_STEP_SUMMARY
echo "- Branch: \`${{ inputs.ref || github.event.client_payload.ref }}\`" >> $GITHUB_STEP_SUMMARY
echo "- Commit: \`${{ inputs.commit_hash || github.event.client_payload.commit_hash }}\`" >> $GITHUB_STEP_SUMMARY
echo "- Message: ${{ inputs.commit_message || github.event.client_payload.commit_message }}" >> $GITHUB_STEP_SUMMARY
echo "- Triggered by: ${{ inputs.triggered_by || github.event.client_payload.triggered_by }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || github.event_name == 'workflow_dispatch' && inputs.environment || github.event_name == 'workflow_call' && inputs.ref || github.ref }}
- name: Log in to the container registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ghcr.io/${{ github.repository_owner }}/convos-backend
tags: |
type=raw,value=${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || github.event_name == 'workflow_dispatch' && inputs.environment || github.event_name == 'workflow_call' && inputs.ref || github.ref_name }}
type=ref,event=pr
- name: Build and push Docker image
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
id: push
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Set digest output
id: digest
run: echo "digest=${{ steps.push.outputs.digest }}" >> $GITHUB_OUTPUT
deploy_otr_dev:
name: Deploy to OTR Development
runs-on: ubuntu-latest
needs: push_to_registry
if: (inputs.ref == 'otr-dev') || (inputs.environment == 'otr-dev') || (github.ref == 'refs/heads/otr-dev' && !inputs.ref && !inputs.environment)
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || github.event_name == 'workflow_dispatch' && inputs.environment || github.event_name == 'workflow_call' && inputs.ref || github.ref }}
- name: Deploy to OTR Dev Environment
uses: xmtp-labs/terraform-deployer@341a5be3ad29108abcbeaacbae90b11ef43409c1 # v1
timeout-minutes: 20
with:
timeout: 20m
terraform-token: ${{ secrets.TERRAFORM_TOKEN }}
terraform-org: xmtp
terraform-workspace: convos-otr-dev
variable-name: api_image
variable-value: "ghcr.io/xmtplabs/convos-backend@${{ needs.push_to_registry.outputs.digest }}"
variable-value-required-prefix: "ghcr.io/xmtplabs/convos-backend@sha256:"
deploy_otr_prod:
name: Deploy to OTR Production
runs-on: ubuntu-latest
needs: push_to_registry
if: (inputs.ref == 'otr-prod') || (inputs.environment == 'otr-prod') || (github.ref == 'refs/heads/otr-prod' && !inputs.ref && !inputs.environment) || (github.event_name == 'repository_dispatch' && github.event.client_payload.ref == 'otr-prod')
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || github.event_name == 'workflow_dispatch' && inputs.environment || github.event_name == 'workflow_call' && inputs.ref || github.ref }}
- name: Deploy to OTR Production Environment
uses: xmtp-labs/terraform-deployer@341a5be3ad29108abcbeaacbae90b11ef43409c1 # v1
timeout-minutes: 20
with:
timeout: 20m
terraform-token: ${{ secrets.TERRAFORM_TOKEN }}
terraform-org: xmtp
terraform-workspace: convos-otr-prod
variable-name: api_image
variable-value: "ghcr.io/xmtplabs/convos-backend@${{ needs.push_to_registry.outputs.digest }}"
variable-value-required-prefix: "ghcr.io/xmtplabs/convos-backend@sha256:"
test_lifecycle_dev:
name: Test S3 Lifecycle Renewal (Dev)
runs-on: ubuntu-latest
needs: deploy_otr_dev
steps:
- name: Wait for deployment and verify health
run: |
echo "Waiting for deployment to stabilize..."
for i in {1..10}; do
sleep 10
if curl -sf "${{ vars.DEV_API_URL }}/healthcheck" > /dev/null 2>&1; then
echo "Service is healthy after $((i * 10)) seconds"
exit 0
fi
echo "Waiting for service to be ready (attempt $i/10)..."
done
echo "::error::Service did not become healthy after 100s"
exit 1
- name: Test lifecycle renewal endpoint
run: |
response=$(curl -s -w "\n%{http_code}" \
--max-time 60 \
--retry 3 \
--retry-connrefused \
-X POST "${{ vars.DEV_API_URL }}/api/v2/assets/test/lifecycle" \
-H "Authorization: Bearer ${{ secrets.LIFECYCLE_TEST_TOKEN }}")
http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | head -n -1)
echo "$body"
if [ "$http_code" != "200" ] || ! echo "$body" | jq -e '.success == true' > /dev/null 2>&1; then
echo "::error::Lifecycle test failed!"
exit 1
fi
echo "✅ Lifecycle renewal test passed (dev)" >> $GITHUB_STEP_SUMMARY
test_lifecycle_prod:
name: Test S3 Lifecycle Renewal (Prod)
runs-on: ubuntu-latest
needs: deploy_otr_prod
steps:
- name: Wait for deployment and verify health
run: |
echo "Waiting for deployment to stabilize..."
for i in {1..10}; do
sleep 10
if curl -sf "${{ vars.PROD_API_URL }}/healthcheck" > /dev/null 2>&1; then
echo "Service is healthy after $((i * 10)) seconds"
exit 0
fi
echo "Waiting for service to be ready (attempt $i/10)..."
done
echo "::error::Service did not become healthy after 100s"
exit 1
- name: Test lifecycle renewal endpoint
run: |
response=$(curl -s -w "\n%{http_code}" \
--max-time 60 \
--retry 3 \
--retry-connrefused \
-X POST "${{ vars.PROD_API_URL }}/api/v2/assets/test/lifecycle" \
-H "Authorization: Bearer ${{ secrets.LIFECYCLE_TEST_TOKEN }}")
http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | head -n -1)
echo "$body"
if [ "$http_code" != "200" ] || ! echo "$body" | jq -e '.success == true' > /dev/null 2>&1; then
echo "::error::Lifecycle test failed!"
exit 1
fi
echo "✅ Lifecycle renewal test passed (prod)" >> $GITHUB_STEP_SUMMARY