-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (125 loc) · 4.22 KB
/
build_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: Build & Deploy
on:
push:
branches:
- "main"
jobs:
build:
name: Build docker containers
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 0
- name: Paths filter
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
bot:
- 'bot/**'
- 'common/**'
- '.github/workflows/**'
server:
- 'server/**'
- 'common/**'
- '.github/workflows/**'
client:
- 'client/**'
- 'common/**'
- '.github/workflows/**'
nginx:
- 'nginx/**'
- '.github/workflows/**'
certbot:
- 'certbot/**'
- '.github/workflows/**'
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build toiki-common
if: steps.filter.outputs.common == 'true'
uses: docker/build-push-action@v2
with:
tags: ghcr.io/toiki-org/toiki-common:latest
push: true
context: ./common
cache-from: type=registry,ref=ghcr.io/toiki-org/toiki-common:latest
cache-to: type=inline
- name: Build toiki-build
if: steps.filter.outputs.client == 'true'
uses: docker/build-push-action@v2
with:
tags: ghcr.io/toiki-org/toiki-build:latest
push: true
context: ./client
cache-from: type=registry,ref=ghcr.io/toiki-org/toiki-build:latest
cache-to: type=inline
build-args: |
VITE_API_URL=${{ secrets.API_URL }}
- name: Build & Publish toiki-nginx
if: steps.filter.outputs.client == 'true' || steps.filter.outputs.nginx == 'true'
uses: docker/build-push-action@v2
with:
tags: ghcr.io/toiki-org/toiki-nginx:latest
push: true
context: ./nginx
cache-from: type=registry,ref=ghcr.io/toiki-org/toiki-nginx:latest
cache-to: type=inline
- name: Build & Publish toiki-backend
if: steps.filter.outputs.server == 'true'
uses: docker/build-push-action@v2
with:
tags: ghcr.io/toiki-org/toiki-backend:latest
push: true
context: ./server
cache-from: type=registry,ref=ghcr.io/toiki-org/toiki-backend:latest
cache-to: type=inline
- name: Build & Publish toiki-bot
if: steps.filter.outputs.bot == 'true'
uses: docker/build-push-action@v2
with:
tags: ghcr.io/toiki-org/toiki-bot:latest
push: true
context: ./bot
cache-from: type=registry,ref=ghcr.io/toiki-org/toiki-bot:latest
cache-to: type=inline
- name: Build & Publish toiki-certbot
if: steps.filter.outputs.certbot == 'true'
uses: docker/build-push-action@v2
with:
tags: ghcr.io/toiki-org/toiki-certbot:latest
push: true
context: ./certbot
cache-from: type=registry,ref=ghcr.io/toiki-org/toiki-certbot:latest
cache-to: type=inline
deploy:
needs: [build]
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Git pull
uses: garygrossgarten/github-action-ssh@v0.6.3
with:
command: cd toiki && git pull origin main
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
privateKey: ${{ secrets.PRIVATE_KEY }}
- name: Docker compose up
uses: garygrossgarten/github-action-ssh@v0.6.3
with:
command: cd toiki && docker-compose pull && docker-compose up --quiet-pull --force-recreate -d
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
privateKey: ${{ secrets.PRIVATE_KEY }}
- name: Prune old docker images
uses: garygrossgarten/github-action-ssh@v0.6.3
with:
command: cd toiki && docker system prune -a -f
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
privateKey: ${{ secrets.PRIVATE_KEY }}