-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (46 loc) · 1.28 KB
/
deploy.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
name: Deploy
on:
push:
branches:
- main
workflow_dispatch:
env:
SERVER_USER: ${{ vars.SERVER_USER }}
SERVER_HOST: ${{ vars.SERVER_HOST }}
SERVER_DIR: ${{ vars.SERVER_DIR }}
jobs:
build:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build on github
run: docker compose build
build-and-run:
runs-on: self-hosted
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Generate auth hosts
run: ssh-keyscan -H ${{ vars.SERVER_HOST }} >> ~/.ssh/known_hosts
- name: Check connection
run: ssh ${{ vars.SERVER_USER }}@${{ vars.SERVER_HOST }} whoami
- name: Sync with server
run: rsync -avz --exclude='.env' ./ ${{ vars.SERVER_USER }}@${{ vars.SERVER_HOST }}:${{ vars.SERVER_DIR }}
- name: Build
run: |
ssh $SERVER_USER@$SERVER_HOST << EOF
cd $SERVER_DIR
docker compose build
EOF
- name: Run
run: |
ssh $SERVER_USER@$SERVER_HOST << EOF
cd $SERVER_DIR
docker compose up -d
EOF