Skip to content

Commit

Permalink
Merge pull request #3 from hrspace-request-builder/feature/ci_cd
Browse files Browse the repository at this point in the history
Feature/ci cd
  • Loading branch information
ErendzhenovBair authored Mar 18, 2024
2 parents 98400de + 2af901e commit 4756654
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 6 deletions.
85 changes: 81 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Test Suite

name: CI/CD
on:
push:
branches: ["main", "develop"]
branches: ["develop"]
pull_request:
branches: ["main", "develop"]
branches: ["develop"]
workflow_dispatch:

jobs:
Expand All @@ -29,3 +28,81 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements/test.requirements.txt
build_and_push_to_docker_hub:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: tests
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to Docker Hub
uses: docker/build-push-action@v4
with:
file: ./docker/dev.Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}:latest

server_environment:
runs-on: ubuntu-latest
needs: build_and_push_to_docker_hub
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Create project directory and .env-file
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
sudo mkdir -p ${{ secrets.PROJECT_NAME }}
sudo chmod 777 ${{ secrets.PROJECT_NAME }}
sudo cat > ${{ secrets.PROJECT_NAME }}/.env << _EOF_
APP_TITLE=${{ secrets.APP_TITLE }}
APP_DESCRIPTION=${{ secrets.APP_DESCRIPTION }}
SECRET_KEY=${{ secrets.SECRET_KEY }}
POSTGRES_USER=${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
DB_HOST=${{ secrets.DB_HOST }}
DB_PORT=${{ secrets.DB_PORT }}
POSTGRES_DB=${{ secrets.POSTGRES_DB }}
PROJECT_NAME=${{ secrets.PROJECT_NAME }}
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
_EOF_
- name: copy infra files via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: "docker/server.docker-compose.yml"
target: ${{ secrets.PROJECT_NAME }}
overwrite: true
strip_components: 1

deploy:
runs-on: ubuntu-latest
needs: server_environment
steps:
- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd ${{ secrets.PROJECT_NAME }}
sudo docker-compose -f server.docker-compose.yml --env-file .env down
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
sudo systemctl stop nginx
sudo docker-compose -f server.docker-compose.yml --env-file .env up -d --quiet-pull
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ipython_config.py
fastapi.db
test.db
_main.yml
_server*
_test*
=GARB=
infra/local/admin
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# hrspace-request-builder-backend
[![CI/CD](https://github.com/hrspace-request-builder/hrspace-request-builder-backend/actions/workflows/main.yml/badge.svg)](https://github.com/hrspace-request-builder/hrspace-request-builder-backend/actions/workflows/main.yml)


Backend for hrspace-requst-builder
Проект развернут на удаленном сервере:
- Swagger доступен по адресу http://185.221.162.231:8000/docs
- админ панель доступна по адресу http://185.221.162.231:8000/admin

## Установка приложения:

Expand Down
27 changes: 27 additions & 0 deletions docker/server.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'
services:

db:
image: postgres:15.1-alpine
restart: always
volumes:
- db_data:/var/lib/postgresql/data/
environment:
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
ports:
- $DB_PORT:$DB_PORT

backend:
image: "${DOCKERHUB_USERNAME}/${PROJECT_NAME}"
# command: bash -c "alembic upgrade head && uvicorn app.main:app"
command: bash -c "uvicorn app.main:app --host=0.0.0.0"
restart: always
depends_on:
- db
ports:
- 8000:8000
env_file:
- ./.env

volumes:
db_data:

0 comments on commit 4756654

Please sign in to comment.