diff --git a/docker-compose.yml b/docker-compose.yml index a5ffcd3..229b977 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,38 +1,48 @@ version: "3.9" services: - yt_postgres: + postgres: + restart: always image: postgres:15 - container_name: yt_postgres + container_name: postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"] + interval: 10s + timeout: 60s + retries: 3 + start_period: 10s volumes: - - ~/.pg/pg_data/yt:/var/lib/postgresql/data + - ../postgres:/var/lib/postgresql/data env_file: - - .env - youtube_project: - image: yt_django:latest - container_name: yt_django + - ../env + project: + build: + dockerfile: Dockerfile + context: . + image: repcofkk:latest + container_name: repcofkk depends_on: - - yt_postgres + - postgres volumes: - - static_volume:/yt/static - - media_volume:/yt/media + - static_volume:/cybercode/static + - media_volume:/cybercode/media env_file: - - .env + - ../env command: > - bash -c "./manage.py collectstatic --noinput && ./manage.py migrate && gunicorn -b 0.0.0.0:8000 soaqaz.wsgi:application" + bash -c "./manage.py collectstatic --noinput && ./manage.py migrate && gunicorn -b 0.0.0.0:8000 repcofkk.wsgi:application" nginx: build: dockerfile: ./Dockerfile context: ./docker/nginx/ - container_name: yt_nginx - image: yt_nginx + container_name: nginx + image: nginx volumes: - - static_volume:/yt/static - - media_volume:/yt/media + - static_volume:/cybercode/static + - media_volume:/cybercode/media depends_on: - - youtube_project + - project ports: - - "${NGINX_EXTERNAL_PORT}:80" + - 80:80 volumes: static_volume: diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000..780c99f --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,5 @@ +FROM nginx:latest + +RUN rm /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d +COPY proxy_params /etc/nginx diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf new file mode 100644 index 0000000..f2ee0c0 --- /dev/null +++ b/docker/nginx/nginx.conf @@ -0,0 +1,21 @@ +upstream youtube_project { + server youtube_project:8000; +} + +server { + + listen 80; + + location / { + include proxy_params; + proxy_pass http://youtube_project; + } + + location /static/ { + alias /yt/static/; + } + + location /media/ { + alias /yt/media/; + } +} \ No newline at end of file diff --git a/docker/nginx/proxy_params b/docker/nginx/proxy_params new file mode 100644 index 0000000..c6f0392 --- /dev/null +++ b/docker/nginx/proxy_params @@ -0,0 +1,7 @@ +proxy_set_header Host $http_host; +proxy_set_header X-Real-IP $remote_addr; +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +proxy_set_header X-Forwarded-Proto $scheme; +proxy_set_header X-NginX-Proxy true; +proxy_set_header Upgrade $http_upgrade; +proxy_pass_header Set-Cookie; diff --git a/repcofkk/production_settings.py b/repcofkk/production_settings.py index 8ee01ab..3db2c62 100644 --- a/repcofkk/production_settings.py +++ b/repcofkk/production_settings.py @@ -15,17 +15,14 @@ ATT_ROOT = '' ADR_LOCAL ='' DOWNLOAD_ROOT = '' -DATABASES_NAME='repcofkk_db' - - DATABASES = { 'default': { - 'HOST': '127.0.0.1', 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': DATABASES_NAME, - 'USER': 'repcofkk_user', - 'PASSWORD': 'Angstrem*45', + 'HOST': os.environ.get('POSTGRES_HOST', '127.0.0.1'), 'PORT': int(os.environ.get('POSTGRES_PORT', '5432')), + 'NAME': os.environ.get('POSTGRES_DB', 'repcofkk_db'), + 'USER': os.environ.get('POSTGRES_USER', 'repcofkk_user'), + 'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'Angstrem*45'), 'CONN_MAX_AGE':None, },