Overview
CI/CD stands for:- CI: Continuous Integration
- CD: Continuous Delivery / Continuous Deployment
- Running tests
- Building Docker images
- Checking code
- Publishing Docker images
- Deploying applications
Basic CI/CD workflow
1. GitHub Actions
GitHub Actions is a CI/CD automation platform integrated with GitHub repositories. A workflow is defined using a YAML file. The standard location is:2. Workflow
A workflow is an automated process containing one or more jobs. Example:name defines the name displayed in the GitHub Actions interface.
3. Workflow Trigger
- Code is pushed to
main - A pull request targets
main
Example
4. Permissions
contents: read
Allows the workflow to read repository contents.
packages: write
Allows the workflow to push packages/images to GitHub Container Registry (GHCR).
5. Jobs
A workflow can contain multiple jobs. Example:6. Runner
7. Checkout Code
8. Setup Python
9. Install Dependencies
Becauserequirements.txt is inside the Day 45 folder:
10. Run Unit Tests
test_app.py:
11. Job Dependencies
The build job can depend on the test job:12. Login to GHCR
GHCR stands for: GitHub Container Registry The workflow can authenticate using the automatically providedGITHUB_TOKEN.
Important values
13. Build Docker Image
Dockerfile and application files are located.
14. Push Docker Image
15. Docker Image Tag
Example:16. Docker Repository Names Must Be Lowercase
An error occurred with:Rule
Use lowercase names for Docker image repositories:17. Complete ci.yml
18. Example app.py
19. Example requirements.txt
20. Example Dockerfile
21. Running the Workflow
After modifying the workflow:22. Expected GitHub Actions Result
23. Important GitHub Actions Concepts
24. CI/CD Pipeline Summary
Key learning points
- GitHub Actions automates CI/CD workflows.
- YAML files define workflows.
actions/checkoutretrieves repository code.actions/setup-pythonconfigures Python.pytestruns automated tests.needscontrols job execution order.- Docker can be built directly inside GitHub Actions.
- GHCR can store Docker images.
GITHUB_TOKENcan authenticate the workflow.- Docker image repository names should use lowercase.
- CI should run before the Docker image is built and published.