In this blog, we’ll walk through the process of setting up a Continuous Integration (CI) and Continuous Deployment (CD) pipeline for a Python Flask application using GitHub Actions. GitHub Actions allows you to automate workflows directly in your GitHub repository.
What is GitHub Actions?
-
- GitHub Actions is a feature provided by GitHub that enables you to automate workflows directly within your GitHub repository.
- It allows you to define custom workflows using YAML syntax, which are triggered by events like code pushes, pull requests, or other repository activities.
By setting up CI/CD pipeline with GitHub Actions, you ensure that your Flask application undergoes automated testing and, if successful, is automatically deployed . This helps maintain code quality, catch issues early, and streamline the release process.
Uploading your Flask app along with the Dockerfile to GitHub :
Follow these steps:
- Create a GitHub Account: If you don’t have a GitHub account, create one at GitHub. Follow this tutorial for more information [link]
- Create a New Repository:
- Log in to your GitHub account.
- Click on the “+” sign in the top right corner and choose “New repository.”
- Fill in the repository name, description, and other details.
- Initialize this repository with a README –
README.md
file should contain information that helps users and contributors understand your project - Choose
.gitignore
template for Python because that is the technology you are using
To edit the README on GitHub:
- Click on the “README.md” file.
- On the top-right of the README, you’ll see a pencil icon. Click on it to enter the edit mode.
- Make your changes.
- Add a commit message to describe your changes.
- Set Up Git Locally:
- Install Git on your local machine if you haven’t already.
- Open a terminal and navigate to your project directory.
- Initialize a Git Repository:
bash
git init
- Add Your Files to the Repository:
bash
git add .
- Commit Your Changes:
bash
git commit -m "Initial commit"
- Connect to GitHub:
- On your GitHub repository page, you’ll find a section called “Quick setup.”
- Copy the URL under “…or push an existing repository from the command line.”
- Push to GitHub:
bash
git remote add origin <paste_your_repository_url>
git branch -M main
git push -u origin main
- Verify on GitHub:
- Visit your GitHub repository. You should see your code and files there.