-
Notifications
You must be signed in to change notification settings - Fork 25
154 lines (136 loc) · 4.97 KB
/
bbm_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
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
---
name: bbm-deploy
on:
workflow_dispatch:
push:
paths:
- ".github/workflows/bbm_deploy.yml"
- "autogen/**"
- "buildbot.tac"
- "common_factories.py"
- "constants.py"
- "docker-compose/**"
- "dockerfiles/**"
- "locks.py"
- "master-**"
- "master.cfg"
- "os_info.yaml"
- "script_templates/**"
- "utils.py"
- "validate_master_cfg.sh"
pull_request:
paths:
- ".github/workflows/bbm_deploy.yml"
- "autogen/**"
- "buildbot.tac"
- "common_factories.py"
- "constants.py"
- "docker-compose/**"
- "dockerfiles/**"
- "locks.py"
- "master-**"
- "master.cfg"
- "os_info.yaml"
- "script_templates/**"
- "utils.py"
- "validate_master_cfg.sh"
jobs:
check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Check master.cfg files for DEV container
run: ./validate_master_cfg.sh -e DEV
# When master container is under development we must ensure
# that configuration changes are valid on both buildbot master
# versions, PROD/DEV. Let's say one will bring a new feature
# to Production independently of a master upgrade.
- name: Check master.cfg files for PROD container
run: ./validate_master_cfg.sh -e PROD
- name: Check get_ssh_cnx_num.py
run: |
cd master-libvirt
python get_ssh_cnx_num.py
deploy:
runs-on: ubuntu-22.04
needs: check
steps:
- name: Set up env vars
run: |
echo "DEPLOY=false" >>$GITHUB_ENV
# INFO
echo "GitHub Branch is ${{ github.ref }}"
echo "GitHub Repository is ${{ github.repository }}"
echo "GitHub Event Name is ${{ github.event_name }}"
# DEV environment
if [[ ${{ github.repository }} == 'MariaDB/buildbot' ]] && \
[[ ${{ github.ref }} == 'refs/heads/dev' ]]; then
echo "DEPLOY=true" >>$GITHUB_ENV
echo "BB_ENV=DEV" >>$GITHUB_ENV
echo "DEPLOY_PATH=/srv/dev" >>$GITHUB_ENV
echo "ENV_FILE=.env.dev" >>$GITHUB_ENV
fi
# PROD environment
if [[ ${{ github.repository }} == 'MariaDB/buildbot' ]] && \
[[ ${{ github.ref }} == 'refs/heads/main' ]] && \
[[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
echo "DEPLOY=true" >>$GITHUB_ENV
echo "BB_ENV=PROD" >>$GITHUB_ENV
echo "DEPLOY_PATH=/srv/prod" >>$GITHUB_ENV
echo "ENV_FILE=.env" >>$GITHUB_ENV
fi
- uses: actions/checkout@v4
- name: prepare
env:
PKEY: ${{ secrets[format('BBM_{0}_SSH_PRIVATE_KEY', env.BB_ENV)] }}
THOST: ${{ secrets[format('BBM_{0}_SSH_KNOWN_HOSTS', env.BB_ENV)] }}
run: |
install -m 600 -D /dev/null ~/.ssh/id_ed25519
install -m 600 -D /dev/null ~/.ssh/known_hosts
echo "$PKEY" >~/.ssh/id_ed25519
echo "$THOST" >~/.ssh/known_hosts
- name: shutdown stack
env:
TUSER: ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}
TPORT: ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }}
TIP: ${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }}
TPATH: ${{ env.DEPLOY_PATH }}
if: ${{ env.DEPLOY == 'true' && env.BB_ENV == 'DEV' }}
run: |
ssh -p $TPORT $TUSER@$TIP "cd $TPATH/docker-compose &&
docker-compose down"
- name: deploy
env:
TUSER: ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}
TPORT: ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }}
TIP: ${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }}
TPATH: ${{ env.DEPLOY_PATH }}
if: ${{ env.DEPLOY == 'true' }}
run: |
# Copy files to remote server
rsync -a \
--progress \
--delete \
--exclude-from=rsync.exclude \
-e "ssh -p $TPORT" ./ $TUSER@$TIP:$TPATH/
# Generate docker-compose
ssh -p $TPORT $USER@$TIP "cd $TPATH/docker-compose/
&& ./generate-config.py --env=${BB_ENV,,}"
# Define auto-generated masters
ssh -p $TPORT $USER@$TIP \ "cd $TPATH/ && ./define_masters.py"
ssh -p $TPORT $USER@$TIP \ "cd $TPATH/docker-compose/ &&
ln -sf .. buildbot"
- name: start stack
env:
TUSER: ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}
TPORT: ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }}
TIP: ${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }}
TPATH: ${{ env.DEPLOY_PATH }}
if: ${{ env.DEPLOY == 'true' && env.BB_ENV == 'DEV' }}
run: |
ssh -p $TPORT $TUSER@$TIP "cd $TPATH/docker-compose &&
docker-compose pull &&
docker-compose --env-file ${{ env.ENV_FILE }} up -d"
- name: clean
run: |
rm ~/.ssh/id_ed25519