diff --git a/.dockerignore b/.dockerignore index d992b0f..d571957 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ -node_modules -.git \ No newline at end of file +*/node_modules +.git +*/dist \ No newline at end of file diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..dd77845 --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,14 @@ +# Build stage +FROM node as build-stage +WORKDIR /app +COPY app/package.json yarn.lock ./ +RUN yarn install +COPY app . +RUN yarn build + +# Production stage +FROM nginx:stable-alpine as production-stage +COPY --from=build-stage /app/dist /usr/share/nginx/html +COPY deployment/nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/app/src/utils/api.js b/app/src/utils/api.js index f598681..67ad944 100644 --- a/app/src/utils/api.js +++ b/app/src/utils/api.js @@ -1,7 +1,7 @@ import axios from 'axios' const api = axios.create({ - baseURL: '/api', + baseURL: '/api/v1', }) export default api diff --git a/app/vite.config.js b/app/vite.config.js index 2683207..133a5f9 100644 --- a/app/vite.config.js +++ b/app/vite.config.js @@ -7,9 +7,8 @@ export default defineConfig({ server: { proxy: { '/api': { - target: `${process.env.API_TARGET || 'http://localhost:3000'}/api/v1`, + target: process.env.API_TARGET || 'http://localhost:3000', changeOrigin: true, - rewrite: (path) => path.replace(/^\/api/, ''), }, '/socket.io': { target: process.env.API_TARGET || 'ws://localhost:3000', diff --git a/deployment/nginx.conf b/deployment/nginx.conf new file mode 100644 index 0000000..7a58af6 --- /dev/null +++ b/deployment/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + location /api/ { + proxy_pass http://backend:3000; + } + + location /socket.io/ { + proxy_pass http://backend:3000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + } +} diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 4644ef6..b04ebb8 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,11 +1,20 @@ version: '3' services: app: + image: lancatlin/linux-odyssey:app + build: + context: . + dockerfile: app/Dockerfile + networks: + internal: + ports: + - 8080:80 + backend: image: lancatlin/linux-odyssey restart: on-failure build: context: . - dockerfile: Dockerfile + dockerfile: server/Dockerfile networks: - internal - players