-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (101 loc) · 3.21 KB
/
ci-cd.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
name: CI/CD
on:
workflow_dispatch:
push:
jobs:
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20.x
cache-dependency-path: "frontend/package-lock.json"
- run: npm ci
- run: npm run format-ci
- run: npm test
- run: npm run build
build-backend:
name: Build Backend
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Setup Poetry
uses: abatilo/[email protected]
- run: poetry install
- run: poetry run pytest -m "not slow" -r fsx
build-images:
name: Build Container Images
needs: [ build-frontend, build-backend ]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
strategy:
fail-fast: true
matrix:
component: [frontend, backend]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-${{ matrix.component }}
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set release version
id: version
shell: bash
run: |
git fetch --prune --unshallow
echo "::set-output name=release::$(git describe --tags --dirty)"
- name: Build ${{ matrix.component }} image
uses: docker/build-push-action@v5
with:
push: true
context: ${{ matrix.component }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
build-args: RELEASE=${{ steps.version.outputs.release }}
deploy:
name: Deploy
needs: [ build-images ]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
environment:
name: production
url: https://snatch.flipdot.org
steps:
- uses: actions/checkout@v4
- name: Setup SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add host fingerprint to known_hosts
run: echo "${{ vars.SSH_HOST_FINGERPRINT }}" >> ~/.ssh/known_hosts
- name: Copy compose.yaml to host
run: scp -r compose.yaml infrastructure ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }}:~/snatch/
- name: Reload docker compose
run: ssh ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }} 'cd ~/snatch && docker compose pull && docker compose up -d'