-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (121 loc) · 4.79 KB
/
deploy.yaml
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
name: Deploy
on:
push:
branches: ['main', 'develop']
workflow_dispatch:
jobs:
build:
name: Build & Deploy
runs-on: ubuntu-latest
env:
TF_WORKSPACE: ${{ github.ref == 'refs/heads/main' && 'production' || (github.ref == 'refs/heads/develop' && 'development') }}
TF_VAR_db_password: ${{ secrets.DB_PASSWORD }}
TF_VAR_db_app_username: ${{ secrets.DB_APP_USERNAME }}
TF_VAR_db_app_password: ${{ secrets.DB_APP_PASSWORD }}
TF_VAR_deployer_public_key: ${{ secrets.DEPLOYER_PUBLIC_KEY }}
TF_VAR_s3_bucket_terraform: ${{ secrets.S3_BUCKET_TERRAFORM }}
TF_VAR_git_sha: ${{ github.sha }}
TF_VAR_cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
TF_VAR_cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
TF_VAR_jwt_public_key: ${{ secrets.JWT_PUBLIC_KEY }}
TF_VAR_jwt_private_key: ${{ secrets.JWT_PRIVATE_KEY }}
TF_VAR_ssl_cert: ${{ secrets.SSL_CERT }}
TF_VAR_ssl_key: ${{ secrets.SSL_KEY }}
TF_VAR_google_refresh_token: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
TF_VAR_google_credentials_web_json: ${{ secrets.GOOGLE_CREDENTIALS_WEB_JSON }}
TF_VAR_google_credentials_installed_json: ${{ secrets.GOOGLE_CREDENTIALS_INSTALLED_JSON }}
TF_VAR_aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
TF_VAR_aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
name: pnpm setup
with:
version: 8
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.5'
cache: 'pnpm'
- name: pnpm install
run: |
pnpm --filter client install
- name: Build client just for checks
run: |
pnpm --filter client run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-north-1
- name: Login to Amazon ECR
id: loginecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Server image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.loginecr.outputs.registry }}/${{ secrets.ECR_REPOSITORY }}:server-${{ github.sha }}
target: server
- name: Worker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.loginecr.outputs.registry }}/${{ secrets.ECR_REPOSITORY }}:worker-${{ github.sha }}
target: worker
- name: Migrate image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.loginecr.outputs.registry }}/${{ secrets.ECR_REPOSITORY }}:migrate-${{ github.sha }}
target: migrate
- name: Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
- name: Terraform init
working-directory: terraform
run: terraform init
- name: Terraform Apply
id: terraform-apply
working-directory: terraform
run: |
terraform apply -auto-approve
- name: Terraform Output
id: terraform-output
working-directory: terraform
run: |
echo "client_bucket=$(terraform output -raw client_bucket)" >> $GITHUB_OUTPUT
echo "api_origin=$(terraform output -raw api_origin)" >> $GITHUB_OUTPUT
- name: Build client
env:
VITE_GRAPHQL_ENDPOINT: ${{ steps.terraform-output.outputs.api_origin }}/graphql
VITE_API_ORIGIN: ${{ steps.terraform-output.outputs.api_origin }}
VITE_DEPLOYMENT: ${{ env.TF_WORKSPACE }}
VITE_UPLOAD_ENABLED: ${{ env.TF_WORKSPACE == 'production' && 'false' || 'true' }}
GOOGLE_CREDENTIALS_WEB_JSON: ${{ secrets.GOOGLE_CREDENTIALS_WEB_JSON }}
NODE_ENV: production
run: |
VITE_GOOGLE_CLIENT_ID=$(echo $GOOGLE_CREDENTIALS_WEB_JSON | jq -r '.client_id')
pnpm --filter client run build
- name: Deploy Client
uses: jakejarvis/s3-sync-action@master
with:
args: --follow-symlinks --delete --cache-control 'max-age=31536000'
env:
AWS_S3_BUCKET: ${{ steps.terraform-output.outputs.client_bucket }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: eu-north-1
SOURCE_DIR: client/dist