Skip to content

Commit

Permalink
Add poetry dependency instalation for ci build testing pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
dotpep committed Feb 29, 2024
1 parent 68c984f commit 2d36508
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
63 changes: 52 additions & 11 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and Deploy Code
on: [push, pull_request]

jobs:
build:
build-ci:
environment:
name: testing
env:
Expand Down Expand Up @@ -40,15 +40,54 @@ jobs:
with:
python-version: '3.10'

- name: Update pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: pip install -r requirements.txt
#- name: Update pip
# run: python -m pip install --upgrade pip
#- name: Install dependencies
# run: pip install -r requirements.txt

- name: Run tests with PyTest
run: |
pip install pytest
pytest -v
#- name: Run tests with PyTest
# run: |
# pip install pytest
# pytest -v

#- name: Install Poetry version 1.7.1
# uses: abatilo/actions-poetry@v2
# with:
# poetry-version: '1.7.1'
#- name: Setup a local virtual environment (if no poetry.toml file)
# run: |
# poetry config virtualenvs.create true --local
# poetry config virtualenvs.in-project true --local
#- uses: actions/cache@v3
# name: Define a cache for the virtual environment based on the dependencies lock file
# with:
# path: ./.venv
# key: venv-${{ hashFiles('poetry.lock') }}
#- name: Install the project dependencies
# run: poetry install
#- name: Run the automated tests with PyTest
# run: poetry run pytest -v

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: '1.7.1'
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install project dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Run tests
run: poetry run pytest -v tests/

#- name: Login to Docker Hub
# uses: docker/login-action@v3
Expand All @@ -69,11 +108,11 @@ jobs:
#- name: Image digest
# run: echo ${{ steps.docker_build.outputs.digest }}

deploy:
deploy-cd:
environment:
name: production
runs-on: ubuntu-20.04
needs: build
needs: build-ci
steps:
- name: Checkout Pulling Git Repo
uses: actions/checkout@v4
Expand All @@ -87,6 +126,8 @@ jobs:
script: |
cd api/src
git pull
poetry install --no-interaction
poetry run alembic upgrade head
echo ${{ secrets.PROD_PASSWORD }} | sudo -S systemctl restart api
# login to our vps ubuntu server with ssh
# cd api/src
Expand Down
5 changes: 1 addition & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from . import models
from .database import engine
from .routers import post, user, auth, vote

#models.Base.metadata.create_all(bind=engine)
Expand All @@ -26,8 +24,7 @@
app.include_router(auth.router)

app.get('/', tags=["Welcome Home Page"])(lambda: {
"message": "Welcome to my Social Media API powered by FastAPI, API documentation in '/docs' and `/redoc` endpoint. \
Succesfully deployed to production VPS Ubuntu Server with CI/CD Github Pipline.",
"message": "Welcome to my Social Media API powered by FastAPI, API documentation in '/docs' and `/redoc` endpoint.",
"source_code": "https://github.com/dotpep/social-media-api",
"domain_name": "https://dotpep.xyz/"})

Expand Down
2 changes: 1 addition & 1 deletion docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
ports:
- 80:8000
command: ["sh", "-c", "alembic upgrade head &&
uvicorn app.main:app --host 0.0.0.0 --port 8000"]
gunicorn --workers 2 --worker-class uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:8000"]
environment:
- DATABASE_HOSTNAME=${DATABASE_HOSTNAME}
- DATABASE_PORT=${DATABASE_PORT}
Expand Down

0 comments on commit 2d36508

Please sign in to comment.