Skip to content

Commit

Permalink
Added actions and docker_compose files
Browse files Browse the repository at this point in the history
  • Loading branch information
kimachinskiy committed Sep 6, 2023
1 parent 42d4ecc commit 03b33d3
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/db_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Postgres_Deploy
on: workflow_dispatch

env:
DBS: "${{ vars.DEV_DB }},${{ vars.PROD_DB }}"
POSTGRES_USER: ${{ vars.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
DATABASE: ${{ vars.POSTGRES_DB }}

PGADMIN_DEFAULT_EMAIL: ${{ vars.DEV_PGADMIN_DEFAULT_EMAIL }}
PGADMIN_DEFAULT_PASSWORD: ${{ secrets.DEV_PGADMIN_DEFAULT_PASSWORD }}

jobs:
deploy:
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker compouse DOWN old containers
run: docker compose -f docker-compose.db.yml down -v
- name: Docker compouse UP new containers
run: docker compose -f docker-compose.db.yml up -d --build
- name: Clean up old docker resources
run: |
docker container prune -f
docker image prune -f
31 changes: 31 additions & 0 deletions .github/workflows/django_cd_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Django CD DEV
on: workflow_dispatch

env:
DEBUG: ${{ vars.DEV_DEBUG }}
SECRET_KEY: ${{ secrets.DEV_SECRET_KEY }}
ENGINE: ${{ vars.ENGINE }}
HOST: ${{ vars.POSTGRES_HOST }}
PORT: ${{ vars.POSTGRES_PORT }}
DB: ${{ vars.DEV_DB }}
USER: ${{ vars.POSTGRES_USER }}
PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
DATABASE: ${{ vars.POSTGRES_DB }}

jobs:
deploy:
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker compouse DOWN old containers
run: docker compose -f docker-compose.dev.yml down -v
- name: Docker compouse UP new containers
run: docker compose -f docker-compose.dev.yml up -d --build
- name: Docker compouse MIGRATE models
run: docker compose -f docker-compose.dev.yml exec web-dev python manage.py migrate --noinput
- name: Clean up old docker resources
run: |
docker container prune -f
docker image prune -f
31 changes: 31 additions & 0 deletions .github/workflows/django_cd_prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Django CD PROD
on: workflow_dispatch

env:
DEBUG: ${{ vars.PROD_DEBUG }}
SECRET_KEY: ${{ secrets.PROD_SECRET_KEY }}
ENGINE: ${{ vars.ENGINE }}
HOST: ${{ vars.POSTGRES_HOST }}
PORT: ${{ vars.POSTGRES_PORT }}
DB: ${{ vars.PROD_DB }}
USER: ${{ vars.POSTGRES_USER }}
PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
DATABASE: ${{ vars.POSTGRES_DB }}

jobs:
deploy:
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker compouse DOWN old containers
run: docker compose -f docker-compose.prod.yml down -v
- name: Docker compouse UP new containers
run: docker compose -f docker-compose.prod.yml up -d --build
- name: Docker compouse MIGRATE models
run: docker compose -f docker-compose.prod.yml exec web-prod python manage.py migrate --noinput
- name: Clean up old docker resources
run: |
docker container prune -f
docker image prune -f
55 changes: 55 additions & 0 deletions .github/workflows/django_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Django CI
on:
workflow_dispatch
# push:
# branches: ["main"]
# pull_request:
# branches: ["main"]
env:
DEBUG: ${{ vars.DEV_DEBUG }}
SECRET_KEY: ${{ secrets.DEV_SECRET_KEY }}
ENGINE: ${{ vars.ENGINE }}
HOST: 127.0.0.1
PORT: ${{ vars.POSTGRES_PORT }}
NAME: ${{ vars.DEV_DB }}
USER: ${{ vars.POSTGRES_USER }}
PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
DB: db

jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ["3.10"]
services:
postgres:
image: postgres:14
env:
POSTGRES_DB: db
POSTGRES_USER: ${{ vars.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
pip install --upgrade pip
pip install -r ./requirements.txt
- name: Run migrations
run: python manage.py migrate
- name: Run Tests
run: python manage.py test

19 changes: 19 additions & 0 deletions .github/workflows/frontend_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Frontend_Deploy
on: workflow_dispatch


jobs:
deploy:
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker compouse DOWN old containers
run: docker compose -f FrontEnd/docker-compose.yml down -v
- name: Docker compouse UP new containers
run: docker compose -f FrontEnd/docker-compose.yml up -d --build
- name: Clean up old docker resources
run: |
docker container prune -f
docker image prune -f
18 changes: 18 additions & 0 deletions .github/workflows/nginx_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Nginx_Deploy
on: workflow_dispatch

jobs:
deploy:
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker compouse DOWN old containers
run: docker compose -f docker-compose.nginx.yml down -v
- name: Docker compouse UP new containers
run: docker compose -f docker-compose.nginx.yml up -d --build
- name: Clean up old docker resources
run: |
docker container prune -f
docker image prune -f
34 changes: 34 additions & 0 deletions docker-compose.db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.8"

services:
db:
image: postgres:14
container_name: db
restart: always
volumes:
- ./configs/postgres:/docker-entrypoint-initdb.d
- db_data:/var/lib/postgresql/data

ports:
- 5432:5432
environment:
POSTGRES_MULTIPLE_DATABASES: ${DBS}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}

pgadmin:
image: dpage/pgadmin4
restart: always
ports:
- 5050:80
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
volumes:
- pgadmin_data:/var/lib/pgadmin/data
depends_on:
- db

volumes:
db_data:
pgadmin_data:
23 changes: 23 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.9'

services:
web-dev:
build: .
container_name: web-dev
restart: on-failure
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./:/Forum
ports:
- 8001:8000
environment:
- DEBUG=${DEBUG}
- SECRET_KEY=${SECRET_KEY}
- ENGINE=${ENGINE}
- HOST=${HOST}
- PORT=${PORT}
- DB=${DB}
- USER=${USER}
- PASSWORD=${PASSWORD}
- DATABASE=${DATABASE}

9 changes: 9 additions & 0 deletions docker-compose.nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.9'

services:
nginx:
build: ./configs/nginx
container_name: nginx
ports:
- 80:80
- 81:81
23 changes: 23 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.9'

services:
web-prod:
build: .
container_name: web-prod
restart: on-failure
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./:/Forum
ports:
- 8000:8000
environment:
- DEBUG=${DEBUG}
- SECRET_KEY=${SECRET_KEY}
- ENGINE=${ENGINE}
- HOST=${HOST}
- PORT=${PORT}
- DB=${DB}
- USER=${USER}
- PASSWORD=${PASSWORD}
- DATABASE=${DATABASE}

0 comments on commit 03b33d3

Please sign in to comment.