-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (81 loc) · 2.66 KB
/
foodgram_workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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.10.5
- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd backend/foodgram/
pip install -r requirements.txt
- name: Tests with flake8
run: |
python3 -m flake8
build:
name: Build Docker image and push to Dockerhub
runs-on: ubuntu-latest
needs: tests
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 Dockerhub
uses: docker/build-push-action@v2
with:
context: ./backend/foodgram/
push: true
tags: pavelsergeev/foodgram_backend:latest
deploy:
runs-on: ubuntu-latest
needs: build
if:
contains('
refs/heads/master
refs/heads/main
', github.ref)
steps:
- name: executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_IP }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
script: |
cd foodgram
sudo docker-compose stop
sudo docker-compose rm web
echo DB_ENGINE=${{ secrets.DB_ENGINE }} > .env
echo DB_NAME=${{ secrets.DB_NAME }} >> .env
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env
echo DB_HOST=${{ secrets.DB_HOST }} >> .env
echo DB_PORT=${{ secrets.DB_PORT }} >> .env
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env
echo HOST_IP=${{ secrets.HOST_IP }} >> .env
echo HOST_URL=${{ secrets.HOST_URL }} >> .env
sudo docker rmi pavelsergeev/foodgram_backend
sudo docker image pull pavelsergeev/foodgram_backend:latest
sudo docker-compose up -d
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: ${{ github.workflow }} успешно выполнен!