-
Notifications
You must be signed in to change notification settings - Fork 0
241 lines (201 loc) · 7.23 KB
/
tests.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
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
241
---
name: Tests
on: # yamllint disable-line rule:truthy
pull_request:
workflow_call:
concurrency:
group: '${{ github.workflow }} @ ${{ github.ref }}'
cancel-in-progress: true
jobs:
check_versions:
name: Tests - Version checking
runs-on: ubuntu-latest
outputs:
version: ${{ steps.sogo.outputs.VERSION }}
steps:
- name: Get latest version of SOGo
id: sogo
run: |
echo "VERSION=$(curl -s https://api.github.com/repos/Alinto/sogo/releases/latest | jq -r '.tag_name' | sed 's/SOGo-//')" >> "$GITHUB_OUTPUT"
test_build:
name: Tests - Build image for testing
needs: check_versions
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and export to Docker
uses: docker/build-push-action@v5
with:
file: ./Dockerfile
load: true
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: test-sogo:${{ github.run_id }}
outputs: type=docker,dest=/tmp/test-sogo-${{ github.run_id }}.tar
build-args: |
SOGO_VERSION=${{ needs.check_versions.outputs.version }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: test-sogo-${{ github.run_id }}
path: /tmp/test-sogo-${{ github.run_id }}.tar
end_to_end_plist:
name: Tests - E2E Testing
needs: test_build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: test-sogo-${{ github.run_id }}
path: /tmp
- name: Load Docker image
env:
RUN_ID: ${{ github.run_id }}
run: |
docker load --input /tmp/test-sogo-$RUN_ID.tar
- name: Setup test configurations
run: |
mkdir -p /tmp/test-sogo
plist_config=$(cat sample-config.conf)
echo "$plist_config" > /tmp/test-sogo/sogo.conf
- name: Setup test PostgreSQL
run: |
docker network create test-sogo
docker run -d \
--name test-postgres \
--network test-sogo \
-e POSTGRES_PASSWORD=sogo \
-e POSTGRES_USER=sogo \
-e POSTGRES_DB=sogo \
postgres
- name: Run test SOGo container
run: |
docker run -d \
--name sogo \
--network test-sogo \
-p 80:80/tcp \
-v /tmp/test-sogo/sogo.conf:/etc/sogo/sogo.conf \
--stop-timeout 30 \
test-sogo:${{ github.run_id }}
- name: Wait for test SOGo container to start
run: |
TIMEOUT_SECONDS=180
START_TIME=$(date +%s)
while ! docker logs sogo 2>&1 | grep -q 'INFO success: sogo entered RUNNING state, process has stayed up for > than 1 seconds'; do
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ $ELAPSED_TIME -gt $TIMEOUT_SECONDS ]; then
echo "Timeout reached. Server failed to start within $TIMEOUT_SECONDS seconds."
printf "\e[0;32m%s\e[0m\n" "*****Test container logs*****"
docker logs sogo
exit 1
fi
echo "Waiting for test SOGo container to start..."
sleep 5
done
- name: Test HTTP status code
run: |
TIMEOUT=60
elapsed_time=0
SUCCESS_CODE=302
while true; do
http_status=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:80/SOGo")
if [ $http_status -eq $SUCCESS_CODE ]; then
echo "Health check successful. HTTP Status Code: $http_status"
exit 0
fi
elapsed_time=$((elapsed_time + 1))
if [ $elapsed_time -ge $TIMEOUT ]; then
echo "Timeout reached. HTTP Health check failed."
exit 1
fi
# Wait for a second before next health check
sleep 1
done
end_to_end_yaml:
name: Tests - E2E Testing (YAML Config)
needs: test_build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: test-sogo-${{ github.run_id }}
path: /tmp
- name: Load Docker image
env:
RUN_ID: ${{ github.run_id }}
run: |
docker load --input /tmp/test-sogo-$RUN_ID.tar
- name: Setup test configurations
run: |
mkdir -p /tmp/test-sogo
yaml_config=$(cat sample-config.yaml)
echo "$yaml_config" > /tmp/test-sogo/sogo.yaml
- name: Setup test PostgreSQL
run: |
docker network create test-sogo
docker run -d \
--name test-postgres \
--network test-sogo \
-e POSTGRES_PASSWORD=sogo \
-e POSTGRES_USER=sogo \
-e POSTGRES_DB=sogo \
postgres
- name: Run test SOGo container
run: |
docker run -d \
--name sogo \
--network test-sogo \
-p 80:80/tcp \
-v /tmp/test-sogo/sogo.yaml:/etc/sogo/sogo.conf.d/00-test.yaml \
--stop-timeout 30 \
test-sogo:${{ github.run_id }}
- name: Wait for test SOGo container to start
run: |
TIMEOUT_SECONDS=180
START_TIME=$(date +%s)
while ! docker logs sogo 2>&1 | grep -q 'INFO success: sogo entered RUNNING state, process has stayed up for > than 1 seconds'; do
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ $ELAPSED_TIME -gt $TIMEOUT_SECONDS ]; then
echo "Timeout reached. Server failed to start within $TIMEOUT_SECONDS seconds."
printf "\e[0;32m%s\e[0m\n" "*****Test container logs*****"
docker logs sogo
exit 1
fi
echo "Waiting for test SOGo container to start..."
sleep 5
done
- name: Test HTTP status code
run: |
TIMEOUT=60
elapsed_time=0
SUCCESS_CODE=302
while true; do
http_status=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:80/SOGo")
if [ $http_status -eq $SUCCESS_CODE ]; then
echo "Health check successful. HTTP Status Code: $http_status"
exit 0
fi
elapsed_time=$((elapsed_time + 1))
if [ $elapsed_time -ge $TIMEOUT ]; then
echo "Timeout reached. HTTP Health check failed."
exit 1
fi
# Wait for a second before next health check
sleep 1
done