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

Added automatic deployment process. #24

Open
wants to merge 4 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
19 changes: 0 additions & 19 deletions .github/workflows/ci.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI/CD
on: [push]

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python $
uses: actions/setup-python@v4
with:
python-version-file: '.python-version' # Read python version from a file
- name: Install dependencies
run: |
pip install --require-hashes -r requirements.txt -r dev-requirements.txt
- name: Test with pytest
run: |
make test
redeploy:
name: Redeploy
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master'

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Create PEM file from secret and set permissions
run: |
echo "${{ secrets.SSH_KEY }}" | tr -d '\r' > key.pem
chmod 400 key.pem

- name: Deploy and restart flask app
run: |
ssh -o StrictHostKeyChecking=no -i "key.pem" ${{ secrets.CONNECTION_STRING }} 'bash -s' < ./redeploy.sh ${{ secrets.FLASK_APP_LOCATION }} ${{ secrets.SLACK_TOKENS }} ${{ secrets.DATA_URL }} ${{ secrets.FLASK_DEBUG_VALUE }}
24 changes: 24 additions & 0 deletions redeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cd wtf-bot
BOT_DIR=$(pwd)

#Other python processes would require this to be refactored to target the wtf-bot processes specifically
PROCESS_ID=$(pgrep -o python3.8)
sudo kill -9 $PROCESS_ID

CHILD_ID=$(pgrep -o python3.8)
sudo kill -9 $CHILD_ID

git checkout master
git pull
pip3 install -r requirements.txt dev-requirements.txt
sudo rm log.txt

sudo -i bash << EOF
cd $BOT_DIR
export FLASK_APP=$1
export SLACK_TOKENS=$2
export DATA_URL=$3
export FLASK_DEBUG=$4
touch log.txt
nohup python3.8 -m flask run -h 0.0.0.0 -p 80 > log.txt 2>&1 &
EOF