Skip to content

Conversation

@ashhley04
Copy link
Contributor

Title:
Add Docker support and Prometheus metrics for FastAPI

Description:
This PR addresses Issue #2: Add Docker Support for Local Development.

Changes included:

  • Added a Dockerfile for the FastAPI application to simplify setup.
  • Updated docker-compose.yml to orchestrate FastAPI, Prometheus, and Grafana.
  • Updated req.txt to ensure compatible Python dependencies (pydantic<2 to avoid version issues).
  • Modified apps.py to include a Prometheus metrics endpoint (/metrics) and a basic health check (/health).
  • Verified that FastAPI, Prometheus, and Grafana work together out-of-the-box using Docker.

Benefit:

  • New developers can now spin up the entire monitoring stack with one command:

docker-compose up -d

  • Reduces setup errors and improves developer experience.
  • Prometheus automatically scrapes FastAPI metrics, which can be visualized in Grafana dashboards.

How to test:

  1. Run docker-compose up -d to start all services.
  2. Visit FastAPI: http://localhost:8000/ → should return {"message": "Hello World"}
  3. Visit metrics endpoint: http://localhost:8000/metrics → Prometheus metrics should appear.
  4. Visit Prometheus: http://localhost:9090 → ensure fastapi:8000 target is UP.
  5. Visit Grafana: http://localhost:3000 → add Prometheus as data source and verify metrics dashboards.

@AryanSharma9917 AryanSharma9917 self-requested a review October 20, 2025 17:10
@AryanSharma9917
Copy link
Owner

Hi @ashhley04,

The workflow is failing because the docker/login-action step requires DOCKERHUB_USERNAME and DOCKERHUB_TOKEN, which aren’t available in PRs coming from forks (GitHub blocks secrets for security reasons).

To fix this, we can conditionally skip the login step for pull request events. Example fix:

- name: Log in to Docker Hub
  if: github.event_name != 'pull_request'
  uses: docker/login-action@v3
  with:
    username: ${{ secrets.DOCKERHUB_USERNAME }}
    password: ${{ secrets.DOCKERHUB_TOKEN }}

Copy link
Owner

@AryanSharma9917 AryanSharma9917 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to update the GitHub Actions workflow file to conditionally skip the Docker login step for pull request events.

@AryanSharma9917
Copy link
Owner

Hi @ashhley04,

The workflow is failing because the docker/login-action step requires DOCKERHUB_USERNAME and DOCKERHUB_TOKEN, which aren’t available in PRs coming from forks (GitHub blocks secrets for security reasons).

To fix this, we can conditionally skip the login step for pull request events. Example fix:

- name: Log in to Docker Hub
  if: github.event_name != 'pull_request'
  uses: docker/login-action@v3
  with:
    username: ${{ secrets.DOCKERHUB_USERNAME }}
    password: ${{ secrets.DOCKERHUB_TOKEN }}

@rakshitsharma0402 please review the PR and see the previous comments. Workflow is failing the reason being docker requires ID and pass so in the workflow what we can do is skip this part of checking the authentication and move ahead.

@ashhley04
Copy link
Contributor Author

Hello @AryanSharma9917,
I’ve implemented the changes as suggested:

  1. Added a condition to skip the Docker login step for pull request events.
  2. Added a message step to indicate when the Docker login is skipped.
  3. Modified the build-and-push step to only push the image on non-PR events.
  4. The workflow file .github/workflows/docker-image.yml has been updated and pushed to the branch add-docker-support.

Please review and let me know if any further adjustments are needed.

@AryanSharma9917
Copy link
Owner

LGTM! Thanks @ashhley04 for the contribution.

Copy link
Owner

@AryanSharma9917 AryanSharma9917 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AryanSharma9917 AryanSharma9917 merged commit 93769c8 into AryanSharma9917:main Oct 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants