A CI/CD pipeline helps you automatically test and deliver your Flask app. It saves time and reduces mistakes by making sure your app works well before it goes live.
CI/CD pipeline for Flask
name: Flask CI/CD Pipeline
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
pytest
- name: Deploy
if: success()
run: |
echo "Deploying Flask app..."
# Add your deploy commands hereThis example uses GitHub Actions syntax for a CI/CD pipeline.
Replace the deploy step with commands specific to your hosting service.
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pyteston:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy to Heroku
run: |
heroku login
git push heroku mainThis pipeline runs on every push. It checks out the code, sets up Python 3.12, installs dependencies, runs tests with pytest, and if tests pass, it runs a deploy step (here just a placeholder echo command).
name: Flask CI/CD Pipeline
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
pytest
- name: Deploy
if: success()
run: |
echo "Deploying Flask app..."Make sure your Flask app has tests written with pytest or another test tool.
Customize the deploy step to match your hosting environment (Heroku, AWS, etc.).
Use secrets or environment variables to keep sensitive info safe during deployment.
CI/CD pipelines automate testing and deployment for Flask apps.
They run on code changes to catch errors early and speed up delivery.
Use GitHub Actions or similar tools to create your pipeline easily.