fix docker file
This commit is contained in:
+93
-50
@@ -204,34 +204,6 @@ EXPOSE 80
|
|||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# --- 2. Nginx конфиг (Базовый HTTP) ---
|
|
||||||
# Этот конфиг будет использоваться внутри контейнера
|
|
||||||
cat > client/nginx-client.conf <<EOF
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name localhost;
|
|
||||||
root /usr/share/nginx/html;
|
|
||||||
index index.html;
|
|
||||||
|
|
||||||
# Frontend Routing (SPA)
|
|
||||||
location / {
|
|
||||||
try_files \$uri \$uri/ /index.html;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Proxy API requests to Backend Container
|
|
||||||
location /api/ {
|
|
||||||
proxy_pass http://backend:3000/api/;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade \$http_upgrade;
|
|
||||||
proxy_set_header Connection 'upgrade';
|
|
||||||
proxy_set_header Host \$host;
|
|
||||||
proxy_cache_bypass \$http_upgrade;
|
|
||||||
proxy_set_header X-Real-IP \$remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# --- 3. Dockerfile для Server ---
|
# --- 3. Dockerfile для Server ---
|
||||||
cat > server/Dockerfile <<EOF
|
cat > server/Dockerfile <<EOF
|
||||||
FROM node:24-alpine AS builder
|
FROM node:24-alpine AS builder
|
||||||
@@ -251,14 +223,38 @@ EXPOSE 3000
|
|||||||
CMD ["node", "dist/main"]
|
CMD ["node", "dist/main"]
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# --- 4. docker-compose.yml ---
|
if [[ "$USE_SSL" == "true" ]]; then
|
||||||
log "Генерация docker-compose.yml..."
|
# === ВАРИАНТ С SSL ===
|
||||||
|
|
||||||
|
# 1. Nginx Config
|
||||||
|
cat > client/nginx-client.conf <<EOF
|
||||||
|
server {
|
||||||
|
listen $FRONTEND_PORT ssl;
|
||||||
|
server_name $UI_HOST;
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
client_max_body_size 50M;
|
||||||
|
|
||||||
|
ssl_certificate /etc/nginx/certs/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/nginx/certs/privkey.pem;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files \$uri \$uri/ /index.html;
|
||||||
|
}
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://backend:3000/api/;
|
||||||
|
proxy_set_header Host \$host;
|
||||||
|
proxy_set_header X-Real-IP \$remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 2. Docker Compose
|
||||||
cat > docker-compose.yml <<EOF
|
cat > docker-compose.yml <<EOF
|
||||||
services:
|
services:
|
||||||
# --- Database ---
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:18-alpine
|
image: postgres:16-alpine
|
||||||
container_name: 3dp-postgres
|
container_name: 3dp-postgres
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
@@ -275,7 +271,6 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
# --- Backend (NestJS) ---
|
|
||||||
backend:
|
backend:
|
||||||
build: ./server
|
build: ./server
|
||||||
container_name: 3dp-backend
|
container_name: 3dp-backend
|
||||||
@@ -294,7 +289,6 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
|
|
||||||
# --- Frontend (Nginx + React) ---
|
|
||||||
frontend:
|
frontend:
|
||||||
build: ./client
|
build: ./client
|
||||||
container_name: 3dp-frontend
|
container_name: 3dp-frontend
|
||||||
@@ -302,46 +296,95 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
ports:
|
ports:
|
||||||
- "${FINAL_PORT}:${FINAL_PORT}"
|
- "${FRONTEND_PORT}:${FRONTEND_PORT}"
|
||||||
|
volumes:
|
||||||
|
- ${CERT_PATH}:/etc/nginx/certs/fullchain.pem:ro
|
||||||
|
- ${KEY_PATH}:/etc/nginx/certs/privkey.pem:ro
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg_data:
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Добавляем SSL конфигурацию (ЕСЛИ ВКЛЮЧЕНО)
|
else
|
||||||
if [[ "$USE_SSL" == "true" ]]; then
|
# === ВАРИАНТ БЕЗ SSL (HTTP) ===
|
||||||
# 1. Перезаписываем nginx конфиг для SSL
|
|
||||||
|
# 1. Nginx Config
|
||||||
cat > client/nginx-client.conf <<EOF
|
cat > client/nginx-client.conf <<EOF
|
||||||
server {
|
server {
|
||||||
listen $FINAL_PORT ssl;
|
listen 80;
|
||||||
server_name $UI_HOST;
|
server_name localhost;
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
client_max_body_size 50M;
|
||||||
ssl_certificate /etc/nginx/certs/fullchain.pem;
|
|
||||||
ssl_certificate_key /etc/nginx/certs/privkey.pem;
|
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
try_files \$uri \$uri/ /index.html;
|
try_files \$uri \$uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://backend:3000/api/;
|
proxy_pass http://backend:3000/api/;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade \$http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
proxy_set_header Host \$host;
|
proxy_set_header Host \$host;
|
||||||
|
proxy_cache_bypass \$http_upgrade;
|
||||||
proxy_set_header X-Real-IP \$remote_addr;
|
proxy_set_header X-Real-IP \$remote_addr;
|
||||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# 2. Добавляем volumes с сертификатами в docker-compose
|
# 2. Docker Compose
|
||||||
# Используем sed для вставки volumes после ports frontend-сервиса
|
cat > docker-compose.yml <<EOF
|
||||||
sed -i "/services:/a \ \ \ \ volumes:\n - $CERT_PATH:/etc/nginx/certs/fullchain.pem:ro\n - $KEY_PATH:/etc/nginx/certs/privkey.pem:ro" docker-compose.yml
|
services:
|
||||||
fi
|
postgres:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
container_name: 3dp-postgres
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: admin
|
||||||
|
POSTGRES_PASSWORD: ${DB_PASS}
|
||||||
|
POSTGRES_DB: 3dp_manager
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- pg_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U admin -d 3dp_manager"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
# Добавляем volume для БД в конец файла
|
backend:
|
||||||
cat >> docker-compose.yml <<EOF
|
build: ./server
|
||||||
|
container_name: 3dp-backend
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
DATABASE_HOST: postgres
|
||||||
|
DATABASE_PORT: 5432
|
||||||
|
DATABASE_USER: admin
|
||||||
|
DATABASE_PASSWORD: ${DB_PASS}
|
||||||
|
DATABASE_NAME: 3dp_manager
|
||||||
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
|
PORT: 3000
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
build: ./client
|
||||||
|
container_name: 3dp-frontend
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- backend
|
||||||
|
ports:
|
||||||
|
- "${FRONTEND_PORT}:${FRONTEND_PORT}"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pg_data:
|
pg_data:
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
#################################
|
#################################
|
||||||
# ЗАПУСК
|
# ЗАПУСК
|
||||||
|
|||||||
Reference in New Issue
Block a user