-
Notifications
You must be signed in to change notification settings - Fork 2
76 lines (69 loc) · 2.58 KB
/
d0018e-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
name: d0018e-deploy
on:
push:
branches: [ "main" ]
paths-ignore:
- 'docs/**'
- 'ansible/**'
- 'README.md'
- '.gitignore'
pull_request:
branches: [ "main" ]
types: [ "closed" ]
paths-ignore:
- 'docs/**'
- 'ansible/**'
- 'README.md'
- '.gitignore'
workflow_dispatch:
jobs:
test:
if: github.event.pull_request.merged == true || github.ref == 'refs/heads/main'
name: Test docker-compose file and containers
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up environment files
run: |
cp .db-example .db
cp .env-example .env
sed -i 's/MYSQL_PASSWORD=""/MYSQL_PASSWORD="${{ secrets.MYSQL_PASSWORD }}"/g' .db
sed -i 's/MYSQL_ROOT_PASSWORD=""/MYSQL_ROOT_PASSWORD="${{ secrets.MYSQL_ROOT_PASSWORD }}"/g' .db
sed -i 's/MYSQL_PASSWORD=""/MYSQL_PASSWORD="${{ secrets.MYSQL_PASSWORD }}"/g' .env
sed -i 's/MYSQL_ROOT_PASSWORD=""/MYSQL_ROOT_PASSWORD="${{ secrets.MYSQL_ROOT_PASSWORD }}"/g' .env
echo "AUTH_KEY=${{ secrets.AUTH_KEY }}" >> .env
- name: Run docker-compose file
run: docker compose up -d
deploy:
if: github.event.pull_request.merged == true || github.ref == 'refs/heads/main'
name: Deploy
needs: test
runs-on: ubuntu-latest
steps:
- name: execute docker-compose on remote host script
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: |
# extract repo name
REPO_NAME=$(basename ${{ github.repository }})
cd $REPO_NAME
# clean up previous build
docker compose down
cd ..
rm -rf -- $REPO_NAME
git clone ${{ github.server_url }}/${{ github.repository }}
# set up.env and.db files
cd $REPO_NAME
cp .db-example .db
cp .env-example .env
sed -i 's/MYSQL_PASSWORD=""/MYSQL_PASSWORD="${{ secrets.MYSQL_PASSWORD }}"/g' .db
sed -i 's/MYSQL_ROOT_PASSWORD=""/MYSQL_ROOT_PASSWORD="${{ secrets.MYSQL_ROOT_PASSWORD }}"/g' .db
sed -i 's/MYSQL_PASSWORD=""/MYSQL_PASSWORD="${{ secrets.MYSQL_PASSWORD }}"/g' .env
sed -i 's/MYSQL_ROOT_PASSWORD=""/MYSQL_ROOT_PASSWORD="${{ secrets.MYSQL_ROOT_PASSWORD }}"/g' .env
echo "AUTH_KEY=${{ secrets.AUTH_KEY }}" >> .env
docker compose up --build -d