-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (87 loc) · 3.08 KB
/
deploy_server.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
name: Deploy Server
on:
push:
branches:
- master
paths:
- packages/image-search-server/src/**
- packages/image-search-server/package.json
jobs:
check-credentials:
name: Check credentials
runs-on: ubuntu-latest
environment: production
outputs:
is_set: ${{ steps.check.outputs.is_set }}
steps:
- name: Check SSH credentials
id: check
run: |
if [[ '${{ secrets.SSH_KEY }}' && '${{ secrets.SSH_HOST }}' && '${{ secrets.SSH_USERNAME }}' ]]; then
echo "is_set=true" >> "$GITHUB_OUTPUT"
else
echo "is_set=false" >> "$GITHUB_OUTPUT"
echo "SSH credentials are not set. Skipping deployment."
fi
check-package:
name: Check package
needs: check-credentials
if: ${{ needs.check-credentials.outputs.is_set == 'true' }}
uses: ./.github/workflows/check.yml
secrets: inherit
with:
cwd: packages/image-search-server
# blocker for commented: https://github.com/oven-sh/bun/issues/6567
deploy:
name: Deploy server
runs-on: ubuntu-latest
needs: check-package
environment: production
defaults:
run:
working-directory: packages/image-search-server
steps:
# - name: Checkout repo
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo '${{ secrets.SSH_KEY }}' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo 'StrictHostKeyChecking no' >> ~/.ssh/config
working-directory: .
# - name: Setup Bun
# uses: oven-sh/setup-bun@f4d14e03ff726c06358e5557344e1da148b56cf7
# - name: Install dependencies
# run: bun install --frozen-lockfile --production
# - name: Build
# run: bun run build
# - name: Deploy
# run: |
# scp dist/image-search-server '${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/image-search-server/image-search-server_new'
# ssh '${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}' /bin/bash << EOF
# pkill -f image-search-server || true
# cd ~/image-search-server
# mv image-search-server_new image-search-server
# nohup ./image-search-server > /dev/null 2>&1 &
# EOF
# temporary solution
- name: Deploy
uses: appleboy/ssh-action@66aa4d343bf909ac4fa0ac52f4e62a9adc354c95
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd
repository_name="$(basename '${{ github.repository }}')"
if [[ ! -d "$repository_name" ]]; then
git clone '${{ github.server_url }}/${{ github.repository }}'
fi
cd "$repository_name"
pkill -f 'bun run start$'
git fetch --all
git reset --hard origin/master
cd packages/image-search-server
bun install --frozen-lockfile --production
nohup bun run start > /dev/null 2>&1 &