- Log in to your GitHub account.
- Navigate to the Repositories section and click New.
- Name your repository, e.g.,
python-ci-cd-example. - Select the Public or Private option based on your preference.
- Check the box for Add a README file to initialize the repository.
- Click Create Repository to finalize the creation.
-
Open your terminal or command prompt.
-
Clone the repository using the following command (replace
your-usernamewith your GitHub username):git clone https://github.com/your-username/python-ci-cd-example.git
-
Navigate into the project directory:
cd python-ci-cd-example
- Log in to your DockerHub account.
- Click on Repositories in the top navigation menu and select Create Repository.
- Provide a name for the repository, e.g.,
python-ci-cd-example. - Ensure the Namespace matches your DockerHub username.
- Choose whether to make the repository Public or Private.
- Click Create to save the repository.
-
Place your Python application files (e.g.,
app.py) and test files (e.g.,test_app.py) in the local project directory. -
Create a
Dockerfilein the root of the project . -
Use the following commands to stage and commit the files to the repository:
git add . git commit -m "Add application files and Dockerfile" git push origin main
-
In the root of your project, create the following directory structure:
.github/workflows/. -
Create a file named
docker-publish.ymlin theworkflowsfolder and add the workflow configuration. -
Push the workflow file to the repository:
git add .github/workflows/docker-publish.yml git commit -m "Add GitHub Actions workflow for CI/CD" git push origin main
- Go to your repository on GitHub and navigate to Settings > Secrets and variables > Actions.
- Add the following secrets:
DOCKER_USERNAME: Your DockerHub username.DOCKER_PASSWORD: Your DockerHub access token.
-
Make any change in your project (e.g., edit
app.pyor add a new file) to trigger the pipeline. -
Push the change to the
mainbranch:git add . git commit -m "Test CI/CD pipeline" git push origin main
-
Go to the Actions tab in your GitHub repository to monitor the workflow progress.