-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (73 loc) · 3.04 KB
/
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
name: Deploy App
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to deploy'
required: true
jobs:
deploy:
runs-on: ubuntu-latest
env:
HOST: ${{ secrets.DEPLOY_SSH_USER }}@${{ secrets.DEPLOY_SSH_HOST }}
DEPLOY_DIRECTORY: /root/apps/shutdown-from-browser
CONFIG_PATH: /root/apps/shutdown-from-browser/config/config.prod.yaml
ENV_FILE_PATH: /root/apps/shutdown-from-browser/config.env
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.tag }}
- name: Check if tag exists
run: |
git fetch --all --tags
if ! git tag | grep -q "^${{ github.event.inputs.tag }}$"; then
echo "error: Tag '${{ github.event.inputs.tag }}' not found"
exit 1
fi
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
- run: |
cd ./web
npm ci
npm install --legacy-peer-deps
npm run build
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.2
- name: Build app
run: |
go mod download
CGO_ENABLED=0 GOOS=linux go build -ldflags "-w" -a -o sfb ./cmd/shutdown-from-browser
- name: Deploy to VM
run: |
sudo apt-get install -y ssh rsync
echo "$DEPLOY_SSH_KEY" > deploy_key.pem
chmod 600 deploy_key.pem
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "mkdir -p ${{ env.DEPLOY_DIRECTORY }}"
rsync -avz -e 'ssh -i deploy_key.pem -o StrictHostKeyChecking=no' --exclude='.git' ./ ${{ env.HOST }}:${{ env.DEPLOY_DIRECTORY }}
env:
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
- name: Remove old systemd service file
run: |
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "rm -f /etc/systemd/system/shutdown-from-browser.service"
- name: List workspace contents
run: |
echo "Listing deployments folder contents:"
ls -la ${{ github.workspace }}/deployments
- name: Create environment file on server
run: |
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "\
touch ${{ env.ENV_FILE_PATH }} && \
chmod 600 ${{ env.ENV_FILE_PATH }} && \
echo 'CONFIG_PATH=${{ env.CONFIG_PATH }}' > ${{ env.ENV_FILE_PATH }} && \
- name: Copy systemd service file
run: |
scp -i deploy_key.pem -o StrictHostKeyChecking=no ${{ github.workspace }}/deployments/shutdown-from-browser.service ${{ env.HOST }}:/tmp/shutdown-from-browser.service
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "mv /tmp/shutdown-from-browser.service /etc/systemd/system/shutdown-from-browser.service"
- name: Start application
run: |
ssh -i deploy_key.pem -o StrictHostKeyChecking=no ${{ env.HOST }} "systemctl daemon-reload && systemctl restart shutdown-from-browser.service"