-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (136 loc) · 4.21 KB
/
Copy pathdeployment.yaml
File metadata and controls
154 lines (136 loc) · 4.21 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
---
name: Deployment
on:
push:
branches:
- master
workflow_dispatch:
jobs:
test:
name: Test
uses: ./.github/workflows/reusable_test.yaml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
build:
name: Build
runs-on: ubuntu-latest
needs: test
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
VITE_GOOGLE_ANALYTICS_ID: G-4LNTLBZCVM
VITE_BACKEND_URL: https://api.githubcontrib.samarchyan.me/
VITE_ADMIN_EMAIL: desecho@gmail.com
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.10.0
- name: Login to GitHub registry
uses: docker/login-action@v3.4.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Checkout code
uses: actions/checkout@v4.2.2
- name: Build and push docker backend image
uses: docker/build-push-action@v6.15.0
with:
push: true
tags: ghcr.io/${{ github.repository }}-backend:latest
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
- name: Build and push docker frontend image
uses: docker/build-push-action@v6.15.0
with:
context: ./frontend
build-args: |
VITE_GOOGLE_ANALYTICS_ID=${{ env.VITE_GOOGLE_ANALYTICS_ID }}
VITE_BACKEND_URL=${{ env.VITE_BACKEND_URL }}
VITE_ADMIN_EMAIL=${{ env.VITE_ADMIN_EMAIL }}
push: true
tags: ghcr.io/${{ github.repository }}-frontend:latest
cache-from: type=gha
cache-to: type=gha,mode=max
upload_files:
name: Upload files
runs-on: ubuntu-latest
needs: build
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
SPACE_NAME: cdn.githubcontrib.samarchyan.me
steps:
- name: Checkout code
uses: actions/checkout@v4.2.2
- name: Set up Python
uses: actions/setup-python@v5.5.0
with:
python-version: "3.12"
- name: Use uv cache
uses: actions/cache@v4.2.3
with:
path: ~/.cache/uv
key: uv
- name: Use venv cache
uses: actions/cache@v4.2.3
with:
path: .venv
key: venv-${{ hashFiles('pyproject.toml', 'uv.lock') }}
- name: Install uv
run: pip install uv
# This is needed to avoid errors when running collectstatic command
- name: Create env files
run: make create-env-files
- name: Create venv
run: make create-venv
- name: Collect static files
run: make collectstatic
- name: Upload static files
uses: BetaHuhn/do-spaces-action@v2.0.146
with:
access_key: ${{ secrets.SPACES_ACCESS_KEY }}
secret_key: ${{ secrets.SPACES_SECRET_KEY }}
space_name: ${{ env.SPACE_NAME }}
space_region: nyc3
source: static
- name: Install doctl
uses: digitalocean/action-doctl@v2.5.1
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Flush CDN cache
run: make flush-cdn-cache
restart_app:
name: Restart app
uses: ./.github/workflows/reusable_restart_app.yaml
needs: upload_files
secrets: inherit
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
migrate_db:
name: Migrate DB
runs-on: ubuntu-latest
needs: restart_app
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- name: Checkout code
uses: actions/checkout@v4.2.2
- name: Install kubectl
uses: azure/setup-kubectl@v4.0.0
- name: Configure kubectl
run: |
mkdir ~/.kube
echo "$KUBECONFIG" > ~/.kube/config
env:
KUBECONFIG: ${{ secrets.KUBECONFIG }} # Done as a variable because it doesn't work in place.
- name: Install doctl
uses: digitalocean/action-doctl@v2.5.1
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Run db migration
run: make prod-migrate