-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (58 loc) · 2.39 KB
/
db-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
name: database-deploy
on:
pull_request:
types: [closed]
branches:
- development
jobs:
pull-n-run-docker-compose:
if: startsWith(github.event.pull_request.head.ref, 'database/')
name: Deploy MySQL Container with Docker Compose
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create .database.env file for remote server
run: |
echo "MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }}" >> .database.env
echo "MYSQL_USER=${{ secrets.MYSQL_USER }}" >> .database.env
echo "MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }}" >> .database.env
- name: Copy docker-compose file to remote server
uses: garygrossgarten/github-action-scp@release
with:
local: ./docker-compose-db.yaml
remote: apps/docker-compose-db.yaml
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
- name: Copy .env file to remote server
uses: garygrossgarten/github-action-scp@release
with:
local: ./.database.env
remote: apps/.database.env
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
- name: Copy MySQL init scripts to remote server
uses: garygrossgarten/github-action-scp@release
with:
local: ./infra/mysql-init/
remote: apps/.infra/mysql-init/
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
- name: Access remote server via SSH and run docker-compose
uses: appleboy/ssh-action@master
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
MYSQL_USER: ${{ secrets.MYSQL_USER }}
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
with:
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
port: 22
script: |
docker-compose -f apps/docker-compose-db.yaml down
docker-compose -f apps/docker-compose-db.yaml pull
docker-compose -f apps/docker-compose-db.yaml up -d --remove-orphans