-
Notifications
You must be signed in to change notification settings - Fork 17
151 lines (130 loc) · 4.02 KB
/
ci-cd.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: CI/CD
on:
push:
branches:
- mainnet
- testnet
- dev
pull_request:
branches-ignore:
- weblate-tr
env:
TURBO_TELEMETRY_DISABLED: 1
jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Install build libraries # https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling
run: sudo apt-get install -y libpango1.0-dev libcairo2-dev libpixman-1-dev pkg-config libgif-dev
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm'
- name: Install Dependencies
run: pnpm install
- name: Build Project
run: pnpm build
- name: Lint Code
run: pnpm lint
deploy:
needs: build_and_test
if: (github.event_name == 'push') && (github.ref == 'refs/heads/mainnet' || github.ref == 'refs/heads/testnet')
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Install Dependencies
run: pnpm install
- name: Set Docker image metadata for api
uses: docker/metadata-action@v5
id: meta-api
with:
images: ghcr.io/planb-network/blms-api
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=sha-
- name: Set Docker image metadata for web
uses: docker/metadata-action@v5
id: meta-web
with:
images: ghcr.io/planb-network/blms-web
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=sha-
- name: Build and push Docker image for api
uses: docker/bake-action@v5
with:
push: true
files: |
./docker-bake.hcl
${{ steps.meta-api.outputs.bake-file }}
targets: api
- name: Build and push Docker image for web
uses: docker/bake-action@v5
with:
push: true
files: |
./docker-bake.hcl
${{ steps.meta-web.outputs.bake-file }}
targets: web
- name: Copy Docker files to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: 'docker/compose.yml,docker/cdn'
overwrite: true
strip_components: 1
target: ${{ github.ref == 'refs/heads/mainnet' && 'mainnet' || 'testnet' }}
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script_stop: true
script: |
cd ${{ github.ref == 'refs/heads/mainnet' && 'mainnet' || 'testnet' }}
docker compose pull
docker compose stop || true
docker compose rm -f || true
docker compose up -d