Skip to content

Commit

Permalink
Merge pull request #91 from hngprojects/dev
Browse files Browse the repository at this point in the history
worflow files for staging, dev and prod
  • Loading branch information
nwanoch authored Jul 19, 2024
2 parents 6b0efc6 + 2fc1ead commit 09ade2e
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PYTHON_ENV=dev
DB_TYPE=mysql
DB_TYPE=postgresql
DB_NAME=dbname
DB_USER=user
DB_PASSWORD=password
DB_HOST=127.0.0.1
DB_PORT=3306
MYSQL_DRIVER=pymysql
DB_URL="mysql+pymysql://user:[email protected]:3306/dbname"
DB_PORT=5432
MYSQL_DRIVER=pymysql
DB_URL="postgresql://user:[email protected]:5432/dbname"
SECRET_KEY = ""
ALGORITHM = HS256
ACCESS_TOKEN_EXPIRE_MINUTES = 10
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/cd.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Dev Branch Deployment

on:
workflow_run:
workflows: ["CI"]
types:
- completed
branches: [dev]

jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use SSH Action
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd python/dev_source_code/
git pull origin dev
source .venv/bin/activate
pip install -r requirements.txt
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo 'The triggering workflow failed'
36 changes: 36 additions & 0 deletions .github/workflows/cd.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Dev Branch Deployment

on:
workflow_run:
workflows: ["CI"]
types:
- completed
branches: [main]

jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use SSH Action
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd python/prod_source_code/
git pull origin main
source .venv/bin/activate
pip install -r requirements.txt
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo 'The triggering workflow failed'
36 changes: 36 additions & 0 deletions .github/workflows/cd.staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Dev Branch Deployment

on:
workflow_run:
workflows: ["CI"]
types:
- completed
branches: [staging]

jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use SSH Action
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd python/staging_source_code/
git pull origin staging
source .venv/bin/activate
pip install -r requirements.txt
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo 'The triggering workflow failed'
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
push:
branches: [main, staging, dev]
pull_request:
branches: [main, staging, dev]

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

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER:
POSTGRES_PASSWORD:
POSTGRES_DB:
ports:
- 5432:5432

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

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
virtual-environment: venv

- name: Install dependencies
run: |
pip install -r requirements.txt
# - name: Copy env file
# run: cp .env.sample .env

# - name: Copy env file for main
# if: github.ref == 'refs/heads/main'
# run: cp .env.production .env

# - name: Copy env file for staging
# if: github.ref == 'refs/heads/staging'
# run: cp .env.staging .env

# - name: Run migrations
# run: |
# activate
# alembic upgrade head

# - name: Run tests
# run: |
# activate
# pytest
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ bcrypt
passlib
pymysql
uuid7
psycopg2-binary

0 comments on commit 09ade2e

Please sign in to comment.