Skip to content

Commit

Permalink
Add deploy_on_server
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Svidunovich authored and Kirill Svidunovich committed Oct 29, 2023
1 parent e69097e commit 56cc58d
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 21 deletions.
66 changes: 45 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,54 @@ jobs:
# python manage.py makemigrations &&
# pytest

build_and_push_backend_image:
name: Build backend and gateway images and push to the DockerHub
# needs:
# - backend_tests
# build_and_push_backend_image:
# name: Build backend image and push to the DockerHub
# # needs:
# # - backend_tests
# runs-on: ubuntu-latest
# steps:
# - name: Clone project to runner
# uses: actions/checkout@v3
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Login to DockerHub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}
# - name: Push backend image to the Dockerhub
# uses: docker/build-push-action@v4
# with:
# context: ./hakaton/
# push: True
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/hakaton_14_backend:latest

deploy_on_server:
name: Deploy project on server
# needs: build_and_push_backend_image
runs-on: ubuntu-latest
steps:
- name: Clone project to runner
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push backend image to the Dockerhub
uses: docker/build-push-action@v4
- name: Copy docker-compose.production.yml to server via ssh
uses: appleboy/scp-action@master
with:
context: ./hakaton/
push: True
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hakaton_14_backend:latest
- name: Push nginx image to the Dockerhub
uses: docker/build-push-action@v4
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
source: "docker-compose.production.yml"
target: "hakaton"
- name: Executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
context: ./gateway/
push: True
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hakaton_14_gateway:latest
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd hakaton
sudo docker compose -f docker-compose.production.yml pull
sudo docker compose -f docker-compose.production.yml down
sudo docker container rm backend
sudo docker image rm backend-backend
sudo docker compose -f docker-compose.production.yml up
sudo systemctl restart nginx
49 changes: 49 additions & 0 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '3.8'

volumes:
database_volume:
static_volume:
media_volume:

services:

db:
image: postgres:15-alpine
volumes:
- database_volume:/var/lib/postgresql/data/
env_file:
- .env

redis:
image: redis:7.2.1-alpine

backend:
image: thesuncatcher222/hakaton_14_backend:latest
env_file: .env
volumes:
- static_volume:/app/static
- media_volume:/app/media
depends_on:
- db
- redis

# frontend:
# build:
# context: ../frontend
# dockerfile: Dockerfile
# volumes:
# - static_volume:/app/build
# depends_on:
# - backend

nginx:
image: nginx:1.19.3-alpine
ports:
- "8000:8000"
volumes:
- ./gateway/nginx.conf:/etc/nginx/conf.d/default.conf
- static_volume:/var/html/static/
- media_volume:/var/html/media/
depends_on:
- backend
# - frontend

0 comments on commit 56cc58d

Please sign in to comment.