Skip to content

Commit

Permalink
cicd complete
Browse files Browse the repository at this point in the history
  • Loading branch information
AzeemWaqarRao committed Nov 11, 2024
1 parent 7e95081 commit 665a4ff
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
Empty file removed .github/workflows
Empty file.
62 changes: 62 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Flask Docker CICD Tutorial

on:
push:
branches:
[ main ]
pull request:
branches:
[ main ]


jobs:
build-and-test:
runs-on: ubuntu-latest

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

- name: Setup Python
uses: actions/setup-python@v4
with:
python-versions: '3.9'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- 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: Setup Docker BuildX
uses: docker/setup-buildx-actions@v2

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

- name: Push image to Docker
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/flaskapp:latest

- name: Image digest
run: echo ${{ secrets.build-and-publish.outputs.digest }}


6 changes: 6 additions & 0 deletions DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.9-slim
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python", "app.py"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Github Actions Tutorial

This project includes,
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(debug=True, host='0.0.0.0', port=5000)
7 changes: 7 additions & 0 deletions test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from app import app

def test_home():
response = app.test_client.get('/')

assert response.status_code == 200
assert response.data == "hello world"

0 comments on commit 665a4ff

Please sign in to comment.