diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 3fa27586..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 @@ -19,17 +22,39 @@ jobs: run: docker load --input /tmp/test-image.tar - name: Run project checks - uses: addnab/docker-run-action@v3 - with: - image: test-image - run: keystone-api check + run: docker run test-image check - name: Run migration checks - uses: addnab/docker-run-action@v3 + 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 + + steps: + - name: Fetch image artifact + uses: actions/download-artifact@v3 with: - image: test-image - run: keystone-api makemigrations --check + name: test-image + path: /tmp + + - name: Load image + run: docker load --input /tmp/test-image.tar + + - name: Run API health checks + run: | + docker run --detach -p 8000:8000 test-image + 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 + if [ "$http_status" -ne 200 ]; then + exit 1 + fi + # Run any/all application tests using the Django `test` utility app-tests: name: Application Tests runs-on: ubuntu-latest @@ -49,7 +74,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: 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"] 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.