From 5fd64aee54c6a3e1573d69e3cb2588923c5e534c Mon Sep 17 00:00:00 2001 From: BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> Date: Thu, 11 Jan 2024 08:52:55 +0100 Subject: [PATCH 1/7] dockerize backend --- Dockerfile | 11 ++++++++++ docker-compose.yml | 7 +++++++ pom.xml | 2 +- ...ipExampleServer.java => JChessServer.java} | 20 ++++++++++++------- .../server/api/servlet/GameCreateServlet.java | 4 ++-- .../server/api/servlet/ThemesServlet.java | 4 ++-- 6 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml rename src/main/java/jchess/server/{WipExampleServer.java => JChessServer.java} (87%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f097a49 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM maven:3-amazoncorretto-21 as build +COPY src/main/java src/main/java +COPY src/main/resources src/main/resources +COPY src/test src/test +COPY pom.xml pom.xml +RUN mvn package -f pom.xml + +FROM amazoncorretto:21 +COPY --from=build /target/jchess.jar /app/jchess.jar +COPY --from=build /target/lib /app/lib +CMD ["java", "-jar", "/app/jchess.jar"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b645cc9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +services: + app: + build: . + ports: + - "8880:8880" + environment: + - IS_DOCKER=true diff --git a/pom.xml b/pom.xml index 049ffbb..5c2974f 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ true lib/ - jchess.server.WipExampleServer + jchess.server.JChessServer diff --git a/src/main/java/jchess/server/WipExampleServer.java b/src/main/java/jchess/server/JChessServer.java similarity index 87% rename from src/main/java/jchess/server/WipExampleServer.java rename to src/main/java/jchess/server/JChessServer.java index a879096..7930e44 100644 --- a/src/main/java/jchess/server/WipExampleServer.java +++ b/src/main/java/jchess/server/JChessServer.java @@ -19,25 +19,27 @@ import jchess.server.api.servlet.GameModesServlet; import jchess.server.api.servlet.ThemesServlet; import jchess.server.api.socket.BoardUpdateWebsocket; -import jchess.server.api.socket.PieceSelectionWebsocket; import jchess.server.api.socket.ChatWebsocket; +import jchess.server.api.socket.PieceSelectionWebsocket; import jchess.server.session.SessionManager; import jchess.server.session.SessionMgrController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.InetAddress; import java.net.URISyntaxException; +import java.net.UnknownHostException; import java.util.concurrent.TimeUnit; -public class WipExampleServer { - private static final Logger logger = LoggerFactory.getLogger(WipExampleServer.class); +public class JChessServer { + private static final Logger logger = LoggerFactory.getLogger(JChessServer.class); public static final String resourcePrefix = "resources"; public static BoardUpdateWebsocket boardUpdateWebsocket; public static PieceSelectionWebsocket pieceSelectionWebsocket; - public static void main(String[] args) throws ServletException, URISyntaxException { + public static void main(String[] args) throws ServletException, URISyntaxException, UnknownHostException { boardUpdateWebsocket = new BoardUpdateWebsocket(); pieceSelectionWebsocket = new PieceSelectionWebsocket(); ChatWebsocket chatWebsocket = new ChatWebsocket(); @@ -45,10 +47,10 @@ public static void main(String[] args) throws ServletException, URISyntaxExcepti SessionMgrController.registerSessionManager(GameSessionData.class, 10, TimeUnit.MINUTES); SessionMgrController.startHeartbeat(1, TimeUnit.MINUTES); - ClassPathResourceManager resourceManager = new ClassPathResourceManager(WipExampleServer.class.getClassLoader()); + ClassPathResourceManager resourceManager = new ClassPathResourceManager(JChessServer.class.getClassLoader()); DeploymentInfo deployment = Servlets.deployment() - .setClassLoader(WipExampleServer.class.getClassLoader()) + .setClassLoader(JChessServer.class.getClassLoader()) .setContextPath("") .setDeploymentName("WipChessServer") .addServlet(Servlets.servlet("GameCreate", GameCreateServlet.class).addMapping("/api/game/create")) @@ -66,8 +68,12 @@ public static void main(String[] args) throws ServletException, URISyntaxExcepti .addPrefixPath("/api/pieceSelection", Handlers.websocket(pieceSelectionWebsocket)) .addPrefixPath("/api/chat", Handlers.websocket(chatWebsocket)); + final String isDocker = System.getenv("IS_DOCKER"); + final String address = (isDocker == null || isDocker.isEmpty()) ? "localhost" : InetAddress.getLocalHost().getHostAddress(); + final int port = 8880; + logger.info("Listening on {}:{}", address, port); Undertow server = Undertow.builder() - .addHttpListener(8880, "127.0.0.1") + .addHttpListener(port, address) .setHandler(pathHandler) .build(); server.start(); diff --git a/src/main/java/jchess/server/api/servlet/GameCreateServlet.java b/src/main/java/jchess/server/api/servlet/GameCreateServlet.java index 09425f9..f2dac70 100644 --- a/src/main/java/jchess/server/api/servlet/GameCreateServlet.java +++ b/src/main/java/jchess/server/api/servlet/GameCreateServlet.java @@ -6,7 +6,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jchess.gamemode.GameMode; -import jchess.server.WipExampleServer; +import jchess.server.JChessServer; import jchess.server.util.HttpUtils; import jchess.server.util.JsonUtils; import org.slf4j.Logger; @@ -32,7 +32,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I final String sessionId; try { - sessionId = WipExampleServer.startNewGame(gameMode); + sessionId = JChessServer.startNewGame(gameMode); } catch (Exception e) { logger.warn("Failed to start new game.", e); HttpUtils.error(resp, StatusCodes.INTERNAL_SERVER_ERROR, "Failed to start new game. Exception: " + e.getMessage()); diff --git a/src/main/java/jchess/server/api/servlet/ThemesServlet.java b/src/main/java/jchess/server/api/servlet/ThemesServlet.java index 513e85b..0fdb8f3 100644 --- a/src/main/java/jchess/server/api/servlet/ThemesServlet.java +++ b/src/main/java/jchess/server/api/servlet/ThemesServlet.java @@ -9,7 +9,7 @@ import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import jchess.server.WipExampleServer; +import jchess.server.JChessServer; import jchess.server.adapter.Vector2IAdapter; import jchess.server.util.JsonUtils; import org.slf4j.Logger; @@ -26,7 +26,7 @@ public class ThemesServlet extends HttpServlet { private static final Logger logger = LoggerFactory.getLogger(ThemesServlet.class); private static final Map> themeMap = new HashMap<>(); private static final Map themeTileInfoMap = new HashMap<>(); - private static final String resourcePrefix = WipExampleServer.resourcePrefix; + private static final String resourcePrefix = JChessServer.resourcePrefix; public ThemesServlet() { try { From 1172495a7ffa419118bc48835113b55f80931677 Mon Sep 17 00:00:00 2001 From: BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> Date: Thu, 11 Jan 2024 08:58:21 +0100 Subject: [PATCH 2/7] rename backend app in docker-compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index b645cc9..ca803ac 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ services: - app: + backend: build: . ports: - "8880:8880" From b7308fcd048b4d31d03f8dd4f33804c7531ed7ad Mon Sep 17 00:00:00 2001 From: BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:04:03 +0100 Subject: [PATCH 3/7] remove clientUri, use relative Url instead --- src/main/jchess-web/.env.example | 3 +-- .../GameComponent/GameComponent.tsx | 7 +++---- .../GameComponent/PieceSelectionComponent.tsx | 4 +--- .../jchess-web/services/rest_api_service.tsx | 21 +++++++------------ src/main/jchess-web/utils/config.ts | 8 ------- 5 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/main/jchess-web/.env.example b/src/main/jchess-web/.env.example index 023aadf..76287dc 100644 --- a/src/main/jchess-web/.env.example +++ b/src/main/jchess-web/.env.example @@ -1,5 +1,4 @@ NEXT_PUBLIC_JCHESS_UNDERTOW_SERVER_URI=http://127.0.0.1:8880 NEXT_PUBLIC_JCHESS_SOCKET_URI=ws://localhost:8880 -NEXT_PUBLIC_CLIENT_URI=http://localhost:3000 NEXT_PUBLIC_BOARD_WITH_COORDINATES=false -NEXT_PUBLIC_LOCAL_STORAGE=false \ No newline at end of file +NEXT_PUBLIC_LOCAL_STORAGE=false diff --git a/src/main/jchess-web/components/GameComponent/GameComponent.tsx b/src/main/jchess-web/components/GameComponent/GameComponent.tsx index c0b1c2b..36f7bff 100644 --- a/src/main/jchess-web/components/GameComponent/GameComponent.tsx +++ b/src/main/jchess-web/components/GameComponent/GameComponent.tsx @@ -116,7 +116,6 @@ export default function GameComponment({ sessionId }: { sessionId: string }) { translationString: string ) { const canvas: JSX.Element[] = []; - const serverUri = Config.clientUri + "/api/"; const offsetWidthFromCanvasRef = canvasRef.current?.offsetWidth || 1; const rawBoardWidth = theme!.tileAspectRatio!.x + theme!.tileStride!.x * (maxTilePos[0] - minTilePos[0]); let scaleFactor = offsetWidthFromCanvasRef / rawBoardWidth; @@ -142,7 +141,7 @@ export default function GameComponment({ sessionId }: { sessionId: string }) { > { console.log("Clicked: " + tileKey); @@ -186,7 +185,7 @@ export default function GameComponment({ sessionId }: { sessionId: string }) { transform: translationString, pointerEvents: "none", }} - src={serverUri + iconPath} + src={"api/" + iconPath} /> ); @@ -213,7 +212,7 @@ export default function GameComponment({ sessionId }: { sessionId: string }) { height: theme!.tileAspectRatio!.y * scaleFactor, pointerEvents: "none", }} - src={serverUri + iconPath} + src={"api/" + iconPath} > ); diff --git a/src/main/jchess-web/components/GameComponent/PieceSelectionComponent.tsx b/src/main/jchess-web/components/GameComponent/PieceSelectionComponent.tsx index 25d66ef..15e40c6 100644 --- a/src/main/jchess-web/components/GameComponent/PieceSelectionComponent.tsx +++ b/src/main/jchess-web/components/GameComponent/PieceSelectionComponent.tsx @@ -12,8 +12,6 @@ export default function PieceSelectionComponent({ sessionId: string; iconMap: { [key: string]: string }; }) { - const serverUri = Config.clientUri + "/api/"; - const [pieceSelectionOffer, setPieceSelectionOffer] = useState(undefined); // Websocket @@ -84,7 +82,7 @@ export default function PieceSelectionComponent({ } }} > - + diff --git a/src/main/jchess-web/services/rest_api_service.tsx b/src/main/jchess-web/services/rest_api_service.tsx index 8ec6e8e..eacdc34 100644 --- a/src/main/jchess-web/services/rest_api_service.tsx +++ b/src/main/jchess-web/services/rest_api_service.tsx @@ -11,8 +11,7 @@ import Config from "@/utils/config"; * @returns A promise that resolves to the session id of the new game. */ export async function postCreateGame(gameCreateBody: GameCreate): Promise { - const serverUri = Config.clientUri; - const response = await fetch(`${serverUri}/api/game/create`, { + const response = await fetch(`api/game/create`, { method: "POST", headers: { "Content-Type": "application/json", @@ -20,13 +19,12 @@ export async function postCreateGame(gameCreateBody: GameCreate): Promise { - const serverUri = Config.clientUri; - const response = await fetch(`${serverUri}/api/game/clicked`, { + const response = await fetch(`api/game/clicked`, { method: "POST", headers: { "Content-Type": "application/json", @@ -46,7 +43,7 @@ export async function postClick(body: GameClicked): Promise { body: JSON.stringify(body), }); if (!response.ok) { - throw new Error(`Error fetching ${serverUri}/api/game/create: ${response.status} ${response.statusText}`); + throw new Error(`Error fetching api/game/create: ${response.status} ${response.statusText}`); } } @@ -74,14 +71,12 @@ export async function fetchGameModes(): Promise { * @throws An error if the fetch request fails or if there is an error parsing the response. */ export async function fetchData(endpoint: string): Promise { - const serverUri = Config.clientUri; - const response = await fetch(`${serverUri}/api/${endpoint}`); + const response = await fetch(`api/${endpoint}`); if (!response.ok) { throw new Error(`Error fetching ${endpoint}: ${response.status} ${response.statusText}`); } try { - const data = await response.json(); - return data; + return await response.json(); } catch (error) { console.error(`Error fetching ${endpoint}:`, error); throw error; diff --git a/src/main/jchess-web/utils/config.ts b/src/main/jchess-web/utils/config.ts index 72258ef..8dad303 100644 --- a/src/main/jchess-web/utils/config.ts +++ b/src/main/jchess-web/utils/config.ts @@ -20,13 +20,6 @@ class Config { return uri as string; } - - static get clientUri(): string { - const uri = process.env.NEXT_PUBLIC_CLIENT_URI; - Config.validateRequiredValue('NEXT_PUBLIC_CLIENT_URI', uri); - return uri as string; - } - static get boardWithCoordinates(): boolean { return process.env.NEXT_PUBLIC_BOARD_WITH_COORDINATES === 'true'; } @@ -37,7 +30,6 @@ class Config { static log(): void { console.log('NEXT_PUBLIC_JCHESS_UNDERTOW_SERVER_URI', Config.undertowServerUri); - console.log('NEXT_PUBLIC_CLIENT_URI', Config.clientUri); console.log('NEXT_PUBLIC_BOARD_WITH_COORDINATES', Config.boardWithCoordinates); console.log('NEXT_PUBLIC_LOCAL_STORAGE', Config.useLocalStorage); console.log('NEXT_PUBLIC_JCHESS_SOCKET_URI', Config.socketServerUri); From 6cb21f748e1967d6089754c981054ae376bd4c71 Mon Sep 17 00:00:00 2001 From: BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:04:38 +0100 Subject: [PATCH 4/7] fix invalid import statements --- src/main/jchess-web/components/ui/carousel.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/jchess-web/components/ui/carousel.tsx b/src/main/jchess-web/components/ui/carousel.tsx index cf3988e..76b8d4b 100644 --- a/src/main/jchess-web/components/ui/carousel.tsx +++ b/src/main/jchess-web/components/ui/carousel.tsx @@ -1,13 +1,14 @@ import * as React from "react"; -import useEmblaCarousel, { - type EmblaCarouselType as CarouselApi, - type EmblaOptionsType as CarouselOptions, - type EmblaPluginType as CarouselPlugin, -} from "embla-carousel-react"; import { ArrowLeft, ArrowRight } from "lucide-react"; import { cn } from "@/utils/tailwindMergeUtils"; import { Button } from "@/components/ui/button"; +import { + type EmblaOptionsType as CarouselOptions, + type EmblaCarouselType as CarouselApi, + type EmblaPluginType as CarouselPlugin, +} from "embla-carousel"; +import useEmblaCarousel from "embla-carousel-react"; type CarouselProps = { opts?: CarouselOptions; From 576657bf1c240562aaa4b9056e214ae1b7363609 Mon Sep 17 00:00:00 2001 From: BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:05:29 +0100 Subject: [PATCH 5/7] dockerize frontend --- docker-compose.yml | 8 ++ src/main/jchess-web/Dockerfile | 77 +++++++++++++++++++ src/main/jchess-web/next.config.js | 1 + .../jchess-web/services/rest_api_service.tsx | 2 - src/main/jchess-web/utils/config.ts | 1 - 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 src/main/jchess-web/Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index ca803ac..251fa6d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,5 +3,13 @@ services: build: . ports: - "8880:8880" + expose: + - "8880" environment: - IS_DOCKER=true + frontend: + build: + context: ./src/main/ + dockerfile: ./jchess-web/Dockerfile + ports: + - "3000:3000" diff --git a/src/main/jchess-web/Dockerfile b/src/main/jchess-web/Dockerfile new file mode 100644 index 0000000..76d1f01 --- /dev/null +++ b/src/main/jchess-web/Dockerfile @@ -0,0 +1,77 @@ +# https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile +FROM node:18-alpine AS base + + +# Rebuild the source code only when needed +FROM base AS builder +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat +WORKDIR /app + +COPY jchess-web/package.json jchess-web/package-lock.json* ./ +COPY ./jchess-web/app app +COPY ./jchess-web/components components +COPY ./jchess-web/pages pages +COPY ./jchess-web/public public +COPY ./jchess-web/services services +COPY ./jchess-web/utils utils +COPY ./jchess-web/.eslintrc.json .eslintrc.json +COPY ./jchess-web/components.json components.json +COPY ./jchess-web/next.config.js next.config.js +COPY ./jchess-web/postcss.config.js postcss.config.js +COPY ./jchess-web/tailwind.config.ts tailwind.config.ts +COPY ./jchess-web/tsconfig.json tsconfig.json +COPY ./resources/dx ./resources/dx + +RUN npm i +RUN npm install -g json-schema-to-typescript +RUN json2ts -i ./resources/dx/schema/ -o ./models --cwd ./resources/dx/schema/types + +# Next.js collects completely anonymous telemetry data about general usage. +# Learn more here: https://nextjs.org/telemetry +# Uncomment the following line in case you want to disable telemetry during the build. +# ENV NEXT_TELEMETRY_DISABLED 1 + +# see .env.example +ENV NEXT_PUBLIC_JCHESS_UNDERTOW_SERVER_URI "http://backend:8880" +# verwirrend, aber: http Requests werden auf dem Server aufgelöst, Sockets auf dem Client +# -> PROBLEM: dann stimmt die Addresse hier natürlich nur, wenn man den Server selbst hostet... (TODO erja) +ENV NEXT_PUBLIC_JCHESS_SOCKET_URI "ws://localhost:8880" +ENV NEXT_PUBLIC_BOARD_WITH_COORDINATES "false" +ENV NEXT_PUBLIC_LOCAL_STORAGE "false" + +RUN npm run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production +# Uncomment the following line in case you want to disable telemetry during runtime. +# ENV NEXT_TELEMETRY_DISABLED 1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 +# set hostname to localhost +ENV HOSTNAME "0.0.0.0" + +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/next-config-js/output +CMD ["node", "server.js"] diff --git a/src/main/jchess-web/next.config.js b/src/main/jchess-web/next.config.js index d1d6059..18db7fa 100644 --- a/src/main/jchess-web/next.config.js +++ b/src/main/jchess-web/next.config.js @@ -1,6 +1,7 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, + output: 'standalone', }; module.exports = nextConfig; diff --git a/src/main/jchess-web/services/rest_api_service.tsx b/src/main/jchess-web/services/rest_api_service.tsx index eacdc34..ebe5302 100644 --- a/src/main/jchess-web/services/rest_api_service.tsx +++ b/src/main/jchess-web/services/rest_api_service.tsx @@ -2,8 +2,6 @@ import { GameClicked } from "@/models/message/GameClicked.schema"; import { GameCreate } from "@/models/message/GameCreate.schema"; import { GameModes } from "@/models/message/GameModes.schema"; import { Themes } from "@/models/message/Themes.schema"; -import { Theme } from "@/models/types/Theme.schema"; -import Config from "@/utils/config"; /** * @function postCreateGame diff --git a/src/main/jchess-web/utils/config.ts b/src/main/jchess-web/utils/config.ts index 8dad303..d0d735f 100644 --- a/src/main/jchess-web/utils/config.ts +++ b/src/main/jchess-web/utils/config.ts @@ -37,4 +37,3 @@ class Config { } export default Config; - \ No newline at end of file From f472b918b162326790fa3a0eff8610f7ca0b9774 Mon Sep 17 00:00:00 2001 From: BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:05:46 +0100 Subject: [PATCH 6/7] fix docker build: requires "public" directory --- src/main/jchess-web/public/.keep | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/jchess-web/public/.keep diff --git a/src/main/jchess-web/public/.keep b/src/main/jchess-web/public/.keep new file mode 100644 index 0000000..8962a96 --- /dev/null +++ b/src/main/jchess-web/public/.keep @@ -0,0 +1 @@ +// Ordner ist aktuell leer, aber die Dockerfile schlägt fehl, wenn er fehlt..... From b0544020511546c8ddd7057bccaeb5dcf1435476 Mon Sep 17 00:00:00 2001 From: BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:25:20 +0100 Subject: [PATCH 7/7] update readme, pass backend_port as arg to frontend --- README.md | 10 ++++++++++ docker-compose.yml | 2 ++ src/main/jchess-web/Dockerfile | 7 +++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index becdffe..39a0231 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,16 @@ Hier wird das Projekt allgemein und das Backend beschrieben. Siehe auch: [Frontend Dokumentation](./src/main/jchess-web/README.md) +### Server start/stop +```bash +# starts both the Backend and Frontend. +# Will be available at 'localhost:3000' +docker-compose up -d + +# stops the servers +docker-compose down +``` + --- ## Entwicklerhilfen diff --git a/docker-compose.yml b/docker-compose.yml index 251fa6d..3558002 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,5 +11,7 @@ services: build: context: ./src/main/ dockerfile: ./jchess-web/Dockerfile + args: + backend_port: 8880 ports: - "3000:3000" diff --git a/src/main/jchess-web/Dockerfile b/src/main/jchess-web/Dockerfile index 76d1f01..9eb987f 100644 --- a/src/main/jchess-web/Dockerfile +++ b/src/main/jchess-web/Dockerfile @@ -1,9 +1,12 @@ +ARG backend_port + # https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile FROM node:18-alpine AS base # Rebuild the source code only when needed FROM base AS builder +ARG backend_port # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat WORKDIR /app @@ -33,10 +36,10 @@ RUN json2ts -i ./resources/dx/schema/ -o ./models --cwd ./resources/dx/schema/ty # ENV NEXT_TELEMETRY_DISABLED 1 # see .env.example -ENV NEXT_PUBLIC_JCHESS_UNDERTOW_SERVER_URI "http://backend:8880" +ENV NEXT_PUBLIC_JCHESS_UNDERTOW_SERVER_URI "http://backend:$backend_port" # verwirrend, aber: http Requests werden auf dem Server aufgelöst, Sockets auf dem Client # -> PROBLEM: dann stimmt die Addresse hier natürlich nur, wenn man den Server selbst hostet... (TODO erja) -ENV NEXT_PUBLIC_JCHESS_SOCKET_URI "ws://localhost:8880" +ENV NEXT_PUBLIC_JCHESS_SOCKET_URI "ws://localhost:$backend_port" ENV NEXT_PUBLIC_BOARD_WITH_COORDINATES "false" ENV NEXT_PUBLIC_LOCAL_STORAGE "false"