Skip to content

Commit

Permalink
Annual health check?! Nah, I get mine every 5s πŸ‘©β€βš•οΈ
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua-Douglas committed Dec 19, 2023
1 parent f273ff7 commit a32f18c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CI-CD-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run Tests With 3rd Party Service Mocking
run: docker run ghcr.io/hackforla/homeuniteus/api:latest pytest
run: docker run --no-healthcheck ghcr.io/hackforla/homeuniteus/api:latest pytest
test-api-nomock:
runs-on: ubuntu-latest
needs: [build-api]
Expand All @@ -89,7 +89,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run Tests Without Mocking
run: docker run --env COGNITO_REGION --env COGNITO_ACCESS_ID --env COGNITO_ACCESS_KEY ghcr.io/hackforla/homeuniteus/api:latest "pytest --mode=release"
run: docker run --no-healthcheck --env COGNITO_REGION --env COGNITO_ACCESS_ID --env COGNITO_ACCESS_KEY ghcr.io/hackforla/homeuniteus/api:latest "pytest --mode=release"
test-app-mock:
runs-on: ubuntu-latest
needs: [build-app, build-api]
Expand All @@ -110,7 +110,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run Tests With Backend Mocking
run: docker run --env CYPRESS_BASE_URL --env CYPRESS_USE_MOCK app:latest-test "npx cypress run"
run: docker run --env CYPRESS_BASE_URL --env CYPRESS_USE_MOCK ghcr.io/hackforla/homeuniteus/app:latest-test "npx cypress run"
env:
CYPRESS_BASE_URL: http://frontend:4040
CYPRESS_USE_MOCK: true
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
run: |
curl http://backend:8080/api/auth/signup/host -H "accept: application/json" -H "Content-Type: application/json" -d "{\"email\": \"[email protected]\", \"password\": \"alskdf454#Adfa\"}"
- name: Test without mocking
run: docker run --env CYPRESS_BASE_URL --env CYPRESS_USE_MOCK --env CYPRESS_REAL_EMAIL --env CYPRESS_REAL_PASSWORD app:latest-test "npx cypress run"
run: docker run --env CYPRESS_BASE_URL --env CYPRESS_USE_MOCK --env CYPRESS_REAL_EMAIL --env CYPRESS_REAL_PASSWORD ghcr.io/hackforla/homeuniteus/app:latest-test "npx cypress run"
env:
CYPRESS_BASE_URL: http://frontend:4040
CYPRESS_USE_MOCK: false
Expand Down
6 changes: 6 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ RUN python -m pip install --no-cache-dir -r requirements-dev.txt

EXPOSE 8080
ENTRYPOINT ["/bin/sh", "-c"]
# We can decrease the number of health checks when
# v25.0 docker engine is release. This engine will
# provide a --start-interval option that allows a custom
# startup health check interval
HEALTHCHECK --interval=5s --timeout=5s --retries=3 \
CMD curl --fail http://${HOST:-localhost}:${PORT:-8080}/api/health || exit 1
CMD ["python -m openapi_server"]
9 changes: 8 additions & 1 deletion api/openapi_server/controllers/admin_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ def initial_sign_in_reset_password():
return {
'token': access_token,
'user': user
}
}

def health():
'''
The health check endpoint always returns a successful status code.
This is useful for determining whether the API startup was successful.
'''
return 'API is healthy 😎', 200
8 changes: 8 additions & 0 deletions api/openapi_server/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ paths:
$ref: "./paths/auth/authInitialInvite.yaml"
/auth/invite:
$ref: "./paths/auth/authInvite.yaml"
/health:
get:
operationId: openapi_server.controllers.admin_controller.health
summary: Health Check
description: Returns the health status of the API.
responses:
'200':
description: API is healthy.
components:
securitySchemes:
jwt:
Expand Down
9 changes: 9 additions & 0 deletions api/tests/test_health_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

def test_get_nonexistent_provider(client):
'''
Test that the healthcheck endpoint works.
The endpoint should always return a success code.
'''
response = client.get(f"/api/health")
assert response.status_code == 200, f'Response body is : {response.json}'
assert len(response.json) > 0

0 comments on commit a32f18c

Please sign in to comment.