Skip to content

Commit 3c57d52

Browse files
committed
Add actions.
0 parents  commit 3c57d52

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Environment System Alternative
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy:
8+
name: Deploy
9+
runs-on: ubuntu-latest
10+
env:
11+
ENVIRONMENT: |-
12+
${{
13+
github.ref_name == 'master' && 'PROD'
14+
|| github.ref_name == 'dev' && 'DEV'
15+
|| github.ref_name == 'test' && 'TEST'
16+
|| 'UNKNOWN'
17+
}}
18+
19+
steps:
20+
- name: Validate Environment
21+
run: |
22+
if [ "${{ env.ENVIRONMENT }}" == "UNKNOWN" ]; then
23+
echo "Error: ENVIRONMENT value is set to UNKNOWN."
24+
exit 1
25+
fi
26+
27+
- name: Get Repo Link
28+
id: get_link
29+
run: echo "::set-output name=repo_link::$(echo $GITHUB_SERVER_URL/$GITHUB_REPOSITORY)"
30+
31+
- name: OpenVPN Install
32+
run: sudo apt-get install openvpn -y
33+
34+
- name: OpenVPN Setup
35+
run: echo "${{ secrets[format('{0}_OPENVPN_CONFIG', env.ENVIRONMENT)] }}" | sudo tee openvpn_config.ovpn > /dev/null
36+
37+
- name: OpenVPN Connect
38+
run: sudo openvpn --config openvpn_config.ovpn --daemon
39+
40+
- name: Wait for a VPN connection
41+
timeout-minutes: 1
42+
run: until ping -c1 ${{ secrets[format('{0}_SSH_HOST', env.ENVIRONMENT)] }}; do sleep 2; done
43+
44+
- name: Connect SSH and Deploy Project
45+
uses: appleboy/[email protected]
46+
with:
47+
host: ${{ secrets[format('{0}_SSH_HOST', env.ENVIRONMENT)] }}
48+
username: ${{ secrets[format('{0}_SSH_USERNAME', env.ENVIRONMENT)] }}
49+
key: ${{ secrets[format('{0}_SSH_PRIVATE_KEY', env.ENVIRONMENT)] }}
50+
port: ${{ secrets[format('{0}_SSH_PORT', env.ENVIRONMENT)] }}
51+
script: |
52+
git clone --single-branch --branch ${{ github.ref_name }} ${{ steps.get_link.outputs.repo_link }}
53+
54+
- name: Kill VPN connection
55+
if: always()
56+
run: |
57+
sudo killall openvpn
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: OpenVPN with SSH
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy:
8+
name: Deploy
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Get Repo Link
13+
id: get_link
14+
run: echo "::set-output name=repo_link::$(echo $GITHUB_SERVER_URL/$GITHUB_REPOSITORY)"
15+
16+
- name: OpenVPN Install
17+
run: sudo apt-get install openvpn -y
18+
19+
- name: OpenVPN Setup
20+
run: echo "${{ secrets.OPENVPN_CONFIG }}" | sudo tee openvpn_config.ovpn > /dev/null
21+
22+
- name: OpenVPN Connect
23+
run: sudo openvpn --config openvpn_config.ovpn --daemon
24+
25+
- name: Wait for a VPN connection
26+
timeout-minutes: 1
27+
run: until ping -c1 ${{ secrets.SSH_HOST }}; do sleep 2; done
28+
29+
- name: Connect SSH and Deploy Project
30+
uses: appleboy/[email protected]
31+
with:
32+
host: ${{ secrets.SSH_HOST }}
33+
username: ${{ secrets.SSH_USERNAME }}
34+
key: ${{ secrets.SSH_PRIVATE_KEY }}
35+
port: ${{ secrets.SSH_PORT }}
36+
script: |
37+
git clone --single-branch --branch ${{ github.ref_name }} ${{ steps.get_link.outputs.repo_link }}
38+
39+
- name: Kill VPN connection
40+
if: always()
41+
run: |
42+
sudo killall openvpn

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# GitHub Actions
2+
## [env-system-alternative](.github/workflows/env-system-alternative.yaml)
3+
If you have an organization on the free plan and you are using a private repository, you cannot use GitHub Environment. You need to use a dynamic Environment instead. It includes a solution for this. If you want to use GitHub Environment, you need to upgrade to the paid version.
4+
5+
|Prod Secrets|Value|
6+
|-|-|
7+
|**PROD**_OPENVPN_CONFIG|.ovpn client file content.|
8+
|**PROD**_SSH_HOST|Instance private ip information because you are using OpenVPN.|
9+
|**PROD**_SSH_USERNAME|Will connect to Instance and restricted username.|
10+
|**PROD**_SSH_PRIVATE_KEY|Private key to be used when connecting to the instance.|
11+
|**PROD**_SSH_PORT|The port information to make the SSH connection. It is usually used as 22. It would be good if you change this port for security.|
12+
13+
|Dev Secrets|Value|
14+
|-|-|
15+
|**DEV**_OPENVPN_CONFIG|.ovpn client file content.|
16+
|**DEV**_SSH_HOST|Instance private ip information because you are using OpenVPN.|
17+
|**DEV**_SSH_USERNAME|Will connect to Instance and restricted username.|
18+
|**DEV**_SSH_PRIVATE_KEY|Private key to be used when connecting to the instance.|
19+
|**DEV**_SSH_PORT|The port information to make the SSH connection. It is usually used as 22. It would be good if you change this port for security.|
20+
21+
|Test Secrets|Value|
22+
|-|-|
23+
|**TEST**_OPENVPN_CONFIG|.ovpn client file content.|
24+
|**TEST**_SSH_HOST|Instance private ip information because you are using OpenVPN.|
25+
|**TEST**_SSH_USERNAME|Will connect to Instance and restricted username.|
26+
|**TEST**_SSH_PRIVATE_KEY|Private key to be used when connecting to the instance.|
27+
|**TEST**_SSH_PORT|The port information to make the SSH connection. It is usually used as 22. It would be good if you change this port for security.|
28+
29+
## [openvpn-with-ssh](.github/workflows/openvpn-with-ssh.yaml)
30+
In many OpenVPN solutions, the .ovpn client file must be included in the repository. This is not a very logical approach. You can use OpenVPN for this by defining the client file as secret.
31+
32+
|Secrets|Value|
33+
|-|-|
34+
|OPENVPN_CONFIG|.ovpn client file content.|
35+
|SSH_HOST|Instance private ip information because you are using OpenVPN.|
36+
|SSH_USERNAME|Will connect to Instance and restricted username.|
37+
|SSH_PRIVATE_KEY|Private key to be used when connecting to the instance.|
38+
|SSH_PORT|The port information to make the SSH connection. It is usually used as 22. It would be good if you change this port for security.|

0 commit comments

Comments
 (0)