-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (104 loc) · 4.3 KB
/
server-control.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
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
name: Server Control
on:
workflow_dispatch:
inputs:
cmd_type:
type: choice
description: 'What do you need to do?'
required: true
default: 'disable'
options:
- enable
- disable
- restart
- update envs and confs (NO DB)
- update DB envs and confs
env:
SERVICE: "nginx"
jobs:
server:
runs-on: ubuntu-latest
steps:
- name: Enable
if: ${{inputs.cmd_type == 'enable'}}
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: |
sudo systemctl start nginx
cd ${{ secrets.TARGET_DOCKER_COMPOSE }}
docker compose start
- name: Disable
if: ${{inputs.cmd_type == 'disable'}}
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: |
sudo systemctl stop ${{ env.SERVICE }}
cd ${{ secrets.TARGET_DOCKER_COMPOSE }}
docker compose stop
- name: Restart
if: ${{inputs.cmd_type == 'restart'}}
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: |
sudo systemctl restart ${{ env.SERVICE }}
cd ${{ secrets.TARGET_DOCKER_COMPOSE }}
docker compose down --rmi all
docker compose up -d
docker system prune -af --volumes
- name: Update envs and confs (NO DB)
if: ${{inputs.cmd_type == 'update envs and confs (NO DB)'}}
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: |
cd ${{ secrets.TARGET_DOCKER_COMPOSE }}
echo '${{ secrets.BACKEND_ENV }}' > ${{ vars.ENV_FILE_BACKEND }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.ENV_FILE_BACKEND }}
echo '${{ secrets.CHAT_SERVICE_ENV }}' > ${{ vars.ENV_FILE_CHAT_SERVICE }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.ENV_FILE_CHAT_SERVICE }}
echo '${{ secrets.CALENDAR_SERVICE_ENV }}' > ${{ vars.ENV_FILE_CALENDAR_SERVICE }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.ENV_FILE_CALENDAR_SERVICE }}
echo '${{ secrets.TG_BOTS_ENV }}' > ${{ vars.ENV_FILE_TG_BOTS }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.ENV_FILE_TG_BOTS }}
echo '${{ secrets.VK_BOTS_ENV }}' > ${{ vars.ENV_FILE_VK_BOTS }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.ENV_FILE_VK_BOTS }}
echo '${{ secrets.GOOGLE_CREDENTIALS_API }}' > ${{ vars.GOOGLE_CREDENTIALS_FILE }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.GOOGLE_CREDENTIALS_FILE }}
echo '${{ secrets.GOOGLE_TOKEN_API }}' > ${{ vars.GOOGLE_TOKEN_FILE }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.GOOGLE_TOKEN_FILE }}
docker compose stop
docker compose create
docker compose start
- name: Update DB envs and confs
if: ${{inputs.cmd_type == 'update DB envs and confs'}}
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: |
cd ${{ secrets.TARGET_DOCKER_COMPOSE }}
echo '${{ secrets.BACKDB_ENV }}' > ${{ vars.ENV_FILE_BACKDB }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.ENV_FILE_BACKDB }}
echo '${{ secrets.TGDB_ENV }}' > ${{ vars.ENV_FILE_TGDB }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.ENV_FILE_TGDB }}
echo '${{ secrets.VKDB_ENV }}' > ${{ vars.ENV_FILE_VKDB }}
sed -i '/DRONE_SSH_PREV_COMMAND_EXIT_CODE/d' ${{ vars.ENV_FILE_VKDB }}
docker compose down --remove-orphans
docker compose up -d