This is a Flask application that uses Redis to count visits and have a healthcheck. It includes:
- A main page (
/) - A health check endpoint (
/health) - A visits counter endpoint (
/visits) - Dockerized services using Docker Compose
- CI pipeline via GitHub Actions with Docker healthcheck integration
- Flask for web serving
- Redis to store a persistent visit counter
- Docker Compose to orchestrate services
- Health checks for both Redis and Flask
- GitHub Actions CI pipeline that uses container health status
flask_redis_app/
├── .gitignore
├── Dockerfile
├── README.md
├── app.py
├── docker-compose.yml
├── requirements.txt
└── .github/
└── workflows/
In bash:
docker-compose up --build
Visit in browser:
http://localhost:8000 → Main page
http://localhost:8000/health → Health check
http://localhost:8000/visits → Visit counter (stored in Redis)
To stop (in bash):
docker-compose down
Both the Redis and Flask services are configured with health checks to ensure reliable startup and operation:
- Redis: Uses the command
redis-cli pingto confirm the Redis server is responsive. - Flask App: Periodically checks the
/healthendpoint to verify that the application is running and accessible.
The Flask service will only start after Redis passes its health check, ensuring service dependencies are met before proceeding.
This project includes a GitHub Actions workflow that automatically tests the application on each push or pull request to the main branch.
The CI pipeline performs the following steps:
- Checkout Code: Pulls the latest version of the repository.
- Build & Start Services: Uses Docker Compose to build and run the Flask and Redis containers in detached mode.
- Wait for Service Availability: Repeatedly checks the
/healthzendpoint to ensure the Flask service is up and responsive. - Validate Health Endpoint: Verifies that the
/healthendpoint returns HTTP status200, confirming the app is healthy. - Cleanup: Shuts down and removes the Docker containers after the tests complete.