Skip to content

Update copy docker-compose.production.yml #46

Update copy docker-compose.production.yml

Update copy docker-compose.production.yml #46

Workflow file for this run

name: Hakaton Team 14 Workflow (main)
on:
push:
branches:
- main
jobs:
backend_tests:
name: Run tests for backend
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13.10
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
POSTGRES_DB: test_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- name: Clone project to runner
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
cd hakaton &&
python -m pip install --upgrade pip &&
pip install -r requirements.txt
- name: Run flake8 tests
run: python -m flake8
- name: Run Pytest
run: |
cd hakaton &&
cp ../.env.example .env &&
python manage.py makemigrations &&
pytest
build_and_push_backend_and_gateway_image:
name: Build backend and gateway images and push to the DockerHub
needs:
- backend_tests
runs-on: ubuntu-latest
steps:
- name: Clone project to runner
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push backend image to the Dockerhub
uses: docker/build-push-action@v4
with:
context: ./hakaton/
push: True
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hr_praktikum_backend:latest
- name: Push gateway image to the Dockerhub
uses: docker/build-push-action@v4
with:
context: ./gateway/
push: True
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hr_praktikum_gateway:latest
deploy_on_server:
name: Deploy project on server
needs: build_and_push_backend_and_gateway_image
runs-on: ubuntu-latest
steps:
- name: Clone project to runner
uses: actions/checkout@v3
- name: Copy docker-compose.yml to server via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
source: "docker-compose.production.yml"
target: "/home/hr_praktikum/"
- name: Executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd /home/hr_praktikum
sudo docker compose down
sudo rm docker-compose.yml
sudo mv docker-compose.production.yml docker-compose.yml
sudo docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/hr_praktikum_backend
sudo docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/hr_praktikum_gateway
sudo docker volume rm hr_praktikum_hr_praktikum_static_volume
sudo docker compose up -d --build
sudo service nginx restart
send_message_telegram:
name: Send message to telegram
needs: deploy_on_server
runs-on: ubuntu-latest
steps:
- name: Send message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_ME_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: Деплой "hr-praktikum backend" выполнен успешно!