File tree Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 1+ name : CI/CD for Dockerized Flask APP
2+
3+ on :
4+ push :
5+ branches : [main]
6+ pull_request :
7+ branches : [main]
8+
9+ jobs :
10+ build-and-test :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - name : Checkout code
15+ uses : actions/checkout@v3
16+
17+ - name : Set up Python
18+ uses : actions/setup-python@v4
19+ with :
20+ python-version : ' 3.13.5'
21+
22+ - name : Install dependencies
23+ run :
24+ python -m pip install --upgrade pip
25+ pip install flask
26+ pip install pytest
27+
28+ - name : Run tests
29+ run :
30+ pytest
31+
32+ build-and-publish :
33+ needs : build-and-test
34+ runs-on : ubuntu-latest
35+
36+ steps :
37+ - name : Checkout code
38+ uses : actions/checkout@v3
39+
40+ - name : Set up Docker Buildx
41+ uses : docker/setup-buildx-action@v2
42+
43+ - name : Login to DockerHub
44+ uses : docker/login-action@v2
45+ with :
46+ username : ${{secrets.DOCKER_USERNAME}}
47+ password : ${{secrets.DOCKER_PASSWORD}}
48+
49+ - name : Build and push Docker image
50+ uses : docker/build-push-action@v4
51+ with :
52+ context : .
53+ push : true
54+ tags : ${{ secrets.DOCKER_USERNAME }}/flask-app:latest
55+
56+ - name : Image digest
57+ run : echo ${{ steps.build-and-publish.outputs.digest }}
58+
Original file line number Diff line number Diff line change 1+ FROM python:3.9-slim
2+
3+ # setting the working directory
4+ WORKDIR /app
5+
6+ # copying the current directory into the container
7+ COPY . /app
8+
9+ # installing the flask
10+ RUN pip install flask
11+
12+ # exposing the PORT
13+ EXPOSE 5000
14+
15+ # running the app
16+ CMD [ "python" , "app.py" ]
Original file line number Diff line number Diff line change 1+ from flask import Flask
2+
3+ # creating the flask app
4+ app = Flask (__name__ )
5+
6+ @app .route ("/" )
7+ def home ():
8+ return "Hello World!"
9+
10+
11+ if __name__ == '__main__' :
12+ app .run (host = 'localhost' , port = 5000 , debug = True )
Original file line number Diff line number Diff line change 1+ from app import app
2+
3+ # defining the test function
4+ def test_home ():
5+ response = app .test_client ().get ("/" )
6+
7+ assert response .status_code == 200
8+ assert response .data == b"Hello World!"
You can’t perform that action at this time.
0 commit comments