-
Notifications
You must be signed in to change notification settings - Fork 3
46 lines (40 loc) · 1.79 KB
/
workflow.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
name: build-deploy
on:
push:
branches:
- stage
env:
working-directory: .
jobs:
deploy:
runs-on: [self-hosted, '${{ vars.RUNNER }}']
if: github.ref_name == ${{ github.ref_name }}
steps:
- name: Deploy the service to "${{ github.ref_name }}"
uses: appleboy/[email protected]
with:
host: ${{ secrets[format('SSH_HOST_{0}', github.ref_name)] }}
username: ${{ secrets[format('SSH_USER_{0}', github.ref_name)] }}
key: ${{ secrets[format('SSH_PRIVATE_KEY_{0}', github.ref_name)] }}
port: ${{ secrets[format('SSH_PORT_{0}', github.ref_name)] }}
script: |
SSH_NESTED_HOST="${{ secrets[format('SSH_NESTED_HOST_{0}', github.ref_name)] }}"
ssh $SSH_NESTED_HOST -T <<EOA
echo "### Deployment started"
if [ -d "${{ secrets.BASE_PATH }}/${{ github.repository }}-${{ github.ref_name }}" ]; then
cd ${{ secrets.BASE_PATH }}/${{ github.repository }}-${{ github.ref_name }} && \
echo "### Generate ENV file"
> .env
echo BRANCH=${{ github.ref_name }} >> .env
echo PORT=${{ vars[format('PORT_{0}', github.ref_name)] }} >> .env
echo EXCLUDE_FILES=${{ vars[format('EXCLUDE_FILES_{0}', github.ref_name)] }} >> .env
git fetch && \
git checkout ${{ github.ref_name }} && \
git reset --hard origin/${{ github.ref_name }} && \
docker compose -f docker-compose.yml pull && \
docker compose -f docker-compose.yml up -d --build
else
echo "Directory does not exist, aborting script."
exit 1
fi
EOA