Skip to content

Workflow file for this run

name: foodgram workflow
on: [push]
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pep8-naming flake8-broken-line flake8-return flake8-isort
pip install -r backend/requirements.txt
- name: Test with flake8
run: |
python -m flake8
build_and_push_to_docker_hub:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: tests
if: github.ref == 'refs/heads/master'
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to Docker Hub
uses: docker/build-push-action@v2
with:
context: backend/
push: true
tags: fabilya/foodgram_backend:latest
- name: Push frontend
uses: docker/build-push-action@v2
with:
context: frontend/
push: true
tags: fabilya/foodgram_frontend:latest
deploy:
if: ${{ github.ref }} == 'master'
runs-on: ubuntu-latest
needs: build_and_push_to_docker_hub
steps:
- name: pull docker image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
script: |
sudo docker pull fabilya/foodgram_backend:latest
sudo docker pull fabilya/foodgram_frontend:latest
cd infra/
sudo docker-compose stop
sudo docker-compose rm backend
- name: docker-compose up
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
script: |
cd infra/
sudo docker-compose up -d --build
send_message:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Send message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: Деплой успешно выполнен!