Skip to content

Commit

Permalink
Finalised the CI/CD pipeline and uncommented out the rest of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Penchukov committed Nov 5, 2023
1 parent 3b52501 commit 85e4f8d
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,82 @@ name: Build and Deploy Code
on: [push, pull_request]

jobs:
# build_and_test:
# environment:
# name: testing
# env:
# PG_USERNAME: ${{secrets.PG_USERNAME}}
# PG_PASSWORD: ${{secrets.PG_PASSWORD}}
# PG_HOST: ${{secrets.PG_HOST}}
# PG_PORT: ${{secrets.PG_PORT}}
# PG_DATABASE: ${{secrets.PG_DATABASE}}
# SECRET_KEY: ${{secrets.SECRET_KEY}}
# ALGORITHM: ${{secrets.ALGORITHM}}
# ACCESS_TOKEN_EXPIRE_MINUTES: ${{secrets.ACCESS_TOKEN_EXPIRE_MINUTES}}
# services:
# postgres:
# image: postgres
# env:
# POSTGRES_PASSWORD: ${{secrets.PG_PASSWORD}}
# POSTGRES_DB: ${{secrets.PG_DATABASE}}_test
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# ports:
# - 5432:5432
# runs-on: ubuntu-latest
# steps:
# - name: Pull the git repository
# uses: actions/checkout@v4
# - name: Install python version 3.11.6
# uses: actions/setup-python@v4
# with:
# python-version: '3.11.6'
# - 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 -s --disable-warnings
build_and_test:
environment:
name: testing
env:
PG_USERNAME: ${{secrets.PG_USERNAME}}
PG_PASSWORD: ${{secrets.PG_PASSWORD}}
PG_HOST: ${{secrets.PG_HOST}}
PG_PORT: ${{secrets.PG_PORT}}
PG_DATABASE: ${{secrets.PG_DATABASE}}
SECRET_KEY: ${{secrets.SECRET_KEY}}
ALGORITHM: ${{secrets.ALGORITHM}}
ACCESS_TOKEN_EXPIRE_MINUTES: ${{secrets.ACCESS_TOKEN_EXPIRE_MINUTES}}
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: ${{secrets.PG_PASSWORD}}
POSTGRES_DB: ${{secrets.PG_DATABASE}}_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
runs-on: ubuntu-latest
steps:
- name: Pull the git repository
uses: actions/checkout@v4
- name: Install python version 3.11.6
uses: actions/setup-python@v4
with:
python-version: '3.11.6'
- 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 -s --disable-warnings
# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# - name: Build and push Docker image
# uses: docker/build-push-action@v5
# with:
# context: .
# file: ./Dockerfile
# push: true
# tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sm-fastapi:latest
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sm-fastapi:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

deploy:
environment:
name: production
runs-on: ubuntu-latest
# needs: [build_and_test]
needs: [build_and_test]

steps:
- name: Pull the git repository
uses: actions/checkout@v4
# - name: Deploy to Heroku
# uses: akhileshns/heroku-deploy@v3.12.14
# with:
# heroku_api_key: ${{secrets.HEROKU_API_KEY}}
# heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
# heroku_email: ${{secrets.HEROKU_EMAIL}}
- name: Deploy to Heroku
uses: akhileshns/heroku-deploy@v3.12.14
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
heroku_email: ${{secrets.HEROKU_EMAIL}}

- name: Deploy to Ubuntu VM
uses: appleboy/ssh-action@v1.0.0
Expand Down

0 comments on commit 85e4f8d

Please sign in to comment.