-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (71 loc) · 2.44 KB
/
main.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
name: Lesya and Moa Deploy
on:
push:
branches:
- main
jobs:
build_image_and_push_to_docker_hub:
name: Push bot Docker image to DockerHub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
with:
context: ./backend/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/lesya_and_moa:latest
setup_and_run_containers:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs:
- build_image_and_push_to_docker_hub
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Copy docker-compose.yml
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
source: "docker-compose.yml"
target: /root/lesya_and_moa
- name: Copy nginx.conf
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
source: "nginx.conf"
target: /root/lesya_and_moa
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
script: |
cd /root/lesya_and_moa
sudo docker compose down
sudo docker system prune -f
sudo docker image prune -f
sudo docker compose pull
sudo docker compose up -d
sudo docker compose exec backend python manage.py makemigrations
sudo docker compose exec backend python manage.py migrate
sudo docker compose exec backend python manage.py collectstatic
sudo docker compose exec backend cp -r /app/collected_static/. /backend_static/static/