Skip to content

adjusted

adjusted #3

Workflow file for this run

name: Build and Deploy Code
# on: [push, pull_request]
on:
push:
# branches:
# - ""
# pull_request:
# branches:
# - "main"
jobs:
build:
environment:
name: Testing
env:
DATABASE_HOSTNAME: ${{secrets.DATABASE_HOSTNAME}}
DATABASE_PORT: ${{secrets.DATABASE_PORT}}
DATABASE_PASSWORD: ${{secrets.DATABASE_PASSWORD}}
DATABASE_NAME: ${{secrets.DATABASE_NAME}}
DATABASE_USERNAME: ${{secrets.DATABASE_USERNAME}}
SECRET_KEY: ${{secrets.SECRET_KEY}}
ALGORITHM: ${{secrets.ALGORITHM}}
TOKEN_EXPIRE_MIN: ${{secrets.TOKEN_EXPIRE_MIN}}
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: ${{secrets.DATABASE_PASSWORD}}
POSTGRES_DB: ${{secrets.DATABASE_NAME}}-test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-20.04
steps:
- name: Pulling git repo
uses: actions/checkout@v2
- name: Install python version 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10.11"
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install all dependencies
run: pip install -r requirements.txt
- name: Test with pytest
run: |
pytest
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{secrets.DOCKER_HUB_USERNAME}}
password: ${{secrets.DOCKER_HUB_ACCESS_TOKEN}}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{steps.buildx.outputs.name}}
push: true
tags: ${{secrets.DOCKER_HUB_USERNAME}}/fast-api:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{steps.docker_build.outputs.digest}}
deploy:
runs-on: ubuntu-20.04
needs: [build]
environment:
name: Production
steps:
- name: Pulling git repo
uses: actions/checkout@v2
# - name: Deploying to Heroku
# uses: akhileshns/[email protected]
# with:
# heroku_api_key: ${{secrets.HEROKU_API_KEY}}
# heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
# heroku_email: ${{secrets.HEROKU_EMAIL}}
- name: Deploy to ubuntu server
uses: appleboy/ssh-action@master
with:
host: ${{secrets.HOST}}
username: ${{secrets.USERNAME}}
password: ${{secrets.PASSWORD}}
script: |
cd fast-api/src
git pull
echo ${{secrets.PASSWORD}} | sudo -S systemctl restart fast-api