From 135428323076100638c25dba0c9b92b0dc71f5ad Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Tue, 17 Sep 2024 09:33:05 +0100 Subject: [PATCH 1/7] Create test.yml GitHub workflow --- .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..498925c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ + +name: Run tests + +on: + workflow_dispatch: + pull_request: + push: + +jobs: + build-and-test: + runs-on: ubuntu-latest + + permissions: + contents: read + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Test people.json is valid JSON + run: | + python3 -c 'import json; json.load(open("people.json"))' + + - name: Test image builds + run: | + docker compose -f compose.yml build + + - name: Test container can start and is healthy + run: | + # Launch the project from docker-compose.yml and wait up to + # 30s for its built-in health check to return "healthy" + docker compose -f compose.yml up --wait --wait-timeout 30 + docker compose -f compose.yml down + + # - name: Run Pytest tests + # run: | + # docker compose -f compose.yml run --entrypoint "" web pytest From 4d2ad568de26ba792e44cc221da410ce248e802d Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Tue, 17 Sep 2024 09:34:48 +0100 Subject: [PATCH 2/7] Add Docker Compose file --- compose.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 compose.yml diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..b0a4283 --- /dev/null +++ b/compose.yml @@ -0,0 +1,5 @@ +services: + web: + build: . + ports: + - "5000:5000" From c62a4cca482517cac833693e4f48616cdce8d752 Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Tue, 17 Sep 2024 09:35:32 +0100 Subject: [PATCH 3/7] Dockerfile: Add health check --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index bf69e9a..71a932d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,3 +21,8 @@ ENV LAST_UPDATE=$last_update ENTRYPOINT [ "python3" ] CMD [ "application.py" ] + +# TODO: in docker 25 and later, we should use --start-interval and +# --start-period to perform more frequent checks on startup to speed +# up tests +HEALTHCHECK --interval=10s CMD curl --fail http://localhost:5000 || exit 1 From 2910ac4cdb26892e517326a3642ec34f64222f7f Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Tue, 17 Sep 2024 09:42:09 +0100 Subject: [PATCH 4/7] test.yml: Add log output --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 498925c..bf551d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,7 @@ jobs: # Launch the project from docker-compose.yml and wait up to # 30s for its built-in health check to return "healthy" docker compose -f compose.yml up --wait --wait-timeout 30 + docker compose logs docker compose -f compose.yml down # - name: Run Pytest tests From 080832f257abf586e370e4c8b1bf07caf83ad47a Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Tue, 17 Sep 2024 09:46:13 +0100 Subject: [PATCH 5/7] test.yml: Show logs even when error --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bf551d8..87a6dcd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,8 +28,10 @@ jobs: run: | # Launch the project from docker-compose.yml and wait up to # 30s for its built-in health check to return "healthy" - docker compose -f compose.yml up --wait --wait-timeout 30 - docker compose logs + if ! docker compose -f compose.yml up --wait --wait-timeout 30; then + docker compose logs + exit 1 + fi docker compose -f compose.yml down # - name: Run Pytest tests From cbba931eeef29604999e1a80929a4b95555006ab Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Tue, 17 Sep 2024 09:53:37 +0100 Subject: [PATCH 6/7] test.yml: Add health check inspect command --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87a6dcd..1e9c322 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,7 @@ jobs: # 30s for its built-in health check to return "healthy" if ! docker compose -f compose.yml up --wait --wait-timeout 30; then docker compose logs + docker inspect --format='{{json .State.Health}}' rse-skills-graph-web-1 | jq exit 1 fi docker compose -f compose.yml down From e9628bd516e72d56f6579c409805647975da79f2 Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Tue, 17 Sep 2024 09:55:50 +0100 Subject: [PATCH 7/7] Dockerfile: Add curl --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 71a932d..02a9ade 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM ubuntu:18.04 MAINTAINER "Ian Hinder " RUN apt-get update -y && \ - apt-get install -y python3 python3-pip python3-requests graphviz libgraphviz-dev && \ + apt-get install -y python3 python3-pip python3-requests graphviz libgraphviz-dev curl && \ rm -rf /var/lib/apt/lists/* COPY ./requirements.txt /app/requirements.txt