-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (121 loc) · 4.43 KB
/
deploy.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
name: 🚀 Deploy
on:
workflow_dispatch:
inputs:
force_deploy:
description: 'Force the deployment (even if no file changes)'
required: true
type: boolean
default: false
push:
branches:
- main
- dev
concurrency: ${{ github.workflow }}-${{ github.ref }}
env:
CI: true
permissions:
id-token: write
contents: write
defaults:
run:
shell: bash
jobs:
deploy:
name: Deployment
runs-on: 'ubuntu-latest'
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- uses: dorny/paths-filter@v3
name: Check changes
id: changes
with:
base: ${{ github.ref }}
list-files: 'shell'
filters: |
deployRequired:
- 'packages/**'
- 'example/**'
backend:
- 'packages/backend-elysia/**'
- name: Set up QEMU
if: steps.changes.outputs.backend == 'true' || github.event.inputs.force_deploy == 'true'
uses: docker/setup-qemu-action@v3
with:
platforms: linux/arm64
- name: Set up Docker Buildx
if: steps.changes.outputs.backend == 'true' || github.event.inputs.force_deploy == 'true'
uses: docker/setup-buildx-action@v3
with:
platforms: linux/arm64
- name: "🔨 Install dependencies"
if: steps.changes.outputs.deployRequired == 'true' || github.event.inputs.force_deploy == 'true'
run: bun install --frozen-lockfile
- name: "🔨 Build the SDK"
if: steps.changes.outputs.deployRequired == 'true' || github.event.inputs.force_deploy == 'true'
run: bun run build:sdk
- name: "👥 Configure AWS Credentials"
if: steps.changes.outputs.deployRequired == 'true' || github.event.inputs.force_deploy == 'true'
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::262732185023:role/github-action-deploy-role
aws-region: eu-west-1
retry-max-attempts: 5
- name: "👥 Login to Amazon ECR"
if: steps.changes.outputs.deployRequired == 'true' || github.event.inputs.force_deploy == 'true'
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: "🔧 Setup environment"
if: steps.changes.outputs.deployRequired == 'true' || github.event.inputs.force_deploy == 'true'
shell: bash
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "STAGE=prod" >> $GITHUB_ENV
echo "ELYSIA_REPO=backend-elysia-prod" >> $GITHUB_ENV
else
echo "STAGE=dev" >> $GITHUB_ENV
echo "ELYSIA_REPO=backend-elysia-dev" >> $GITHUB_ENV
fi
if [[ "${{ steps.changes.outputs.backend }}" == "true" ]]; then
echo "BACKEND_IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV
else
echo "BACKEND_IMAGE_TAG=latest" >> $GITHUB_ENV
fi
echo "Deployment stage : ${{ env.STAGE }}"
echo "Elysia rep : ${{ env.ELYSIA_REPO }}"
echo "Backend image tag : ${{ env.BACKEND_IMAGE_TAG }}"
- name: "🔨 Build Elysia backend"
if: steps.changes.outputs.backend == 'true' || github.event.inputs.force_deploy == 'true'
uses: docker/build-push-action@v6
with:
file: ./infra/docker/ElysiaDockerfile
platforms: linux/arm64
push: true
tags: |
262732185023.dkr.ecr.eu-west-1.amazonaws.com/${{ env.ELYSIA_REPO }}:latest
262732185023.dkr.ecr.eu-west-1.amazonaws.com/${{ env.ELYSIA_REPO }}:${{ github.sha }}
# Github actions cache
cache-from: type=gha
cache-to: type=gha,mode=min
build-args: |
STAGE=${{ env.STAGE }}
env:
STAGE: ${{ env.STAGE }}
- name: "🚀 SST Deploy"
if: steps.changes.outputs.deployRequired == 'true' || github.event.inputs.force_deploy == 'true'
run: |
STAGE=${STAGE_OVERRIDE:-$STAGE}
echo "Deploying with stage: $STAGE"
bun sst install
bun sst deploy --stage $STAGE
env:
STAGE: ${{ env.STAGE }}
ELYSIA_REPO: ${{ env.ELYSIA_REPO }}
BACKEND_IMAGE_TAG: ${{ env.BACKEND_IMAGE_TAG }}