Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR12 #4

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python Package CI/CD

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build-and-deploy:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7"]

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

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8
if [ -f requirements-prod.txt ]; then pip install -r requirements-prod.txt; fi

- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Run Flask App
run: |
python app.py

- name: Set execute permission for deploy.sh
run: |
chmod +x deploy.sh

- name: Deploy to S3
run: |
./deploy.sh

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: '${{ secrets.AWS_ACCESS_KEY_ID }}'
aws-secret-access-key: '${{ secrets.AWS_SECRET_ACCESS_KEY }}'
aws-region: '${{ secrets.AWS_REGION }}'

- name: Get current date and time
id: date
run: 'echo "::set-output name=date::$(date +''%Y-%m-%d-%H:%M:%S'')"'

- name: Build and run Docker image
run: |
docker build -t python-flask:1 .
docker run --name python-flask -p 5000:5000 -d python-flask:1

- name: Deploy using AWS CodeDeploy
id: deploy
run: |
aws deploy create-deployment --application-name python_flask --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name python_flask --file-exists-behavior OVERWRITE --s3-location bucket=pythonflask1,key=app.zip-${{ github.sha }}-${{ steps.date.outputs.date }}.zip,bundleType=zip
15 changes: 15 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Assuming your Python application is in the current directory

# Zip the application
zip -r app.zip *

# Set your AWS S3 bucket name
S3_BUCKET="pythonflask1"

# Upload the zip file to S3
aws s3 cp app.zip s3://$S3_BUCKET/

# Clean up: Remove the local zip file
rm app.zip