Skip to content

Commit

Permalink
Deploy (#40)
Browse files Browse the repository at this point in the history
* feat: add caching

* feat: fix docker-compose

* fix command

* fix shit

* fix

* image fix
  • Loading branch information
rasulov1337 authored Dec 16, 2024
1 parent e7ed717 commit b946587
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 95 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
.idea/
precompiled-templates.js
/images/
/nginx/ssl/
/nginx/ssl/
dist/
25 changes: 25 additions & 0 deletions docker-compose-debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
frontend:
image: node:20
working_dir: /app
volumes:
- ./:/app
- /app/node_modules
ports:
- '5173:5173' # For local development!
command: >
sh -c "npm i && npm run start"
nginx:
image: nginx:latest
volumes:
- ./nginx/:/etc/nginx/
ports:
- '80:80'
- '443:443'
depends_on:
- frontend
extra_hosts:
- 'host.docker.internal:host-gateway'
command: >
sh -c "chmod +x /etc/nginx/generate-certs.sh && sh /etc/nginx/generate-certs.sh"
51 changes: 26 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
services:
frontend:
image: node:20
working_dir: /app
volumes:
- ./:/app
- /app/node_modules
ports:
- '5173:5173' # For local development!
command: >
sh -c "npm i && npm run start"
nginx:
image: nginx:latest
volumes:
- ./nginx/:/etc/nginx/
ports:
- '80:80'
- '443:443'
depends_on:
- frontend
extra_hosts:
- 'host.docker.internal:host-gateway'
command: >
sh -c "chmod +x /etc/nginx/generate-certs.sh && sh /etc/nginx/generate-certs.sh"
version: '3.8'

services:
frontend:
image: node:20
working_dir: /app
volumes:
- .:/app
- /app/node_modules
command: >
sh -c "npm i && npm run start"
nginx:
image: nginx:latest
volumes:
- ./nginx/:/etc/nginx/
# - ./app:/app/ # изменено на правильный путь
ports:
- '80:80'
- '443:443'
depends_on:
- frontend
extra_hosts:
- 'host.docker.internal:host-gateway'
command: >
sh /etc/nginx/generate-certs.sh
16 changes: 9 additions & 7 deletions nginx/generate-certs.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash

# Установка OpenSSL, если он не установлен
if ! command -v openssl &> /dev/null; then
echo "OpenSSL не найден. Устанавливаем..."
apt update && apt install -y openssl
else
echo "OpenSSL уже установлен."
fi
# # Установка OpenSSL, если он не установлен
# if ! command -v openssl &> /dev/null; then
# echo "OpenSSL не найден. Устанавливаем..."
# apt update && apt install -y openssl
# else
# echo "OpenSSL уже установлен."
# fi

ls /app/ -la

# Папка для хранения сертификатов
CERT_DIR="/etc/nginx/ssl"
Expand Down
62 changes: 62 additions & 0 deletions nginx/nginx-dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
events { }

http {
server {
listen 80;
server_name localhost;

# Перенаправление всех HTTP-запросов на HTTPS
return 301 http://$host$request_uri;
}

server {
listen 443 ssl http2;
server_name localhost;

ssl_certificate /etc/nginx/ssl/pootnick.crt;
ssl_certificate_key /etc/nginx/ssl/pootnick.key;
ssl_protocols TLSv1.2 TLSv1.3;

location /api/ {
proxy_pass http://host.docker.internal:8008/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;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /websocket/ {
proxy_pass https://host.docker.internal:8008/api/messages/setconn;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off;
proxy_read_timeout 86400;
}

location /images/default.png {
proxy_pass http://frontend:5173/default.png;
}

location /images/ {
proxy_pass http://host.docker.internal:9000; # Minio
proxy_set_header Host $host;
}

location /cities/ {
proxy_pass http://host.docker.internal:9000; # Minio
proxy_set_header Host $host;
}

location / {
proxy_pass http://frontend:5173; # Vite
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;
}
}
}
129 changes: 67 additions & 62 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,62 +1,67 @@
events { }

http {
server {
listen 80;
server_name localhost;

# Перенаправление всех HTTP-запросов на HTTPS
return 301 http://$host$request_uri;
}

server {
listen 443 ssl http2;
server_name localhost;

ssl_certificate /etc/nginx/ssl/pootnick.crt;
ssl_certificate_key /etc/nginx/ssl/pootnick.key;
ssl_protocols TLSv1.2 TLSv1.3;

location /api/ {
proxy_pass http://host.docker.internal:8008/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;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /websocket/ {
proxy_pass https://host.docker.internal:8008/api/messages/setconn;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off;
proxy_read_timeout 86400;
}

location /images/default.png {
proxy_pass http://frontend:5173/default.png;
}

location /images/ {
proxy_pass http://host.docker.internal:9000; # Minio
proxy_set_header Host $host;
}

location /cities/ {
proxy_pass http://host.docker.internal:9000; # Minio
proxy_set_header Host $host;
}

location / {
proxy_pass http://frontend:5173; # Vite
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;
}
}
}
events { }

http {
server {
listen 80;
server_name localhost;

# Перенаправление всех HTTP-запросов на HTTPS
return 301 http://$host$request_uri;
}

server {
listen 443 ssl http2;
server_name localhost;

ssl_certificate /etc/nginx/ssl/pootnick.crt;
ssl_certificate_key /etc/nginx/ssl/pootnick.key;
ssl_protocols TLSv1.2 TLSv1.3;

location /api/ {
proxy_pass http://host.docker.internal:8008/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;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /websocket/ {
proxy_pass https://host.docker.internal:8008/api/messages/setconn;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off;
proxy_read_timeout 86400;
}

location /images/ {
proxy_pass http://host.docker.internal:9000; # Minio
expires 30d;
add_header Cache-Control "public"; # public = browsers + CDN
proxy_set_header Host $host;
}

location /cities/ {
proxy_pass http://host.docker.internal:9000; # Minio
proxy_set_header Host $host;
}

# location ~* \.(css|jpg|png|jpeg)$ {
# root /app/dist/;
# expires 30d;
# proxy_pass http://frontend:5173; # Vite
# add_header Cache-Control "public"; # public = browsers + CDN
# }

location / {
proxy_pass http://frontend:5173; # Vite
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;
}
}
}

0 comments on commit b946587

Please sign in to comment.