Skip to content

Commit

Permalink
updated docker file and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelstrike committed Jan 29, 2025
1 parent d1776d5 commit 990a7c9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI/CD for Dockerized Flask App

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
dockerbuild:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build The Docker Image
run: docker build . --file DockerFile --tag workflow-test:$(date +%s)
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flask
pip install pytest
- name: Run tests
run: |
pytest
build-and-publish:
needs: build-and-test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./DockerFile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/flasktest-app:latest

- name: Image digest
run: echo ${{ steps.build-and-publish.outputs.digest }}
11 changes: 11 additions & 0 deletions DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.9-slim

WORKDIR /app

COPY . /app

RUN pip install flask

EXPOSE 5001

CMD [ "python" , "app.py" ]
10 changes: 10 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
return 'Hello, World!'

if __name__ == '__main__':
app.run(host="0.0.0.0", port=5001)
6 changes: 6 additions & 0 deletions test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from app import app

def test_home():
response = app.test_client().get('/')
assert response.status_code == 200
assert response.data == b'Hello, World!'

0 comments on commit 990a7c9

Please sign in to comment.