-
-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (113 loc) · 4.17 KB
/
build.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
name: Build and Deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
tofu_version: '1.7.1'
tg_version: '0.69.0'
ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
jobs:
build:
strategy:
matrix:
name: [backend, frontend]
name: Build ${{ matrix.name }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./${{ matrix.name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: './${{ matrix.name }}/.nvmrc'
- name: Run npm install
run: npm ci
- name: Run build
run: npm run build
- name: Upload build output
uses: actions/upload-artifact@v4
with:
name: build-output-${{ matrix.name }}
if-no-files-found: error
path: dist
retention-days: 1
merge:
name: Merge Artifacts
runs-on: ubuntu-latest
needs: build
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: build-output
retention-days: 1
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: merge
env:
TF_VAR_dist_dir: ${{ github.workspace }}/dist
TF_VAR_stage: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || '' }}
TF_VAR_pages_branch: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref_name }}
OP_SERVICE_ACCOUNT_TOKEN: ${{ github.ref == 'refs/heads/main' && secrets.OP_TF_PROD_ENV || secrets.OP_TF_DEV_ENV }}
working_dir: 'deployment'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: 'Get build artifact'
uses: actions/download-artifact@v4
with:
name: build-output
path: '${{ github.workspace }}/dist'
- name: Install 1Password CLI
uses: 1password/install-cli-action@v1
- name: Install Terragrunt
uses: eLco/setup-terragrunt@v1
with:
terragrunt_version: ${{ env.tg_version }}
- name: 'Install OpenTofu'
uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ env.tofu_version }}
tofu_wrapper: false
- name: Deploy All
working-directory: ${{ env.working_dir }}
run: op run --env-file=".env" -- terragrunt run-all apply --terragrunt-non-interactive
- name: Deploy Backend Output
id: deploy-backend-output
working-directory: ${{ env.working_dir }}/modules/cloudflare/backend
run: |
echo "output=$(op run --no-masking --env-file='../../../.env' -- terragrunt output -json | jq -c .)" >> $GITHUB_OUTPUT
- name: Deploy Frontend Output
id: deploy-frontend-output
working-directory: ${{ env.working_dir }}/modules/cloudflare/frontend
run: |
echo "output=$(op run --no-masking --env-file='../../../.env' -- terragrunt output -json | jq -c .)" >> $GITHUB_OUTPUT
- name: Publish Frontend to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN_PAGES_UPLOAD }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ fromJson(steps.deploy-frontend-output.outputs.output).pages_project_name.value }}
directory: 'dist/frontend'
branch: ${{ fromJson(steps.deploy-frontend-output.outputs.output).pages_branch.value }}
wranglerVersion: '3'
- name: Comment
uses: actions-cool/maintain-one-comment@v3
if: ${{ github.event_name == 'pull_request' }}
with:
number: ${{ github.event.number }}
body: |
🚀 Preview deployed to:
- Frontend URL: https://${{ fromJson(steps.deploy-frontend-output.outputs.output).immich_subdomain.value }}
- Backend URL: ${{ fromJson(steps.deploy-backend-output.outputs.output).data_api_url.value }}
emojis: 'rocket'
body-include: '<!-- web PR URL -->'