diff --git a/connect4-ui/AGENTS.md b/AGENTS.md similarity index 100% rename from connect4-ui/AGENTS.md rename to AGENTS.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bf4fce4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,112 @@ +# ============================================ +# Stage 1: Dependencies Installation Stage +# ============================================ + +# IMPORTANT: Node.js Version Maintenance +# This Dockerfile uses Node.js 24.13.0-slim, which was the latest LTS version at the time of writing. +# To ensure security and compatibility, regularly update the NODE_VERSION ARG to the latest LTS version. +ARG NODE_VERSION=24.13.0-slim + +FROM node:${NODE_VERSION} AS dependencies + +# Set working directory +WORKDIR /app + +# Copy package-related files first to leverage Docker's caching mechanism +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ + +# Install project dependencies with frozen lockfile for reproducible builds +RUN --mount=type=cache,target=/root/.npm \ + --mount=type=cache,target=/usr/local/share/.cache/yarn \ + --mount=type=cache,target=/root/.local/share/pnpm/store \ + if [ -f package-lock.json ]; then \ + npm ci --no-audit --no-fund; \ + elif [ -f yarn.lock ]; then \ + corepack enable yarn && yarn install --frozen-lockfile --production=false; \ + elif [ -f pnpm-lock.yaml ]; then \ + corepack enable pnpm && pnpm install --frozen-lockfile; \ + else \ + echo "No lockfile found." && exit 1; \ + fi + +# ============================================ +# Stage 2: Build Next.js application in standalone mode +# ============================================ + +FROM node:${NODE_VERSION} AS builder + +# Set working directory +WORKDIR /app + +# Copy project dependencies from dependencies stage +COPY --from=dependencies /app/node_modules ./node_modules + +# Copy application source code +COPY . . + +ENV NODE_ENV=production + +# 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 + +# Build Next.js application +# If you want to speed up Docker rebuilds, you can cache the build artifacts +# by adding: --mount=type=cache,target=/app/.next/cache +# This caches the .next/cache directory across builds, but it also prevents +# .next/cache/fetch-cache from being included in the final image, meaning +# cached fetch responses from the build won't be available at runtime. +RUN if [ -f package-lock.json ]; then \ + npm run build; \ + elif [ -f yarn.lock ]; then \ + corepack enable yarn && yarn build; \ + elif [ -f pnpm-lock.yaml ]; then \ + corepack enable pnpm && pnpm build; \ + else \ + echo "No lockfile found." && exit 1; \ + fi + +# ============================================ +# Stage 3: Run Next.js application +# ============================================ + +FROM node:${NODE_VERSION} AS runner + +# Set working directory +WORKDIR /app + +# Set production environment variables +ENV NODE_ENV=production +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +# 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 run time. +# ENV NEXT_TELEMETRY_DISABLED=1 + +# Copy production assets +COPY --from=builder --chown=node:node /app/public ./public + +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown node:node .next + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=node:node /app/.next/standalone ./ +COPY --from=builder --chown=node:node /app/.next/static ./.next/static + +# If you want to persist the fetch cache generated during the build so that +# cached responses are available immediately on startup, uncomment this line: +# COPY --from=builder --chown=node:node /app/.next/cache ./.next/cache + +# Switch to non-root user for security best practices +USER node + +# Expose port 3000 to allow HTTP traffic +EXPOSE 3000 + +# Start Next.js standalone server +CMD ["node", "server.js"] \ No newline at end of file diff --git a/connect4-ui/app/globals.css b/app/globals.css similarity index 100% rename from connect4-ui/app/globals.css rename to app/globals.css diff --git a/connect4-ui/app/layout.tsx b/app/layout.tsx similarity index 100% rename from connect4-ui/app/layout.tsx rename to app/layout.tsx diff --git a/connect4-ui/app/page.tsx b/app/page.tsx similarity index 100% rename from connect4-ui/app/page.tsx rename to app/page.tsx diff --git a/connect4-ui/app/play/page.tsx b/app/play/page.tsx similarity index 100% rename from connect4-ui/app/play/page.tsx rename to app/play/page.tsx diff --git a/connect4-ui/app/spectate/page.tsx b/app/spectate/page.tsx similarity index 100% rename from connect4-ui/app/spectate/page.tsx rename to app/spectate/page.tsx diff --git a/connect4-ui/components/AdminSettingsPanel.tsx b/components/AdminSettingsPanel.tsx similarity index 100% rename from connect4-ui/components/AdminSettingsPanel.tsx rename to components/AdminSettingsPanel.tsx diff --git a/connect4-ui/components/Board.tsx b/components/Board.tsx similarity index 100% rename from connect4-ui/components/Board.tsx rename to components/Board.tsx diff --git a/connect4-ui/components/Celebration.tsx b/components/Celebration.tsx similarity index 100% rename from connect4-ui/components/Celebration.tsx rename to components/Celebration.tsx diff --git a/connect4-ui/components/Nav.tsx b/components/Nav.tsx similarity index 100% rename from connect4-ui/components/Nav.tsx rename to components/Nav.tsx diff --git a/connect4-ui/connect4-moderator-server b/connect4-moderator-server similarity index 100% rename from connect4-ui/connect4-moderator-server rename to connect4-moderator-server diff --git a/connect4-ui/.eslintrc.json b/connect4-ui/.eslintrc.json deleted file mode 100644 index 6b10a5b..0000000 --- a/connect4-ui/.eslintrc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": [ - "next/core-web-vitals", - "next/typescript" - ] -} diff --git a/connect4-ui/.prettierignore b/connect4-ui/.prettierignore deleted file mode 100644 index dd736b3..0000000 --- a/connect4-ui/.prettierignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -.next -out -connect4-moderator-server diff --git a/connect4-ui/.prettierrc b/connect4-ui/.prettierrc deleted file mode 100644 index 8973894..0000000 --- a/connect4-ui/.prettierrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "useTabs": false, - "tabWidth": 2 -} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d2868ee --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + connect4-ui: + build: + context: . + dockerfile: Dockerfile + image: connect4-ui + container_name: connect4-ui + environment: + NODE_ENV: production + PORT: "3000" + ports: + - "3000:3000" + restart: unless-stopped \ No newline at end of file diff --git a/docker_build.sh b/docker_build.sh new file mode 100644 index 0000000..eb79694 --- /dev/null +++ b/docker_build.sh @@ -0,0 +1 @@ +docker build . -t joshuafhiggins/connect4-ui \ No newline at end of file diff --git a/connect4-ui/lib/connection.tsx b/lib/connection.tsx similarity index 100% rename from connect4-ui/lib/connection.tsx rename to lib/connection.tsx diff --git a/connect4-ui/lib/protocol.ts b/lib/protocol.ts similarity index 99% rename from connect4-ui/lib/protocol.ts rename to lib/protocol.ts index 3f5babe..24d53ca 100644 --- a/connect4-ui/lib/protocol.ts +++ b/lib/protocol.ts @@ -30,7 +30,7 @@ export interface ReservationEntry { export const DEFAULT_WS_URL = process.env.NODE_ENV === "development" ? "ws://localhost:8080" - : "wss://connect4.abunchofknowitalls.com"; + : "wss://connect4.abunchofknowitalls.com/ws"; export const RECONNECT_INTERVAL_MS = 5000; export const RECONNECT_TIMEOUT_MS = 60000; diff --git a/connect4-ui/lib/sfx.ts b/lib/sfx.ts similarity index 100% rename from connect4-ui/lib/sfx.ts rename to lib/sfx.ts diff --git a/connect4-ui/next-env.d.ts b/next-env.d.ts similarity index 100% rename from connect4-ui/next-env.d.ts rename to next-env.d.ts diff --git a/connect4-ui/next.config.ts b/next.config.ts similarity index 100% rename from connect4-ui/next.config.ts rename to next.config.ts diff --git a/connect4-ui/package-lock.json b/package-lock.json similarity index 100% rename from connect4-ui/package-lock.json rename to package-lock.json diff --git a/connect4-ui/package.json b/package.json similarity index 100% rename from connect4-ui/package.json rename to package.json diff --git a/connect4-ui/postcss.config.js b/postcss.config.js similarity index 100% rename from connect4-ui/postcss.config.js rename to postcss.config.js diff --git a/connect4-ui/public/sfx/chip_collide_1.ogg b/public/sfx/chip_collide_1.ogg similarity index 100% rename from connect4-ui/public/sfx/chip_collide_1.ogg rename to public/sfx/chip_collide_1.ogg diff --git a/connect4-ui/public/sfx/chip_collide_2.ogg b/public/sfx/chip_collide_2.ogg similarity index 100% rename from connect4-ui/public/sfx/chip_collide_2.ogg rename to public/sfx/chip_collide_2.ogg diff --git a/connect4-ui/public/sfx/chip_collide_3.ogg b/public/sfx/chip_collide_3.ogg similarity index 100% rename from connect4-ui/public/sfx/chip_collide_3.ogg rename to public/sfx/chip_collide_3.ogg diff --git a/connect4-ui/public/sfx/chip_collide_4.ogg b/public/sfx/chip_collide_4.ogg similarity index 100% rename from connect4-ui/public/sfx/chip_collide_4.ogg rename to public/sfx/chip_collide_4.ogg diff --git a/connect4-ui/public/sfx/chip_collide_5.ogg b/public/sfx/chip_collide_5.ogg similarity index 100% rename from connect4-ui/public/sfx/chip_collide_5.ogg rename to public/sfx/chip_collide_5.ogg diff --git a/connect4-ui/public/sfx/chip_collide_6.ogg b/public/sfx/chip_collide_6.ogg similarity index 100% rename from connect4-ui/public/sfx/chip_collide_6.ogg rename to public/sfx/chip_collide_6.ogg diff --git a/connect4-ui/public/sfx/chip_collide_7.ogg b/public/sfx/chip_collide_7.ogg similarity index 100% rename from connect4-ui/public/sfx/chip_collide_7.ogg rename to public/sfx/chip_collide_7.ogg diff --git a/connect4-ui/tsconfig.json b/tsconfig.json similarity index 100% rename from connect4-ui/tsconfig.json rename to tsconfig.json diff --git a/connect4-ui/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo similarity index 100% rename from connect4-ui/tsconfig.tsbuildinfo rename to tsconfig.tsbuildinfo