-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (46 loc) · 1.77 KB
/
env-system-alternative.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
name: Environment System Alternative
on:
workflow_dispatch:
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
env:
ENVIRONMENT: |-
${{
github.ref_name == 'master' && 'PROD'
|| github.ref_name == 'dev' && 'DEV'
|| github.ref_name == 'test' && 'TEST'
|| 'UNKNOWN'
}}
steps:
- name: Validate Environment
run: |
if [ "${{ env.ENVIRONMENT }}" == "UNKNOWN" ]; then
echo "Error: ENVIRONMENT value is set to UNKNOWN."
exit 1
fi
- name: OpenVPN Install
run: sudo apt-get install openvpn -y
- name: OpenVPN Setup
run: echo "${{ secrets[format('{0}_OPENVPN_CONFIG', env.ENVIRONMENT)] }}" | sudo tee openvpn_config.ovpn > /dev/null
- name: OpenVPN Connect
run: sudo openvpn --config openvpn_config.ovpn --daemon
- name: Wait for a VPN connection
timeout-minutes: 1
run: until ping -c1 ${{ secrets[format('{0}_SSH_HOST', env.ENVIRONMENT)] }}; do sleep 2; done
- name: Connect SSH and Deploy Project
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets[format('{0}_SSH_HOST', env.ENVIRONMENT)] }}
username: ${{ secrets[format('{0}_SSH_USERNAME', env.ENVIRONMENT)] }}
key: ${{ secrets[format('{0}_SSH_PRIVATE_KEY', env.ENVIRONMENT)] }}
port: ${{ secrets[format('{0}_SSH_PORT', env.ENVIRONMENT)] }}
allenvs: true
script_stop: true
script: |
git clone --single-branch --branch ${{ github.ref_name }} $GITHUB_SERVER_URL/$GITHUB_REPOSITORY
- name: Kill VPN connection
if: always()
run: |
sudo killall openvpn