Skip to content

Commit e90dcea

Browse files
author
Irene Busah
committed
Completed the CI/CD workflow and flask app
1 parent d0db3e6 commit e90dcea

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

.github/workflows/cicd.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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" ]

app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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)

test_app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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!"

0 commit comments

Comments
 (0)