Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API health checks to CI #70

Merged
merged 9 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading