0% found this document useful (0 votes)
6 views8 pages

CI/CD Pipeline Setup with GitHub Actions

The document outlines the process of setting up CI/CD pipelines using GitHub Actions, emphasizing the benefits of automated builds and deployments. It details key concepts, workflow creation, and best practices for integrating with cloud services while maintaining security through GitHub Secrets. Additionally, it provides a specific CI/CD pipeline example for a Python + Flask application, including setup instructions and deployment methods.

Uploaded by

Anand Shilu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

CI/CD Pipeline Setup with GitHub Actions

The document outlines the process of setting up CI/CD pipelines using GitHub Actions, emphasizing the benefits of automated builds and deployments. It details key concepts, workflow creation, and best practices for integrating with cloud services while maintaining security through GitHub Secrets. Additionally, it provides a specific CI/CD pipeline example for a Python + Flask application, including setup instructions and deployment methods.

Uploaded by

Anand Shilu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CI/CD with GitHub Actions – Setting up Automated Builds and

Deployments

1. 🔹 Introduction to CI/CD

 CI (Continuous Integration)

o Developers frequently merge code into a shared repository.

o Automated builds and tests ensure changes don’t break the


application.

 CD (Continuous Deployment/Delivery)

o After successful builds/tests, code is automatically deployed to


staging or production.

o Ensures rapid, reliable software delivery.

➡️Together, CI/CD improves development speed, code quality, and


reliability.

2. 🔹 Why GitHub Actions?

 Native CI/CD platform inside GitHub.

 YAML-based workflows (easy to customize).

 Runs directly on GitHub-hosted runners or self-hosted machines.

 Integrates with cloud providers (AWS, Azure, GCP, Render, etc.).

 Supports event-driven automation (on push, pull request, release,


schedule).

3. 🔹 Key Concepts in GitHub Actions

 Workflow → Automation pipeline defined in .github/workflows/.

 Event → Trigger (e.g., push, pull_request, schedule).

 Job → A set of steps that run in a runner.

 Runner → Virtual machine/container where jobs execute.

 Step → Individual task (checkout code, install dependencies, run


tests, deploy).
 Action → Prebuilt reusable task (e.g., checkout, setup-node, upload-
artifact).

4. 🔹 Setting up a CI/CD Pipeline

Step 1: Create Workflow File

Inside your repository:

repo-root/

└── .github/

└── workflows/

└── [Link]

Step 2: Basic Workflow Example

name: CI/CD Pipeline

on:

push:

branches: [ main ]

pull_request:

branches: [ main ]

jobs:

build:

runs-on: ubuntu-latest

steps:

- name: Checkout code

uses: actions/checkout@v3

- name: Set up [Link]

uses: actions/setup-node@v3

with:
node-version: '18'

- name: Install dependencies

run: npm install

- name: Run tests

run: npm test

deploy:

needs: build

runs-on: ubuntu-latest

if: [Link] == 'refs/heads/main'

steps:

- name: Checkout code

uses: actions/checkout@v3

- name: Deploy to Production

run: echo "Deploying app..."

# Replace with actual deployment command (e.g., docker push, AWS


CLI, Render CLI, etc.)

5. 🔹 Adding Deployment to Cloud (Example: Render/Heroku/AWS)

 For Render/Heroku → Use API keys stored in GitHub Secrets.

- name: Deploy to Render

run: curl -X POST "$RENDER_DEPLOY_HOOK"

 For AWS → Use AWS GitHub Action with access keys.

- name: Deploy to AWS S3

uses: aws-actions/s3-sync@v1

with:
bucket: my-bucket

region: ap-south-1

source-dir: ./build

6. 🔹 Best Practices

 Keep secrets in GitHub Secrets (never hardcode credentials).

 Use matrix builds to test across multiple OS/language versions.

 Cache dependencies for faster builds (actions/cache).

 Separate build, test, and deploy jobs.

 Use status badges in [Link] to display workflow results.

7. 🔹 Benefits of CI/CD with GitHub Actions

✅ Automated testing → Higher code quality


✅ Faster feedback loop for developers
✅ Reliable, repeatable deployments
✅ Works across many programming languages and cloud providers
✅ Easy to maintain since config is stored in the repository

📌 Summary:

 GitHub Actions allows creating event-driven workflows for CI/CD.

 Workflows are written in YAML inside .github/workflows/.

 Key steps: checkout → install → test → build → deploy.

 Supports secrets, cloud integrations, and reusable workflows.

Perfect 👍 Since you’re working with Python + Flask + ML models, I’ll


give you a ready-to-use CI/CD pipeline with GitHub Actions.

This workflow will:

1. Run whenever you push code to main.

2. Set up Python environment.


3. Install dependencies.

4. Run tests (you can customize).

5. Deploy (example: Render/Heroku — we’ll keep both patterns).

🚀 CI/CD Pipeline for Python + Flask (ML Model)

Create a file:

.github/workflows/[Link]

name: CI/CD Pipeline - Flask ML App

on:

push:

branches: [ "main" ]

pull_request:

branches: [ "main" ]

jobs:

build-test:

runs-on: ubuntu-latest

steps:

# Step 1: Checkout repo

- name: Checkout code

uses: actions/checkout@v3

# Step 2: Set up Python

- name: Set up Python

uses: actions/setup-python@v4

with:

python-version: "3.10"
# Step 3: Install dependencies

- name: Install dependencies

run: |

python -m pip install --upgrade pip

pip install -r [Link]

# Step 4: Run tests

- name: Run tests

run: |

pytest tests/ --maxfail=1 --disable-warnings -q

deploy:

needs: build-test

runs-on: ubuntu-latest

if: [Link] == 'refs/heads/main'

steps:

- name: Checkout code

uses: actions/checkout@v3

- name: Set up Python

uses: actions/setup-python@v4

with:

python-version: "3.10"

# Example: Deploy to Render (using deploy hook stored in secrets)

- name: Deploy to Render

run: curl -X POST "$RENDER_DEPLOY_HOOK"


env:

RENDER_DEPLOY_HOOK: ${{ secrets.RENDER_DEPLOY_HOOK }}

# Example: Deploy to Heroku (needs API key in secrets)

# - name: Deploy to Heroku

# run: |

# git remote add heroku [Link]


{{ secrets.HEROKU_API_KEY }}@[Link]/$
{{ secrets.HEROKU_APP_NAME }}.git

# git push heroku main

🔑 Setup Instructions

1. Add a [Link] with all dependencies (Flask, joblib,


scikit-learn, etc.).

2. Create a tests/ folder with unit tests (example: API response test).

3. # tests/test_app.py

4. def test_dummy():

5. assert 1 + 1 == 2

6. Set GitHub Secrets

o Go to your repo → Settings → Secrets and variables →


Actions → New repository secret.

o Add:

 RENDER_DEPLOY_HOOK (if using Render)

 HEROKU_API_KEY and HEROKU_APP_NAME (if using


Heroku)

7. Push code → GitHub Actions will run CI/CD automatically.

✅ With this setup:

 Every commit to main is built, tested, and deployed.

 Secrets keep credentials safe.

 You can extend it for Docker builds, AWS, or Azure.

You might also like