Skip to content

changed cd

changed cd #87

Workflow file for this run

name: Workflow For Build and Deploy
on:
push:
branches:
- develop
jobs:
build_backend_and_push_to_docker_hub:
name: Push docker image of backend to DockerHub
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Set up Docker Buildbox
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 Docker
uses: docker/build-push-action@v4
with:
context: .
file: ./backend/Dockerfile
push: true
tags: blakkheart/diary_backend:latest
build_gateway_and_push_to_docker_hub:
name: Push docker image of gateway to DockerHub
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Set up Docker Buildbox
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 Docker
uses: docker/build-push-action@v4
with:
context: ./infra/
push: true
tags: blakkheart/diary_gateway:latest
deploy:
name: Deploy project on server
runs-on: ubuntu-latest
needs:
- build_backend_and_push_to_docker_hub
- build_gateway_and_push_to_docker_hub
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Copy docker-compose.yml via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
source: "docker-compose.production.yml"
target: "/home/${{ secrets.USER }}/diary-training"
- name: Executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
script: |
cd /home/${{ secrets.USER }}/diary-training/
sudo docker compose -f docker-compose.production.yml pull
sudo docker compose -f docker-compose.production.yml down
sudo docker compose -f docker-compose.production.yml up -d
sudo docker compose -f docker-compose.production.yml exec backend python manage.py collectstatic
sudo docker compose -f docker-compose.production.yml exec backend python manage.py migrate
sudo docker compose -f docker-compose.production.yml exec backend python manage.py loaddata fixture/achievements_fixture.json