-
Notifications
You must be signed in to change notification settings - Fork 32
137 lines (123 loc) · 4.34 KB
/
zerotouch.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
name: ZeroTouch
"on":
pull_request:
types: [opened, reopened]
push:
branches:
- "*"
paths-ignore:
- '**.md'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# aws:
# runs-on: ubuntu-latest
# mythic-beasts:
# runs-on: ubuntu-latest
digitalocean:
runs-on: ubuntu-latest
strategy:
matrix:
architecture: ['x64']
region: ['nyc1']
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up SSH key
run: |
echo "${{ secrets.DO_SSH_KEY }}" > private_key
chmod 600 private_key
echo "${{ secrets.DO_SSH_KEY_PUB }}" > public_key
chmod 600 public_key
- name: Set up doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DO_API_TOKEN }}
- name: Extract branch name
run: |
branch_name=$(git symbolic-ref --short HEAD)
echo "BRANCH_NAME=${branch_name}" >> $GITHUB_ENV
- name: Create a new droplet
id: create_droplet
run: |
DROPLET_NAME="${{ github.workflow }}-${{ github.job }}-${{ github.run_id }}"
DROPLET_JSON=$(doctl compute droplet create $DROPLET_NAME \
--image ubuntu-22-04-x64 \
--size s-1vcpu-1gb \
--region ${{ matrix.region }} \
--ssh-keys ${{ secrets.DO_SSH_FINGERPRINT }} \
--format ID,PublicIPv4 \
--no-header \
--wait \
--output json)
echo "$DROPLET_JSON"
echo "DROPLET_ID=$(echo "$DROPLET_JSON" | jq '.[].id')" >> $GITHUB_ENV
echo "DROPLET_IP=$(echo "$DROPLET_JSON" | jq -r '.[].networks.v4[0].ip_address')" >> $GITHUB_ENV
- name: Wait for SSH
run: |
COUNT=0
RETRIES=40
while [ $COUNT -lt $RETRIES ]
do
echo "Attempting to connect to $DROPLET_IP as root (attempt $(($COUNT + 1))/$RETRIES)..."
ssh -i private_key -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -o "ConnectTimeout=5" "root@$DROPLET_IP" 'echo SSH_READY' && break
COUNT=$(($COUNT + 1))
sleep 15
done
if [ $COUNT -lt $RETRIES ]; then
echo "SSH is ready on $DROPLET_IP"
exit 0
else
echo "Failed to establish an SSH connection to $DROPLET_IP after $RETRIES attempts"
exit 1
fi
- name: Checkout the git repository (Main Branch)
if: github.ref == 'refs/heads/main'
run: |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i private_key \
root@$DROPLET_IP "bash -s" <<- 'ENDSSH'
git clone https://github.com/FreeTAKTeam/FreeTAKHub-Installation.git
ENDSSH
- name: Checkout the git repository (Development Branches)
if: github.ref != 'refs/heads/main'
run: |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i private_key \
root@$DROPLET_IP "bash -s" <<- 'ENDSSH'
git clone https://github.com/FreeTAKTeam/FreeTAKHub-Installation.git
cd ~/FreeTAKHub-Installation
git checkout ${{ env.BRANCH_NAME }}
ENDSSH
- name: Install the software
run: |
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=12 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i private_key \
root@$DROPLET_IP "bash -s" <<- 'ENDSSH'
# Adding sleep timer due to background apt-get updates
sleep 540
# Execute Zerotouch Installer
~/FreeTAKHub-Installation/scripts/easy_install.sh --branch ${{ env.BRANCH_NAME }}
ENDSSH
- name: Test TAK Port 8087
run: |
until nc -zv $DROPLET_IP 8087; do
sleep 5
done
- name: Test TAK Port 8089
run: |
until nc -zv $DROPLET_IP 8089; do
sleep 5
done
- name: Test REST API Port 19023
run: |
until nc -zv $DROPLET_IP 19023; do
sleep 5
done
- name: Test Web UI Port 5000
run: |
until nc -zv $DROPLET_IP 5000; do
sleep 5
done
- name: Destroy droplet
if: always()
run: doctl compute droplet delete -f $DROPLET_ID