New vite config and dockerfile for prod
All checks were successful
gitea/minesweeper-frontend/pipeline/head This commit looks good

This commit is contained in:
Jose134 2025-01-22 00:47:24 +01:00
parent 22ac242c29
commit bd6fdf2a9e
5 changed files with 50 additions and 22 deletions

View File

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

2
Jenkinsfile vendored
View File

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

15
nginx.conf Normal file
View File

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

View File

@ -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'],

View File

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