Skip to content

Add post endpoint

Add post endpoint #24

Workflow file for this run

name: CI/CD
on: [push]
# push:
# branches: ["develop"]
# workflow_dispatch:
jobs:
tests:
name: Tests Ruff and pytest
runs-on: ubuntu-latest
strategy:
max-parallel: 3
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Ruff check
uses: chartboost/ruff-action@v1
- name: Install Dependencies
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@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to Docker Hub
uses: docker/build-push-action@v5
with:
file: ./docker/dev.Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend: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, docker/nginx.conf"
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 }}_frontend \
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend
sudo systemctl stop nginx
sudo docker-compose -f server.docker-compose.yml --env-file .env up -d --quiet-pull