diff --git a/.github/workflows/django_cd_dev.yml b/.github/workflows/django_cd_dev.yml index a60a1a91..9fa66e9c 100644 --- a/.github/workflows/django_cd_dev.yml +++ b/.github/workflows/django_cd_dev.yml @@ -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: @@ -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: | diff --git a/.github/workflows/django_cd_prod.yml b/.github/workflows/django_cd_prod.yml index d0655224..97702f34 100644 --- a/.github/workflows/django_cd_prod.yml +++ b/.github/workflows/django_cd_prod.yml @@ -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 diff --git a/.github/workflows/django_ci.yml b/.github/workflows/django_ci.yml index 0c568394..fc8ea0d2 100644 --- a/.github/workflows/django_ci.yml +++ b/.github/workflows/django_ci.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 34102edb..2e982dfd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,19 @@ 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 @@ -13,4 +21,8 @@ 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 \ No newline at end of file diff --git a/FrontEnd/nginx.conf b/FrontEnd/nginx.conf index e4e62a9c..abc61f48 100644 --- a/FrontEnd/nginx.conf +++ b/FrontEnd/nginx.conf @@ -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; } diff --git a/configs/nginx/nginx.conf b/configs/nginx/nginx.conf index ea50f4a6..f90092b7 100644 --- a/configs/nginx/nginx.conf +++ b/configs/nginx/nginx.conf @@ -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; @@ -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; diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index e948fd32..a5471f3d 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -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: diff --git a/forum/settings.py b/forum/settings.py index 627fe7f4..55fd07c2 100644 --- a/forum/settings.py +++ b/forum/settings.py @@ -11,6 +11,7 @@ """ from datetime import timedelta from pathlib import Path +import os from corsheaders.defaults import default_headers from decouple import config @@ -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 @@ -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