Skip to content

Commit

Permalink
Adds API health checks to CI (#70)
Browse files Browse the repository at this point in the history
* Drop keystone-api command

* Call docker directly

* Adds api health checks

* Adds detach flag

* Removes permissions from health endpoint

* Updates api test lgic

* Adds sleep statement

* Long sleep

* Adds cmments to test workflow
  • Loading branch information
djperrefort committed Dec 4, 2023
1 parent 23b0ad0 commit 76a8e67
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
41 changes: 33 additions & 8 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions keystone_api/apps/health/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 76a8e67

Please sign in to comment.