From 0366011c6ea43f879ec61fae8630bbdc1a0a0bb9 Mon Sep 17 00:00:00 2001 From: Ahmed Nassar Date: Thu, 19 Dec 2024 00:43:34 +0200 Subject: [PATCH] feat: Re-enable health check endpoint and add Render CLI installation steps in GitHub Actions workflow --- .github/workflows/django.yml | 38 ++++++++++++++++++------------------ egypt_metro/urls.py | 4 ++-- egypt_metro/views.py | 32 +++++++++++++++--------------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 382f3ef..123e659 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -38,22 +38,22 @@ jobs: run: | poetry export --without-hashes -o requirements.txt - # - name: Install Render CLI - # run: | - # npm install -g render-cli - # echo 'export PATH="$PATH:$(npm bin -g)"' >> $GITHUB_ENV - # echo "Render CLI installation complete." - - # - name: Verify Render CLI Installation - # run: | - # echo "Verifying Render CLI" - # render --version # Check if render command works - - # - name: Deploy to Render - # env: - # SECRET_KEY: ${{ secrets.SECRET_KEY }} - # DATABASE_URL: ${{ secrets.DATABASE_URL }} - # run: | - # echo "Starting deployment to Render..." - # render deploy --config render.yaml --service-name egypt-metro - # echo "Deployment complete!" + - name: Install Render CLI + run: | + npm install -g render-cli + echo 'export PATH="$PATH:$(npm bin -g)"' >> $GITHUB_ENV + echo "Render CLI installation complete." + + - name: Verify Render CLI Installation + run: | + echo "Verifying Render CLI" + render --version # Check if render command works + + - name: Deploy to Render + env: + SECRET_KEY: ${{ secrets.SECRET_KEY }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + run: | + echo "Starting deployment to Render..." + render deploy --config render.yaml --service-name egypt-metro + echo "Deployment complete!" diff --git a/egypt_metro/urls.py b/egypt_metro/urls.py index 81c4d8d..99dcdb4 100644 --- a/egypt_metro/urls.py +++ b/egypt_metro/urls.py @@ -16,7 +16,7 @@ """ from django.contrib import admin from django.urls import path, include -# from .views import health_check +from .views import health_check # from django.conf import settings # from django.conf.urls.static import static from drf_yasg.views import get_schema_view @@ -47,7 +47,7 @@ path("api/stations/", include("apps.stations.urls")), # Stations and trips # Miscellaneous - # path("health/", health_check, name="health_check"), # Health check + path("health/", health_check, name="health_check"), # Health check # Documentation # path( diff --git a/egypt_metro/views.py b/egypt_metro/views.py index 10191f9..711eee0 100644 --- a/egypt_metro/views.py +++ b/egypt_metro/views.py @@ -1,25 +1,25 @@ -# import logging +import logging from django.http import JsonResponse -# from django.db import connection +from django.db import connection -# logger = logging.getLogger(__name__) +logger = logging.getLogger(__name__) -# def health_check(request): -# """ -# Health check view to verify the application is running properly. -# """ -# try: -# # Check database connection -# with connection.cursor() as cursor: -# cursor.execute("SELECT 1;") +def health_check(request): + """ + Health check view to verify the application is running properly. + """ + try: + # Check database connection + with connection.cursor() as cursor: + cursor.execute("SELECT 1;") -# # Return a success response -# return JsonResponse({"status": "ok"}, status=200) + # Return a success response + return JsonResponse({"status": "ok"}, status=200) -# except Exception as e: -# logger.error("Health check failed", exc_info=e) -# return JsonResponse({"status": "error", "message": str(e)}, status=500) + except Exception as e: + logger.error("Health check failed", exc_info=e) + return JsonResponse({"status": "error", "message": str(e)}, status=500) def custom_404(request, exception=None):