fix code #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |