diff --git a/Dockerfile b/Dockerfile index de3e87f..1861d40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ -FROM node:23-alpine - -WORKDIR /usr/src/app - -COPY package*.json ./ - -RUN npm install - +FROM node:20-alpine as builder +WORKDIR /app COPY . . +ARG VITE_APP_BACKEND_ADDRESS +ENV VITE_APP_BACKEND_ADDRESS $VITE_APP_BACKEND_ADDRESS +RUN npm install +RUN npm run build -EXPOSE 5713 - -ENTRYPOINT ["npm", "run", "dev", "--", "--port=5173", "--host=0.0.0.0"] \ No newline at end of file +FROM nginx:1.25.4-alpine-slim as prod +COPY --from=builder /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d +EXPOSE 3000 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 1821201..db01716 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { stage('Docker build') { steps { sh """ - docker build --network="host" -t ${IMAGE_NAME} . + docker build --build-arg VITE_SOCKET_URL=http://minesweeper-backend.darkbird.es --network="host" -t ${IMAGE_NAME} . """ } } diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..66f6733 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 3000; + root /usr/share/nginx/html; + index index.html; + etag on; + + location / { + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file diff --git a/src/socket.js b/src/socket.js index 71bf7b9..6d08999 100644 --- a/src/socket.js +++ b/src/socket.js @@ -1,6 +1,6 @@ import { io } from 'socket.io-client'; -const URL = 'http://minesweeper-backend.darkbird.es'; +const URL = import.meta.env.VITE_SOCKET_URL || 'http://localhost:5174'; export const socket = io(URL, { autoConnect: false, transports: ['websocket'], diff --git a/vite.config.js b/vite.config.js index a6c5ac1..c6050ce 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,11 +1,24 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' +import { defineConfig, loadEnv } from "vite"; +import process from "process"; +import react from "@vitejs/plugin-react"; -// https://vite.dev/config/ -export default defineConfig({ - plugins: [react()], - server: { - host: true +export default defineConfig(({ command, mode }) => { + const env = loadEnv(mode, process.cwd()); + return { + plugins: [react()], + server: { + port: 3000, + host: true, + watch: { + usePolling: true, + }, + esbuild: { + target: "esnext", + platform: "linux", + }, }, - base: "http://localhost:5173" -}) + define: { + VITE_SOCKET_URL: JSON.stringify(env.VITE_SOCKET_URL), + }, + }; +}); \ No newline at end of file