diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index f34cd93..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: ci -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 diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..8520875 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -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 }} diff --git a/redeploy.sh b/redeploy.sh new file mode 100644 index 0000000..a58cb1e --- /dev/null +++ b/redeploy.sh @@ -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 \ No newline at end of file