This commit is contained in:
Kseninia Mikhaylova 2024-04-26 17:16:12 +03:00
parent 9a006c1405
commit bc46210cb7
12 changed files with 210 additions and 6 deletions

30
back/Dockerfile Normal file
View File

@ -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"]

View File

@ -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

View File

@ -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')

14
back/docker-entrypoint.sh Executable file
View File

@ -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

12
back/requirements.txt Normal file
View File

@ -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"

58
docker-compose.yml Normal file
View File

@ -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

13
front/Dockerfile Normal file
View File

@ -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

View File

@ -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 () => {
<div class="header">Проекты Кустарщины</div>
<div class="main">
<div v-if="state.active_product">
<model-fbx class="model" :src="`${SERVER_URL}/${state.active_product.model3d.replace('/back', '')}`"></model-fbx>
<p>
{{ state.active_product.description }}
<model-fbx :src="`${SERVER_URL}/${state.active_product.model3d.replace('/back', '')}`"></model-fbx>
</p>
</div>
</div>
</div>

View File

@ -22,3 +22,7 @@ body {
.main {
grid-area: 2 / 2 / 6 / 6;
}
.model {
max-width: 33vw;
}

View File

@ -1 +1 @@
export const SERVER_URL = import.meta.env.VITE_SERVER_URL ?? ''
export const SERVER_URL = import.meta.env.VITE_SERVER_URL ?? 'http://localhost'

View File

@ -23,7 +23,7 @@ export const useProductStore = defineStore('product', {
}
})
interface ProductInfo {
export interface ProductInfo {
id: number
title: string
model3d: string

65
nginx/nginx.conf Normal file
View File

@ -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;
}
}
}