Skip to content

Commit ac34fac

Browse files
authored
Copy asgi.py, ensure container runs as a CI check, (#179)
This PR ensures that we copy the new asgi.py file (introduced in #161) into the container, which fixes #178. It also adds a step in the build / publish workflow to spin up the container and check that it starts successfully.
1 parent 8330775 commit ac34fac

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

.dockerignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# ignore everything
22
*
33
# use exceptions to create an "allow list"
4-
!/config
5-
!/src
4+
!/asgi.py
65
!/bin
6+
!/config
77
!/poetry.lock
88
!/pyproject.toml
9-
!/version.json
9+
!/src
10+
!/version.json

.github/workflows/build-publish.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
jobs:
1414
build-and-publish:
1515
runs-on: ubuntu-latest
16+
env:
17+
TEST_TAG: ${{ github.repository }}:test
18+
TEST_CONTAINER_NAME: jbi-healthcheck
1619
steps:
1720
- name: Check out the repo
1821
uses: actions/checkout@v3
@@ -43,6 +46,31 @@ jobs:
4346
username: ${{ secrets.DOCKERHUB_USERNAME }}
4447
password: ${{ secrets.DOCKERHUB_TOKEN }}
4548

49+
- name: Build and export to Docker
50+
uses: docker/build-push-action@v3
51+
with:
52+
context: .
53+
load: true
54+
push: false
55+
tags: ${{ env.TEST_TAG }}
56+
57+
- name: Spin up container
58+
run: |
59+
docker run \
60+
--name ${{ env.TEST_CONTAINER_NAME }} \
61+
--detach \
62+
--env-file .env.example \
63+
--publish 8000:8000 \
64+
${{ env.TEST_TAG }}
65+
66+
- name: Check that container is running
67+
run: |
68+
docker exec ${{ env.TEST_CONTAINER_NAME }} python bin/healthcheck.py
69+
70+
- name: Spin down container
71+
run: |
72+
docker rm -f ${{ env.TEST_CONTAINER_NAME }}
73+
4674
- name: Build and push
4775
uses: docker/build-push-action@v3
4876
with:

bin/healthcheck.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
5+
import requests
6+
from requests.adapters import HTTPAdapter, Retry
7+
8+
PORT = os.environ["PORT"]
9+
10+
session = requests.Session()
11+
12+
retries = Retry(total=5, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
13+
session.mount("http://", HTTPAdapter(max_retries=retries))
14+
if __name__ == "__main__":
15+
response = session.get(f"http://0.0.0.0:{PORT}/")
16+
response.raise_for_status()

0 commit comments

Comments
 (0)