-
Notifications
You must be signed in to change notification settings - Fork 7
240 lines (232 loc) · 7.64 KB
/
ci.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
on:
push:
pull_request:
types: [opened, reopened, synchronize]
workflow_dispatch:
name: CI
jobs:
build:
name: Build server image
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: nivlheim
POSTGRES_DB: nivlheim
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd "pg_isready"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Go tests
run: |
cd server/service
go test -v
env:
NIVLHEIM_PGHOST: localhost
NIVLHEIM_PGUSER: nivlheim
NIVLHEIM_PGPASSWORD: postgres
NIVLHEIM_PGDATABASE: nivlheim
NIVLHEIM_PGSSLMODE: disable
- name: Docker build
run: |
VERSION=`cat VERSION`
if [[ "$GITHUB_REF_NAME" != "master" ]]; then
VERSION="$VERSION-$GITHUB_REF_NAME"
fi
echo "version=$VERSION"
docker build --file ci/docker/api_Dockerfile --tag nivlheim:latest --build-arg version=$VERSION .
- name: Docker save
run: docker save nivlheim | gzip > nivlheim-image.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nivlheim-image.tar.gz
path: nivlheim-image.tar.gz
buildwww:
name: Build httpd+cgi image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker build
run: docker build --file ci/docker/Dockerfile --tag nivlheim-www:latest .
- name: Docker save
run: |
IMAGE=`docker images | head -2 | tail -1 | awk '{print $3}'`
docker inspect $IMAGE
docker save nivlheim-www | gzip > nivlheim-www.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nivlheim-www.tar.gz
path: nivlheim-www.tar.gz
buildclient:
name: Build client image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker build
run: |
cp client/client.yaml tmp_client.yaml
echo " server: localhost" >> tmp_client.yaml
docker build --file ci/docker/client_Dockerfile --tag nivlheimclient:latest .
docker save nivlheimclient | gzip > nivlheim-client.tar.gz
rm tmp_client.yaml
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nivlheim-client.tar.gz
path: nivlheim-client.tar.gz
test-scripts:
name: Run test scripts
needs: [build, buildwww, buildclient]
runs-on: ubuntu-latest
strategy:
matrix:
test:
- cert_handling.sh
- cfengine.sh
- change_ca.sh
- client_timing.sh
- clones.sh
- powershell.sh
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
# the name input parameter is not provided, so all artifacts will be downloaded
- name: Load images
run: |
docker load --input nivlheim-www.tar.gz/nivlheim-www.tar.gz
docker load --input nivlheim-image.tar.gz/nivlheim-image.tar.gz
docker load --input nivlheim-client.tar.gz/nivlheim-client.tar.gz
- name: Start containers
run: docker compose -f "ci/docker/docker-compose.yml" up -d
- name: SSL handshake
run: openssl s_client -connect localhost:443 -prexit
continue-on-error: true
- name: Status API
run: curl -k --no-progress-meter https://localhost/api/v2/status
- name: Run one of the test scripts
run: tests/test_${{ matrix.test }}
- name: Retrieve logs from Docker
if: always()
run: docker compose -f "ci/docker/docker-compose.yml" logs
- name: Retrieve server logs
if: always()
run: |
echo "------- access_log -------------------------------"
docker exec docker-nivlheimweb-1 grep -v 127.0.0.1 /var/log/httpd/access_log || true
echo "------- error_log --------------------------------"
docker exec docker-nivlheimweb-1 cat /var/log/httpd/error_log || true
echo "------- system.log--------------------------------"
docker exec docker-nivlheimweb-1 cat /var/log/nivlheim/system.log || true
- name: Stop containers
if: always()
run: docker compose -f "ci/docker/docker-compose.yml" down
publish:
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') }}
name: Publish server image
needs: [test-scripts]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: nivlheim-image.tar.gz
- name: Load image
run: docker load < nivlheim-image.tar.gz
- name: Log in to registry
run: >
echo "${{ secrets.GITHUB_TOKEN }}"
| docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/nivlheim
if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
TAG_NAME=latest
else
TAG_NAME="${GITHUB_REF#refs/tags/}"
fi
docker tag nivlheim:latest "$IMAGE_ID:$TAG_NAME"
docker push "$IMAGE_ID:$TAG_NAME"
publishwww:
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') }}
name: Publish httpd+cgi image
needs: [test-scripts]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: nivlheim-www.tar.gz
- name: Load image
run: docker load < nivlheim-www.tar.gz
- name: Log in to registry
run: >
echo "${{ secrets.GITHUB_TOKEN }}"
| docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/nivlheim_www
if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
TAG_NAME=latest
else
TAG_NAME="${GITHUB_REF#refs/tags/}"
fi
docker tag nivlheim-www:latest "$IMAGE_ID:$TAG_NAME"
docker push "$IMAGE_ID:$TAG_NAME"
# cd_hook:
# name: Webhook to local builders
# needs: [test-scripts]
# runs-on: ubuntu-20.04
# continue-on-error: true
# steps:
# - name: HTTP request
# run: curl -sS "http://nivlheim-test.uio.no/hook.pl?commit=${GITHUB_SHA}&branch=${GITHUB_REF_NAME}"
release:
if: ${{ github.ref == 'refs/heads/master' }}
name: Tag and release
needs: [test-scripts]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 50
- name: Create a version tag
id: tagstep
uses: salsify/action-detect-and-tag-new-version@v2
with:
version-command: cat VERSION
- name: Generate changelog
if: steps.tagstep.outputs.tag != ''
id: changelog
uses: jaywcjlove/changelog-generator@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'
- name: Create a new release
if: steps.tagstep.outputs.tag != ''
uses: softprops/action-gh-release@v1
with:
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
tag_name: ${{ steps.tagstep.outputs.tag }}
generate_release_notes: true