From f78c88be9d845bfba9367fad7c813d221518f7ab Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 12:43:28 -0500 Subject: [PATCH 1/9] Drop keystone-api command --- .github/workflows/Test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 3fa27586..42ebae1e 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -22,13 +22,13 @@ jobs: uses: addnab/docker-run-action@v3 with: image: test-image - run: keystone-api check + run: check - name: Run migration checks uses: addnab/docker-run-action@v3 with: image: test-image - run: keystone-api makemigrations --check + run: makemigrations --check app-tests: name: Application Tests From 03bc8bd5b45d30f4aa471a6b09bc99490485f522 Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 13:15:40 -0500 Subject: [PATCH 2/9] Call docker directly --- .github/workflows/Test.yml | 10 ++-------- Dockerfile | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 42ebae1e..90ad0636 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -19,16 +19,10 @@ jobs: run: docker load --input /tmp/test-image.tar - name: Run project checks - uses: addnab/docker-run-action@v3 - with: - image: test-image - run: check + run: docker run test-image check - name: Run migration checks - uses: addnab/docker-run-action@v3 - with: - image: test-image - run: makemigrations --check + run: docker run test-image makemigrations --check app-tests: name: Application Tests diff --git a/Dockerfile b/Dockerfile index 4a3b7f81..9643214e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ COPY README.md README.md # Install the application ENV PIP_ROOT_USER_ACTION=ignore -RUN pip install -e . +RUN pip install -e . && pip cache purge # Setup and launch the application ENTRYPOINT ["keystone-api"] From 4ff0f5ae39acaa8d717dcb38c49aa298fd4112eb Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 13:17:58 -0500 Subject: [PATCH 3/9] Adds api health checks --- .github/workflows/Test.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 90ad0636..551cd6ff 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -24,6 +24,25 @@ jobs: - name: Run migration checks run: docker run test-image makemigrations --check + health-checks: + name: API Health Checks + runs-on: ubuntu-latest + + steps: + - name: Fetch image artifact + uses: actions/download-artifact@v3 + with: + name: test-image + path: /tmp + + - name: Load image + run: docker load --input /tmp/test-image.tar + + - name: Run migration checks + run: | + docker run -p 8000:8000 test-image + curl localhst:8000 + app-tests: name: Application Tests runs-on: ubuntu-latest @@ -43,7 +62,7 @@ jobs: report-test-status: name: Report Test Status runs-on: ubuntu-latest - needs: [ app-tests, system-checks ] + needs: [ app-tests, system-checks, health-checks ] if: always() steps: From ec096aec2d3015fafccf71d6380f83eb9868b91c Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 13:22:54 -0500 Subject: [PATCH 4/9] Adds detach flag --- .github/workflows/Test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 551cd6ff..3303f279 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -38,9 +38,9 @@ jobs: - name: Load image run: docker load --input /tmp/test-image.tar - - name: Run migration checks + - name: Run API health checks run: | - docker run -p 8000:8000 test-image + docker run --detach -p 8000:8000 test-image curl localhst:8000 app-tests: From 4f7ca6a89bce8817174120c0ff2a544e7c76a29c Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 13:36:50 -0500 Subject: [PATCH 5/9] Removes permissions from health endpoint --- .github/workflows/Test.yml | 2 +- keystone_api/apps/health/views.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 3303f279..69275c4e 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -41,7 +41,7 @@ jobs: - name: Run API health checks run: | docker run --detach -p 8000:8000 test-image - curl localhst:8000 + curl localhost:8000/health app-tests: name: Application Tests diff --git a/keystone_api/apps/health/views.py b/keystone_api/apps/health/views.py index 78b51007..23334a00 100644 --- a/keystone_api/apps/health/views.py +++ b/keystone_api/apps/health/views.py @@ -15,6 +15,8 @@ class HealthChecks(ViewSet, CheckMixin): """View for rendering system status messages""" + permission_classes = [] + def list(self, request: HttpRequest, *args, **kwargs) -> JsonResponse: """Return a JSON response detailing system status checks. From 8b8b501658a70a3eece0f132cc3b99d636f3199d Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 14:21:50 -0500 Subject: [PATCH 6/9] Updates api test lgic --- .github/workflows/Test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 69275c4e..839727e9 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -41,7 +41,11 @@ jobs: - name: Run API health checks run: | docker run --detach -p 8000:8000 test-image - curl localhost:8000/health + http_status=$(wget -NS localhost:8000/health/ 2>&1 | grep "HTTP/" | awk '{print $2}') + jq . index.html + if [ "$http_status" -ne 200 ]; then + exit 1 + fi app-tests: name: Application Tests From 8e6976bf989c43cf27643febf2ca3daf4610ac1a Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 14:38:07 -0500 Subject: [PATCH 7/9] Adds sleep statement --- .github/workflows/Test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 839727e9..418f724a 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -41,6 +41,8 @@ jobs: - name: Run API health checks run: | docker run --detach -p 8000:8000 test-image + sleep 5 + http_status=$(wget -NS localhost:8000/health/ 2>&1 | grep "HTTP/" | awk '{print $2}') jq . index.html if [ "$http_status" -ne 200 ]; then From 92ebf3d68f6e4f4641b53a1cf8be674e92175461 Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 14:45:17 -0500 Subject: [PATCH 8/9] Long sleep --- .github/workflows/Test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 418f724a..8ff6a32f 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -41,7 +41,7 @@ jobs: - name: Run API health checks run: | docker run --detach -p 8000:8000 test-image - sleep 5 + sleep 30 http_status=$(wget -NS localhost:8000/health/ 2>&1 | grep "HTTP/" | awk '{print $2}') jq . index.html From bdd7958672f89a92f4d251585e12b8969b4616e7 Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Mon, 4 Dec 2023 14:57:00 -0500 Subject: [PATCH 9/9] Adds cmments to test workflow --- .github/workflows/Test.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 8ff6a32f..a5b7be39 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -4,6 +4,9 @@ on: workflow_call: jobs: + + # System configuration tests including checks for obviously + # incorrect settings and missing database migrations system-checks: name: System Checks runs-on: ubuntu-latest @@ -24,6 +27,8 @@ jobs: - name: Run migration checks run: docker run test-image makemigrations --check + # Integration test requiring all API health checks to pass + # when launching the docker container with default settings. health-checks: name: API Health Checks runs-on: ubuntu-latest @@ -41,7 +46,7 @@ jobs: - name: Run API health checks run: | docker run --detach -p 8000:8000 test-image - sleep 30 + sleep 30 # Wait for API server to start http_status=$(wget -NS localhost:8000/health/ 2>&1 | grep "HTTP/" | awk '{print $2}') jq . index.html @@ -49,6 +54,7 @@ jobs: exit 1 fi + # Run any/all application tests using the Django `test` utility app-tests: name: Application Tests runs-on: ubuntu-latest