Skip to content

dxas90/learn-python

Repository files navigation

learn-python Build Status

A simple Flask microservice for learning Kubernetes, Docker, and modern Python development practices.

🚀 Features

  • RESTful API with multiple endpoints
  • Health checks and monitoring endpoints
  • CORS support for cross-origin requests
  • Security headers (X-Frame-Options, CSP, etc.)
  • Docker support with multi-stage builds
  • Kubernetes ready with deployment configurations
  • CI/CD pipelines (GitLab CI, GitHub Actions)
  • Comprehensive testing with pytest
  • Production-ready with Gunicorn

📋 API Endpoints

Endpoint Method Description
/ GET Welcome page with API documentation
/ping GET Simple ping-pong health check
/healthz GET Detailed health check with system metrics
/info GET Application and system information
/version GET Application version information
/echo POST Echo back the request body

🛠️ Quick Start

Prerequisites

  • Python 3.12 or higher
  • Docker (optional)
  • make (optional, for using Makefile commands)

Local Development

  1. Clone the repository
git clone https://github.com/dxas90/learn-python.git
cd learn-python
  1. Install dependencies
make install
# or manually:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
  1. Run the application
make dev
# or manually:
source .venv/bin/activate
FLASK_ENV=development flask run --host=0.0.0.0 --port=8000
  1. Test the API
curl http://localhost:8000/
curl http://localhost:8000/ping
curl http://localhost:8000/healthz

Running Tests

make test
# or with coverage:
make test-coverage

Docker Deployment

# Build the image
make docker-build

# Run the container
make docker-run

# Or manually:
docker build -t learn-python .
docker run -p 8000:8000 learn-python

OpenShift Deployment

oc new-app https://github.com/dxas90/learn-python.git

Kubernetes Deployment

make k8s-deploy
# or manually:
kubectl apply -f k8s/
          Git Actions:                CI System Actions:

   +-------------------------+       +-----------------+
+-►| Create a Feature Branch |   +--►| Build Container |
|  +------------+------------+   |   +--------+--------+
|               |                |            |
|               |                |            |
|      +--------▼--------+       |    +-------▼--------+
|  +--►+ Push the Branch +-------+    | Push Container |
|  |   +--------+--------+            +-------+--------+
|  |            |                             |
|  |            |                             |
|  |     +------▼------+            +---------▼-----------+
|  +-----+ Test/Verify +◄-------+   | Deploy Container to |
|        +------+------+        |   | Ephemeral Namespace |
|               |               |   +---------+-----------+
|               |               |             |
|               |               +-------------+
|               |
|               |                    +-----------------+
|               |             +-----►| Build Container |
|      +--------▼--------+    |      +--------+--------+
|  +--►+ Merge to Master +----+               |
|  |   +--------+--------+                    |
|  |            |                     +-------▼--------+
|  |            |                     | Push Container |
|  |     +------▼------+              +-------+--------+
|  +-----+ Test/Verify +◄------+              |
|        +------+------+       |              |
|               |              |    +---------▼-----------+
|               |              |    | Deploy Container to |
|               |              |    | Staging   Namespace |
|               |              |    +---------+-----------+
|               |              |              |
|               |              +--------------+
|               |
|        +------▼-----+             +---------------------+
+--------+ Tag Master +------------►| Deploy Container to |
         +------------+             |     Production      |
                                    +---------------------+

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 3

  •  
  •  
  •