Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kimachinskiy committed Oct 3, 2023
1 parent 495c9b6 commit ba9e2d6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/django_cd_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
EMAIL_HOST_USER: ""
EMAIL_HOST_PASSWORD: ""
CORS_ORIGIN_WHITELIST: ${{ vars.CORS_ORIGIN_WHITELIST }}
REACT_APP_BASE_API_URL: ${{ vars.API_DEV }}

jobs:
deploy:
Expand All @@ -32,9 +33,9 @@ jobs:
- name: Docker compouse UP Django container
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
run: docker compose -f docker-compose.dev.yml exec ${{ vars.API_DEV }} python manage.py migrate --noinput
- name: Docker compouse COLLECTSTATIC
run: docker compose -f docker-compose.dev.yml exec web-dev python manage.py collectstatic --no-input
run: docker compose -f docker-compose.dev.yml exec ${{ vars.API_DEV }} python manage.py collectstatic --no-input

- name: Clean up old docker resources
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/django_cd_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Docker compouse UP Django container
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
run: docker compose -f docker-compose.dev.yml exec api_dev python manage.py migrate --noinput

- name: Docker compouse DOWN old Fronend container
run: docker compose -f FrontEnd/docker-compose.yml down -v
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/django_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ jobs:
pip install -r ./requirements.txt
- name: Run migrations
run: python manage.py migrate
- name: Run collectstatic
run: python manage.py collectstatic --no-input
- name: Run Tests
run: python manage.py test

18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
FROM python:3.9-alpine

WORKDIR /Forum
RUN mkdir -p /home/forum

RUN addgroup --system forum && adduser --system --group forum

ENV HOME=/home/forum
ENV APP_HOME=/home/forum/app
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/forum/static
RUN mkdir $APP_HOME/forum/media
WORKDIR $APP_HOME

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev

RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip3 install -r requirements.txt

COPY . /Forum
COPY . $APP_HOME

RUN chown -R forum:forum $APP_HOME

USER forum
10 changes: 5 additions & 5 deletions FrontEnd/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ server {
location /api/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://web-dev:8000/api/;
proxy_pass http://api_dev:8000/api/;
proxy_redirect off;

client_max_body_size 100M;
}

location /static/ {
autoindex on;
alias public/static;
alias /home/forum/app/forum/static/;
}

location /media/ {
autoindex on;
alias /public/media;
alias /home/forum/app/forum/medis/;
}

# Django Admin
location /admin/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://web-dev:8000/admin/;
proxy_pass http://api_dev:8000/admin/;
proxy_redirect off;
}

Expand Down
4 changes: 2 additions & 2 deletions configs/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server {

# Django API
location /api/ {
proxy_pass http://web-dev:8000/api/;
proxy_pass http://api_dev:8000/api/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
Expand All @@ -31,7 +31,7 @@ server {

# Django Admin
location /admin/ {
proxy_pass http://web-dev:8000/admin/;
proxy_pass http://api_dev:8000/admin/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
version: '3.9'

services:
web-dev:
api_dev:
build: .
container_name: web-dev
container_name: api_dev
restart: on-failure
command: gunicorn forum.wsgi:application --bind 0.0.0.0:8000
volumes:
- ./:/Forum
# - ./:/Forum
- ./static:/forum/static
# ports:
# - 8000:8000
environment:
Expand Down
6 changes: 5 additions & 1 deletion forum/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
from datetime import timedelta
from pathlib import Path
import os

from corsheaders.defaults import default_headers
from decouple import config
Expand All @@ -28,7 +29,7 @@
DEBUG = config('DEBUG')

# ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]', '0.0.0.0', '178.212.110.52', 'web-dev']
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]', '0.0.0.0', '178.212.110.52', 'api_dev']

# Application definition

Expand Down Expand Up @@ -148,6 +149,9 @@
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = os.path.join(BASE_DIR, 'media')
MEDIA_ROOT = '/var/www/forum/media/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
Expand Down

0 comments on commit ba9e2d6

Please sign in to comment.