Skip to content

Instantly share code, notes, and snippets.

@twyle
Created June 6, 2022 07:52
Show Gist options
  • Save twyle/a7819d4d18b7338de9cdf3b73c3dec12 to your computer and use it in GitHub Desktop.
Save twyle/a7819d4d18b7338de9cdf3b73c3dec12 to your computer and use it in GitHub Desktop.
name: "Development Build"
on:
push:
branches: [ development ]
pull_request:
branches: [ development ]
jobs:
Build:
runs-on: ubuntu-latest
environment:
name: Development
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
if [ -d tests ] || [ -d test ]; then FLASK_ENV=${{secrets.FLASK_ENV}} python -m pytest; fi
Test-Local:
runs-on: ubuntu-latest
environment:
name: Development
needs: [Build]
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test application
run: |
FLASK_ENV=${{secrets.FLASK_ENV}} python main.py &
sleep 5
curl http://127.0.0.1:5000/ | grep "template api"
DeployDev:
name: Deploy to Dev
# if: github.event_name == 'pull_request'
needs: [Test-Local]
runs-on: ubuntu-latest
environment:
name: Development
steps:
- name: Deploy
run: echo I am deploying the api to AWS
- name: Deploy in EC2
env:
PRIVATE_KEY: ${{ secrets.AWS_PRIVATE_KEY }}
HOST_NAME : ${{ secrets.HOST_NAME }}
USER_NAME : ${{ secrets.USER_NAME }}
USER_PASSWORD: ${{ secrets.USER_PASSWORD }}
APP_DIR: ${{secrets.APP_DIR}}
SERVICE_NAME: ${{secrets.SERVICE_NAME}}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOST_NAME} "
cd ${APP_DIR} &&
git pull &&
echo ${USER_PASSWORD} | sudo -S systemctl restart ${SERVICE_NAME} "
Test-Remote:
name: Test Remote Deployment
needs: [DeployDev]
runs-on: ubuntu-latest
environment:
name: Development
steps:
- name: Test application
run: |
sleep 5
curl ${{ secrets.HOST_NAME }}:${{ secrets.PORT }} | grep "template api"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment