A simple Python REST API server and client application demonstrating GitLab CI/CD running on a GitHub-hosted repository.
├── server/
│ └── app.py # Flask REST API server
├── client/
│ └── client.py # Python client for the API
├── tests/
│ └── test_server.py # Unit tests
├── .gitlab-ci.yml # GitLab CI pipeline configuration
├── requirements.txt # Python dependencies
└── README.md
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtpython -m server.appThe server will start on http://localhost:5000
# Check server health
python -m client.client health
# Add a message
python -m client.client add "Hello, World!" --author "John"
# List all messages
python -m client.client list
# Get a specific message
python -m client.client get 1
# Delete a message
python -m client.client delete 1pytest tests/ -v| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check |
| GET | /messages |
Get all messages |
| POST | /messages |
Add a new message |
| GET | /messages/<id> |
Get a specific message |
| DELETE | /messages/<id> |
Delete a message |
This project is designed to have its code on GitHub while running CI/CD pipelines on GitLab. Here's how to set it up:
-
Create a GitLab account at gitlab.com if you don't have one
-
Create a new project in GitLab:
- Go to New Project → Run CI/CD for external repository
- Select GitHub as the source
- Authorize GitLab to access your GitHub account
- Select this repository from the list
-
GitLab will automatically:
- Mirror your GitHub repository
- Run the CI pipeline defined in
.gitlab-ci.ymlon every push - Report pipeline status back to GitHub (as commit statuses)
-
Create an empty GitLab project
-
Set up repository mirroring:
- Go to Settings → Repository → Mirroring repositories
- Add your GitHub repo URL:
https://github.com/YOUR_USERNAME/test-gitlab-ci.git - Set direction to Pull
- Add authentication (GitHub personal access token)
- Enable Mirror only protected branches if desired
-
Configure the mirror:
- Set update frequency (GitLab.com mirrors every 5 minutes minimum)
- Or trigger manual sync when needed
You can also trigger GitLab CI from GitHub Actions. Add this to .github/workflows/trigger-gitlab.yml:
name: Trigger GitLab CI
on: [push, pull_request]
jobs:
trigger:
runs-on: ubuntu-latest
steps:
- name: Trigger GitLab Pipeline
run: |
curl -X POST \
-F token=${{ secrets.GITLAB_TRIGGER_TOKEN }} \
-F ref=main \
https://gitlab.com/api/v4/projects/YOUR_PROJECT_ID/trigger/pipelineThe GitLab CI pipeline includes:
flake8- Python code lintingblack- Code formatting check
pytest- Unit tests with coverage reporting- Import verification
- Application startup verification
No environment variables are required for basic operation. For production deployments, consider setting:
FLASK_ENV- Set toproductionfor production deploymentsFLASK_SECRET_KEY- Secret key for session management
MIT License - Feel free to use this as a template for your own projects!