feat: dockerize client (nginx) and server (node) with docker-compose
This commit is contained in:
1 parent
38814668e7
commit
8da1d1edc9
12 files changed
+143
-3
No files matched your search
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="ms-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/regnum.iml" filepath="$PROJECT_DIR$/.idea/regnum.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,4 @@
|
||||
node_modules
|
||||
dist
|
||||
.env.local
|
||||
*.log
|
||||
@@ -0,0 +1,3 @@
|
||||
# En production Docker, nginx proxifie /socket.io vers le container server
|
||||
# Le client se connecte donc sur la même origine (pas de port différent)
|
||||
VITE_SERVER_URL=
|
||||
@@ -0,0 +1,19 @@
|
||||
# ── Stage 1 : build ──────────────────────────────────────────────────────────
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json* ./
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# ── Stage 2 : serve with nginx ────────────────────────────────────────────────
|
||||
FROM nginx:1.27-alpine
|
||||
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -0,0 +1,27 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Vue Router - renvoyer toutes les routes vers index.html
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Proxy WebSocket + API vers le serveur Node
|
||||
location /socket.io/ {
|
||||
proxy_pass http://server:3000;
|
||||
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;
|
||||
}
|
||||
|
||||
# Compression gzip
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/javascript application/json;
|
||||
gzip_min_length 1024;
|
||||
}
|
||||
@@ -4,9 +4,12 @@ let socket = null
|
||||
|
||||
export function useSocket() {
|
||||
if (!socket) {
|
||||
socket = io(import.meta.env.VITE_SERVER_URL || 'http://localhost:3000', {
|
||||
autoConnect: true
|
||||
})
|
||||
// En dev : pointe vers localhost:3000
|
||||
// En prod Docker : connexion sur la même origine (nginx proxifie /socket.io)
|
||||
const url = import.meta.env.VITE_SERVER_URL || (
|
||||
import.meta.env.PROD ? window.location.origin : 'http://localhost:3000'
|
||||
)
|
||||
socket = io(url, { autoConnect: true })
|
||||
}
|
||||
return socket
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
services:
|
||||
|
||||
server:
|
||||
build:
|
||||
context: ./server
|
||||
dockerfile: Dockerfile
|
||||
container_name: regnum-server
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
PORT: 3000
|
||||
expose:
|
||||
- "3000"
|
||||
networks:
|
||||
- regnum-net
|
||||
|
||||
client:
|
||||
build:
|
||||
context: ./client
|
||||
dockerfile: Dockerfile
|
||||
container_name: regnum-client
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8080:80"
|
||||
depends_on:
|
||||
- server
|
||||
networks:
|
||||
- regnum-net
|
||||
|
||||
networks:
|
||||
regnum-net:
|
||||
driver: bridge
|
||||
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
*.log
|
||||
.env
|
||||
@@ -0,0 +1,20 @@
|
||||
# ── Stage 1 : deps ───────────────────────────────────────────────────────────
|
||||
FROM node:20-alpine AS deps
|
||||
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json* ./
|
||||
RUN npm ci --omit=dev
|
||||
|
||||
# ── Stage 2 : runtime ─────────────────────────────────────────────────────────
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
|
||||
EXPOSE 3000
|
||||
CMD ["node", "src/index.js"]
|
||||
Reference in new issue
Block a user