-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (176 loc) · 6.34 KB
/
Copy pathdeploy.yml
File metadata and controls
194 lines (176 loc) · 6.34 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
- dev
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: false
jobs:
check:
runs-on:
group: default
labels: linux
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432
steps:
- name: Checkout code
uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- uses: oven-sh/setup-bun@v2
- name: Install uv
uses: astral-sh/setup-uv@v10.0.1
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Install cargo-tarpaulin
uses: taiki-e/install-action@v2
with:
tool: cargo-tarpaulin
- name: Install dependencies
run: bun install
- name: Lint
run: bun run lint
- name: Test
run: bun run test
env:
DB_SCHEMA: public
DB_URL: localhost
DB_PORT: ${{ job.services.postgres.ports['5432'] }}
DB_ID: postgres
DB_PW: postgres
DB_DB: postgres
- name: Build
run: bun run build
- uses: atos-actions/clean-self-hosted-runner@v1
if: ${{ always() }}
changepacks:
name: changepacks
runs-on: ubuntu-latest
permissions:
# create pull request comments
pull-requests: write
# Actions > General > Workflow permissions for creating pull request
# Create brench to create pull request
contents: write
needs:
- check
steps:
- uses: actions/checkout@v7
- uses: changepacks/action@main
id: changepacks
- uses: atos-actions/clean-self-hosted-runner@v1
if: ${{ always() }}
outputs:
changepacks: ${{ steps.changepacks.outputs.changepacks }}
deploy:
name: deploy
needs: [check, changepacks]
if: (needs.changepacks.result == 'success' && contains(needs.changepacks.outputs.changepacks, 'package.json')) || github.ref_name == 'dev' || github.ref_name == 'main' || github.event_name == 'workflow_dispatch'
runs-on: self-hosted
environment: ${{ (contains(needs.changepacks.outputs.changepacks, 'package.json') || github.event_name == 'workflow_dispatch') && 'PROD' || 'DEV' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Collect API environment variables
uses: dev-five-git/collect-env-action@main
with:
prefix: 'API_ENV_'
output: 'apis/api/.env'
remove-prefix: true
secrets: ${{ toJson(secrets) }}
- name: Overwrite .env
uses: dev-five-git/overwrite-env-file-action@main
if: ${{ !(contains(needs.changepacks.outputs.changepacks, 'package.json') || github.event_name == 'workflow_dispatch') }}
- name: Compress
run: |
docker build -f Dockerfile.build -t build:latest .
CONTAINER_ID=$(docker create build:latest)
docker cp $CONTAINER_ID:/app/front.tar.gz ./front.tar.gz
docker cp $CONTAINER_ID:/app/api.tar.gz ./api.tar.gz
tar -czf deploy.tar.gz api.tar.gz front.tar.gz docker-compose.yml Dockerfile.front Dockerfile.api nginx.conf apis/api/.env
# zip -r deploy.zip api.tar.gz front.tar.gz docker-compose.yml Dockerfile.front Dockerfile.api nginx.conf apis/api/.env
- name: upload
uses: actions/upload-artifact@v7
with:
name: deploy
path: deploy.tar.gz
retention-days: 1
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@main
if: runner.os == 'macOS'
- name: Install sshpass (macOS only)
if: runner.os == 'macOS'
run: |
brew install hudochenkov/sshpass/sshpass
- name: ssh
uses: appleboy/ssh-action@v1
env:
PORT: ${{ secrets.PORT }}
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
with:
command_timeout: 40m
host: ${{ secrets.SSH_HOSTNAME }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
envs: PORT,DOCKER_BUILDKIT,COMPOSE_DOCKER_CLI_BUILD
script: |
DIR=~/"${{ github.repository }}"
mkdir -p "$DIR"
echo "${{ secrets.SSH_PASSWORD }}" | sudo -S chmod -R 777 "$DIR"
rm -rf "$DIR/deploy.tar.gz"
- name: Scp
run: |
sshpass -p "${{ secrets.SSH_PASSWORD }}" scp -o StrictHostKeyChecking=no -P ${{ secrets.SSH_PORT }} deploy.tar.gz ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOSTNAME }}:~/${{ github.repository }}/deploy.tar.gz
- name: ssh
uses: appleboy/ssh-action@v1
env:
PORT: ${{ secrets.PORT }}
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
with:
command_timeout: 40m
host: ${{ secrets.SSH_HOSTNAME }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
envs: PORT,DOCKER_BUILDKIT,COMPOSE_DOCKER_CLI_BUILD
script: |
set -e
docker buildx inspect devfivebuilder >/dev/null 2>&1 \
|| docker buildx create --name devfivebuilder --use
docker buildx use devfivebuilder
docker buildx inspect --bootstrap
DIR=~/"${{ github.repository }}"
echo "${{ secrets.SSH_PASSWORD }}" | sudo -S chmod -R 777 "$DIR"
# build 진행해서 캐싱 시작, 기존 서버가 켜져있을 때 build 시작
cd "$DIR"
docker compose down --rmi all
tar -xzf "$DIR/deploy.tar.gz" -C "$DIR"
rm -f "$DIR/deploy.tar.gz"
cd "$DIR"
docker compose up -d --build
rm -f "$DIR/front.tar.gz"
rm -f "$DIR/api.tar.gz"
- uses: atos-actions/clean-self-hosted-runner@v1
if: ${{ always() }}