diff --git a/back/Dockerfile b/back/Dockerfile new file mode 100644 index 0000000..5a28038 --- /dev/null +++ b/back/Dockerfile @@ -0,0 +1,30 @@ +# Use the official Python image with version 3.11 +FROM python:3.11 + +# Set environment variables for Python and unbuffered mode +ENV PYTHONUNBUFFERED 1 +ENV PYTHONDONTWRITEBYTECODE 1 + +# RUN addgroup --system app && adduser --system --group app + +# Set the working directory to /app +ENV APP_HOME=/app +WORKDIR $APP_HOME +# Install deb pkgs for usb +RUN apt-get update + +# Install dependencies +COPY requirements.txt /app/ +RUN pip install --upgrade pip && pip install -r requirements.txt + +# Copy the current directory contents into the container at /app +COPY . $APP_HOME/ + +# Expose the port that Gunicorn will run on +EXPOSE 8000 + +# RUN python manage.py collectstatic -y +# RUN python manage.py makemigrations +# RUN python manage.py migrate + +CMD ["bash", "./docker-entrypoint.sh"] diff --git a/back/back/settings.py b/back/back/settings.py index 4b6207b..5ca2af2 100644 --- a/back/back/settings.py +++ b/back/back/settings.py @@ -32,6 +32,8 @@ ALLOWED_HOSTS = [ "127.0.0.1:8000", "192.168.103.159", "192.168.103.159:8000", + "back", + "back:8000", ] CSRF_TRUSTED_ORIGINS = ( "http://localhost", @@ -47,6 +49,9 @@ CORS_ORIGIN_WHITELIST = [ "http://127.0.0.1", "http://192.168.103.159", "http://192.168.103.159:8000", + "http://front:4173", + "http://front:5173", + "http://back:8000", ] # Application definition diff --git a/back/back/urls.py b/back/back/urls.py index 7dda663..767bc7b 100644 --- a/back/back/urls.py +++ b/back/back/urls.py @@ -22,4 +22,4 @@ from api import views urlpatterns = [ path("admin/", admin.site.urls), path("api/products", views.products), -] + static('/files', document_root='back/files') +] + static('/files', document_root='files') diff --git a/back/docker-entrypoint.sh b/back/docker-entrypoint.sh new file mode 100755 index 0000000..2c5e94f --- /dev/null +++ b/back/docker-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Collect static files +echo "Collect static files" +python manage.py collectstatic --noinput + +# Apply database migrations +echo "Apply database migrations" +python manage.py makemigrations +python manage.py migrate + +# Start server +echo "Starting server" +python manage.py runserver 0.0.0.0:8000 \ No newline at end of file diff --git a/back/requirements.txt b/back/requirements.txt new file mode 100644 index 0000000..3f30053 --- /dev/null +++ b/back/requirements.txt @@ -0,0 +1,12 @@ +asgiref==3.8.1 ; python_version >= "3.10" and python_version < "4.0" +colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" +django-cors-headers==4.3.1 ; python_version >= "3.10" and python_version < "4.0" +django==5.0.4 ; python_version >= "3.10" and python_version < "4.0" +djangorestframework==3.15.1 ; python_version >= "3.10" and python_version < "4.0" +mslex==1.2.0 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32" +psutil==5.9.8 ; python_version >= "3.10" and python_version < "4.0" +sqlparse==0.5.0 ; python_version >= "3.10" and python_version < "4.0" +taskipy==1.12.2 ; python_version >= "3.10" and python_version < "4.0" +tomli==2.0.1 ; python_version >= "3.10" and python_version < "4.0" +typing-extensions==4.11.0 ; python_version >= "3.10" and python_version < "3.11" +tzdata==2024.1 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..57a5953 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,58 @@ +services: + back: + build: + context: ./back + dockerfile: Dockerfile + container_name: back + restart: always + expose: + - "8000" + environment: + - HOST_IP_ADDR=$HOST_IP_ADDR + healthcheck: + test: curl -f http://localhost:8000/api/products || exit 1 + interval: 5s + timeout: 3s + retries: 10 + start_interval: 10s + privileged: true + volumes: + - ./.env:/app/.env + networks: + - network + + front: + build: + context: ./front + dockerfile: Dockerfile + container_name: front + restart: always + expose: + - "4173" + depends_on: + back: + condition: service_healthy + networks: + - network + + nginx: + image: nginx:1.25 + container_name: nginx + restart: always + ports: + - "8098:80" + depends_on: + back: + condition: service_healthy + links: + - back:back + - front:front + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./nginx/conf.d:/etc/nginx/conf.d + networks: + - network + +networks: + network: + driver: bridge diff --git a/front/Dockerfile b/front/Dockerfile new file mode 100644 index 0000000..8af2174 --- /dev/null +++ b/front/Dockerfile @@ -0,0 +1,13 @@ +FROM node:21 + +RUN mkdir -p /src + +COPY package.json src/package.json + +WORKDIR /src + +RUN npm install + +COPY . /src +RUN npm run build +CMD npm run preview -- --host \ No newline at end of file diff --git a/front/src/App.vue b/front/src/App.vue index ca5ee27..6bb766d 100644 --- a/front/src/App.vue +++ b/front/src/App.vue @@ -2,10 +2,11 @@ import { onMounted, reactive } from 'vue'; import { ModelFbx } from 'vue-3d-model'; import { useProductStore } from './stores/product'; +import type { ProductInfo } from './stores/product'; import { SERVER_URL } from './constants' type StateType = { - active_product?: number + active_product?: ProductInfo } const products = useProductStore() @@ -37,8 +38,10 @@ onMounted(async () => {
Проекты Кустарщины
- {{ state.active_product.description }} - + +

+ {{ state.active_product.description }} +

diff --git a/front/src/assets/main.scss b/front/src/assets/main.scss index 8a2e2f5..1db9042 100644 --- a/front/src/assets/main.scss +++ b/front/src/assets/main.scss @@ -21,4 +21,8 @@ body { .main { grid-area: 2 / 2 / 6 / 6; +} + +.model { + max-width: 33vw; } \ No newline at end of file diff --git a/front/src/constants.ts b/front/src/constants.ts index fd03d9f..57cc0b1 100644 --- a/front/src/constants.ts +++ b/front/src/constants.ts @@ -1 +1 @@ -export const SERVER_URL = import.meta.env.VITE_SERVER_URL ?? '' \ No newline at end of file +export const SERVER_URL = import.meta.env.VITE_SERVER_URL ?? 'http://localhost' \ No newline at end of file diff --git a/front/src/stores/product.ts b/front/src/stores/product.ts index b88842c..1038d68 100644 --- a/front/src/stores/product.ts +++ b/front/src/stores/product.ts @@ -23,7 +23,7 @@ export const useProductStore = defineStore('product', { } }) -interface ProductInfo { +export interface ProductInfo { id: number title: string model3d: string diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..743893f --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,65 @@ +user root; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } + + upstream django { + server back:8000; + keepalive 16; + } + + server { + listen 80; + server_name localhost; + + location / { + proxy_pass http://front:4173; + proxy_set_header Host $host:$server_port; + 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; + } + location /api/ { + proxy_pass http://back:8000/api/; + } + location /files/ { + proxy_pass http://back:8000/files/; + } + + location /admin/ { + proxy_pass http://back:8000/admin/; + } + location /static/admin/ { + proxy_pass http://back:8000/static/admin/; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + } +}