This repository was archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (165 loc) · 8.3 KB
/
test-integration.yml
File metadata and controls
189 lines (165 loc) · 8.3 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Integration Test
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
branches:
- master
- next
env:
STACKHEAD_VERSION: next
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v2
with:
go-version: 1.13
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build
run: sh ./.build/build.sh
- uses: actions/upload-artifact@v2
with:
name: stackhead-cli
path: bin/stackhead-cli
checkLabel:
needs: build
name: Please request integration test and review
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- run: if [ ${{ contains( github.event.pull_request.labels.*.name, 'action/integration-test') }} == false ]; then exit 1; else exit 0; fi
test-integration:
name: Integration Test
needs: checkLabel
runs-on: ubuntu-latest
strategy:
matrix:
os: [ 'ubuntu-18.04', 'ubuntu-20.04' ] # , 'centos-8'
fail-fast: false
if: github.event.pull_request.draft == false
env:
DOMAIN_PREFIX: pr-${{ github.event.number }}-cli-${{ matrix.os }}
DOMAIN: test.stackhead.io
steps:
- uses: actions/checkout@v2
- name: Remove Python 2 and old Ansible 2.9 version
run: sudo apt purge python ansible -y
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Ansible v2.10.3 (GH actions currently uses 2.9)
run: pip install ansible==2.10.3
- name: Print Ansible and Python version
run: ansible --version && python --version
- uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}"
- name: Download StackHead CLI artifact
uses: actions/download-artifact@v2
with:
name: stackhead-cli
path: /home/runner/bin
- name: Set execution permission on binary
run: chmod +x /home/runner/bin/stackhead-cli
working-directory: /home/runner/bin
- name: Setup Hetzner server
id: setup_server
uses: saitho/hetzner-cloud-action@v1.1.0
with:
action: create
server_name: "${{ env.DOMAIN_PREFIX }}"
server_image: "${{ matrix.os }}"
server_location: fsn1
server_ssh_key_name: gh-actions
wait_for_ssh: 1
env:
API_TOKEN: ${{ secrets.HETZNER_TOKEN }}
- name: Add DNS record
uses: saitho/create-dns-record@patch-1
with:
type: "A"
name: "${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
content: "${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}"
ttl: 1
proxied: 0
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
- name: Add DNS record for subdomain
uses: saitho/create-dns-record@patch-1
with:
type: "A"
name: "sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
content: "${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}"
ttl: 1
proxied: 0
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
- name: Perform integration test
uses: getstackhead/stackhead/actions/integration-test@next
with:
ipaddress: ${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}
domain: '${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}'
domain2: 'sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}'
webserver: nginx # when using cli "getstackhead.stackhead_webserver_" prefix is added automatically
cli: 1
cli_bin_path: /home/runner/bin/stackhead-cli
- name: PR comment if integration stage was left intact
uses: mshick/add-pr-comment@v1
if: always() && contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
with:
message: |
Because the `action/keep-integration-stage` label was set, the integration stage is left intact.
You may now continue debugging on it, if you had been granted SSH access.
IP-Address: ${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}
OS: ${{ matrix.os }}
## Quick command reference
### Build
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/build.sh
```
### Setup server
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/setup.sh
```
### Deploy application
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/deploy.sh
```
### Validate application
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/validate.sh
```
### Destroy application
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/destroy.sh
```
## Done debugging?
Destroy the stage by deleting the server in the Hetzner control panel and the DNS setting in the Cloudflare control panel.
repo-token: ${{ secrets.GH_TOKEN }}
allow-repeats: false
- name: Remove DNS record
uses: saitho/delete-dns-record@saitho-patch-1
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
with:
name: "${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
- name: Remove DNS record for subdomain
uses: saitho/delete-dns-record@saitho-patch-1
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
with:
name: "sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
- name: Remove Hetzner server
uses: saitho/hetzner-cloud-action@v1.1.0
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
with:
action: remove
server_id: "${{ steps.setup_server.outputs.hcloud_server_id }}"
env:
API_TOKEN: ${{ secrets.HETZNER_TOKEN }}