Skip to content

Commit 1e21e65

Browse files
committed
ci(main): add a test for docker run of the built container
1 parent 4a40634 commit 1e21e65

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

.github/workflows/conda.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ jobs:
2020
init-shell: bash powershell
2121
micromamba-version: 1.5.6-0
2222
post-cleanup: all
23-
- run: |-
24-
echo "Testing package import"
25-
python -c 'import fractopo'
26-
echo "Testing module entrypoint"
27-
python -m fractopo --help
28-
echo "Running unittests with pytest"
29-
pytest -v
23+
- name: Test package import
24+
run: python -c 'import fractopo'
25+
- name: Test module entrypoint
26+
run: python -m fractopo --help
27+
- name: Run unittests with pytest
28+
run: pytest -v
3029
strategy:
3130
fail-fast: false
3231
matrix:

.github/workflows/main.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ jobs:
2020
name: nialov
2121
- name: Load image to docker
2222
run: nix run .#load-fractopo-image
23+
- name: Test run of loaded fractopo-app container
24+
run: docker run -d --name fractopo-test -p 2718:2718 fractopo-app:vsrjfhp7gd4pgxxzhdrmnr4xglwyln35
25+
- name: Wait for API to be ready
26+
run: |-
27+
for i in {1..60}; do
28+
if curl -s http://localhost:2718/; then
29+
echo "API is up!"
30+
exit 0
31+
fi
32+
sleep 1
33+
done
34+
echo "API did not start in time" >&2
35+
exit 1
36+
- name: Test API root endpoint
37+
run: curl -f http://localhost:2718/
2338
- env:
2439
PUSHER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2540
if: github.event_name == 'push'

nix/ci.nix

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ in
157157
};
158158
};
159159

160+
dockerPort = builtins.toString 2718;
161+
160162
in
161163
baseNixSteps
162164
++ [
@@ -165,6 +167,32 @@ in
165167
run = "nix run .#load-fractopo-image";
166168

167169
}
170+
{
171+
name = "Test run of loaded fractopo-app container";
172+
run =
173+
let
174+
inherit (inputs.self.legacyPackages.x86_64-linux.fractopo-app-image-stream) imageName imageTag;
175+
in
176+
"docker run -d --name fractopo-test -p ${dockerPort}:${dockerPort} ${imageName}:${imageTag}";
177+
}
178+
{
179+
name = "Wait for API to be ready";
180+
run = ''
181+
for i in {1..60}; do
182+
if curl -s http://localhost:${dockerPort}/; then
183+
echo "API is up!"
184+
exit 0
185+
fi
186+
sleep 1
187+
done
188+
echo "API did not start in time" >&2
189+
exit 1
190+
'';
191+
}
192+
{
193+
name = "Test API root endpoint";
194+
run = "curl -f http://localhost:${dockerPort}/";
195+
}
168196
(mkPushStep {
169197
rev = "$(git rev-parse --short HEAD)";
170198
name = "Push to ghcr.io from all branches";
@@ -200,6 +228,7 @@ in
200228
strategy = {
201229
fail-fast = false;
202230
matrix = {
231+
# Test same Python versions as for poetry job
203232
inherit (config.workflows.".github/workflows/main.yaml".jobs.poetry.strategy.matrix)
204233
python-version
205234
;
@@ -228,12 +257,20 @@ in
228257
};
229258
}
230259
{
260+
name = "Test package import";
231261
run = ''
232-
echo "Testing package import"
233262
python -c 'import fractopo'
234-
echo "Testing module entrypoint"
263+
'';
264+
}
265+
{
266+
name = "Test module entrypoint";
267+
run = ''
235268
python -m fractopo --help
236-
echo "Running unittests with pytest"
269+
'';
270+
}
271+
{
272+
name = "Run unittests with pytest";
273+
run = ''
237274
pytest -v
238275
'';
239276
}

0 commit comments

Comments
 (0)