1- test :
2- runs-on : ubuntu-latest
1+ name : CI-CD Docker to GHCR
32
4- steps :
5- - name : Check out repository
6- uses : actions/checkout@v4
3+ on :
4+ push :
5+ branches :
6+ - main
7+ workflow_dispatch :
78
8- - name : Set up Python
9- uses : actions/setup-python@v5
10- with :
11- python-version : " 3.11"
9+ env :
10+ REGISTRY : ghcr.io
11+ IMAGE_NAME : gbadedata/ml-inference-api
1212
13- - name : Install dependencies
14- run : |
15- python -m pip install --upgrade pip
16- pip install -r requirements.txt
17- pip install pytest
13+ jobs :
14+ test :
15+ runs-on : ubuntu-latest
1816
19- - name : Train model artifact
20- run : python model/train.py
17+ steps :
18+ - name : Check out repository
19+ uses : actions/checkout@v4
2120
22- - name : Run tests
23- run : pytest
21+ - name : Set up Python
22+ uses : actions/setup-python@v5
23+ with :
24+ python-version : " 3.11"
25+
26+ - name : Install dependencies
27+ run : |
28+ python -m pip install --upgrade pip
29+ pip install -r requirements.txt
30+ pip install pytest
31+
32+ - name : Train model artifact
33+ run : python model/train.py
34+
35+ - name : Verify model artifact exists
36+ run : ls -R model
37+
38+ - name : Run tests
39+ run : pytest
40+
41+ build-and-push :
42+ runs-on : ubuntu-latest
43+ needs : test
44+
45+ permissions :
46+ contents : read
47+ packages : write
48+
49+ steps :
50+ - name : Check out repository
51+ uses : actions/checkout@v4
52+
53+ - name : Train model artifact
54+ run : |
55+ python -m pip install --upgrade pip
56+ pip install -r requirements.txt
57+ python model/train.py
58+
59+ - name : Log in to GHCR
60+ uses : docker/login-action@v3
61+ with :
62+ registry : ${{ env.REGISTRY }}
63+ username : ${{ github.actor }}
64+ password : ${{ secrets.GITHUB_TOKEN }}
65+
66+ - name : Extract Docker metadata
67+ id : meta
68+ uses : docker/metadata-action@v5
69+ with :
70+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
71+ tags : |
72+ type=raw,value=latest
73+ type=sha
74+
75+ - name : Build and push Docker image
76+ uses : docker/build-push-action@v6
77+ with :
78+ context : .
79+ push : true
80+ tags : ${{ steps.meta.outputs.tags }}
81+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments