Skip to content

Commit 1aa7e86

Browse files
implement full CI/CD pipeline with Docker image publishing
1 parent 381077e commit 1aa7e86

3 files changed

Lines changed: 105 additions & 42 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
release:
9+
types: [ published ]
10+
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
jobs:
16+
test:
17+
name: Test
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set up Python 3.12
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: "3.12"
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install -r requirements.txt
32+
33+
- name: Lint with flake8
34+
run: |
35+
pip install flake8
36+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.venv,yolov5,data
37+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=.venv,yolov5,data
38+
39+
- name: Run tests
40+
run: |
41+
python -m pytest tests/ -v
42+
43+
build-and-push:
44+
name: Build and Push Docker Image
45+
runs-on: ubuntu-latest
46+
needs: test
47+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Set up Docker Buildx
53+
uses: docker/setup-buildx-action@v3
54+
55+
- name: Log in to GitHub Container Registry
56+
uses: docker/login-action@v3
57+
with:
58+
registry: ghcr.io
59+
username: ${{ github.actor }}
60+
password: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Extract metadata
63+
id: meta
64+
uses: docker/metadata-action@v5
65+
with:
66+
images: ghcr.io/${{ github.repository_owner }}/defectnet
67+
tags: |
68+
type=ref,event=branch
69+
type=sha,prefix={{branch}}-
70+
type=raw,value=latest,enable={{is_default_branch}}
71+
72+
- name: Build and push Docker image
73+
uses: docker/build-push-action@v5
74+
with:
75+
context: .
76+
push: true
77+
tags: ${{ steps.meta.outputs.tags }}
78+
labels: ${{ steps.meta.outputs.labels }}
79+
cache-from: type=gha
80+
cache-to: type=gha,mode=max
81+

.github/workflows/python-app.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# DefectNet [![Tests](https://github.com/stuartasiimwe7/DefectNet/actions/workflows/python-app.yml/badge.svg)](https://github.com/stuartasiimwe7/DefectNet/actions/workflows/python-app.yml)
2-
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
3-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1+
# DefectNet [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![CI/CD](https://github.com/stuartasiimwe7/DefectNet/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/stuartasiimwe7/DefectNet/actions/workflows/ci-cd.yml)
42

53
A RestFul API for automated detecting of defects in Printed Circuit Boards (PCBs) using YOLOv5 deep learning models, built with FastAPI.
64

@@ -101,7 +99,7 @@ There is comprehensive test coverage across all components with 32 passing tests
10199

102100
**Prerequisites:** Python 3.8+ (see requirements.txt for dependencies)
103101

104-
### Local Setup
102+
### Want to replicate?
105103

106104
```bash
107105
# Clone and navigate
@@ -124,6 +122,13 @@ uvicorn app:app --reload --host 0.0.0.0 --port 8000
124122

125123
### Docker Setup
126124

125+
**Option 1: Pull from GitHub Container Registry**
126+
```bash
127+
docker pull ghcr.io/stuartasiimwe7/defectnet:latest
128+
docker run -p 8000:8000 ghcr.io/stuartasiimwe7/defectnet:latest
129+
```
130+
131+
**Option 2: Build locally**
127132
```bash
128133
docker build -t defectnet .
129134
docker run -p 8000:8000 defectnet
@@ -173,6 +178,20 @@ MAX_FILE_SIZE_MB=1
173178
LOG_LEVEL=INFO
174179
```
175180

181+
## CI/CD Pipeline
182+
183+
This project uses GitHub Actions for continuous integration and deployment:
184+
185+
**Continuous Integration:**
186+
- Automated testing on every push/PR
187+
- Code linting with flake8
188+
- Python 3.12 compatibility checks
189+
190+
**Continuous Deployment:**
191+
- Automatic Docker image builds on main branch
192+
- Published to GitHub Container Registry
193+
- Tagged with commit SHA and 'latest'
194+
176195
## Testing
177196

178197
Run all tests:
@@ -201,4 +220,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
201220

202221
## Acknowledgments
203222

204-
Built using YOLOv5 by Ultralytics and FastAPI framework for production-ready PCB defect detection.
223+
Built using YOLOv5 by Ultralytics and FastAPI framework.

0 commit comments

Comments
 (0)