File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+ dockerbuild :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - uses : actions/checkout@v4
14+ - name : Build The Docker Image
15+ run : docker build . --file DockerFile --tag workflow-test:$(date +%s)
16+
17+ build-and-test :
18+ runs-on : ubuntu-latest
19+
20+ steps :
21+ - name : Checkout code
22+ uses : actions/checkout@v3
23+
24+ - name : Set up Python
25+ uses : actions/setup-python@v4
26+ with :
27+ python-version : ' 3.9'
28+
29+ - name : Install dependencies
30+ run : |
31+ python -m pip install --upgrade pip
32+ pip install flask
33+ pip install pytest
34+
35+ - name : Run tests
36+ run : |
37+ pytest
38+
39+ build-and-publish :
40+ needs : build-and-test
41+ runs-on : ubuntu-latest
42+
43+ steps :
44+ - name : Checkout code
45+ uses : actions/checkout@v3
46+
47+ - name : Set up Docker Buildx
48+ uses : docker/setup-buildx-action@v2
49+
50+ - name : Login to DockerHub
51+ uses : docker/login-action@v2
52+ with :
53+ username : ${{ secrets.DOCKER_USERNAME }}
54+ password : ${{ secrets.DOCKER_PASSWORD }}
55+
56+ - name : Build and push Docker image
57+ uses : docker/build-push-action@v4
58+ with :
59+ context : .
60+ file : ./DockerFile
61+ push : true
62+ tags : ${{ secrets.DOCKER_USERNAME }}/flasktest-app:latest
63+
64+ - name : Image digest
65+ run : echo ${{ steps.build-and-publish.outputs.digest }}
Original file line number Diff line number Diff line change 1+ venv
Original file line number Diff line number Diff line change 1+ # Use the official Python image from the Docker Hub
2+ FROM python:3.9-slim
3+
4+ # Set the working directory
5+ WORKDIR /app
6+
7+ # Copy the current directory contents into the container at /app
8+ COPY . /app
9+
10+ # Install any needed packages specified in requirements.txt
11+ RUN pip install flask
12+
13+ # Make port 5000 available to the world outside this container
14+ EXPOSE 5000
15+
16+ # Run app.py when the container launches
17+ CMD ["python", "app.py"]
Original file line number Diff line number Diff line change 1+ ## This project shouw how to work with github action
Original file line number Diff line number Diff line change 1+ from flask import Flask
2+
3+ app = Flask (__name__ )
4+
5+ @app .route ("/" )
6+ def home ():
7+ return "Hello World!"
8+
9+ if __name__ == "__main__" :
10+ app .run (host = "0.0.0.0" ,port = 5000 )
Original file line number Diff line number Diff line change 1+ Flask
2+ pytest
Original file line number Diff line number Diff line change 1+ from app import app
2+
3+ def test_home ():
4+ response = app .test_client ().get ("/" )
5+
6+ assert response .status_code == 200
7+ assert response .data == b"Hello World!"
You can’t perform that action at this time.
0 commit comments