Add Docker Compose deployment

This commit is contained in:
2026-05-05 14:23:45 -04:00
parent 01e1c78bf7
commit 7b6676cdc9
6 changed files with 67 additions and 4 deletions

13
.dockerignore Normal file
View File

@@ -0,0 +1,13 @@
.git
.gitignore
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
*.log
.env
.env.*
Dockerfile
compose.yaml

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM node:24-alpine
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
COPY package.json ./
COPY index.html styles.css game.js server.js ./
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "fetch('http://127.0.0.1:' + (process.env.PORT || 3000) + '/healthz').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"
CMD ["node", "server.js"]

View File

@@ -11,13 +11,27 @@ A notepad-playable browser game that combines Tic Tac Toe's line-making goal wit
- First player to make `4 in a row` wins.
- If the board fills with no winner, the game is a draw.
## Run Multiplayer
## Run With Docker Compose
```powershell
docker compose up --build
```
Then open `http://localhost:3000` in two browser windows. The first two connected players are paired automatically.
Stop it with:
```powershell
docker compose down
```
## Run Locally
```powershell
npm start
```
Then open `http://localhost:3000` in two browser windows. The first two connected players are paired automatically.
Then open `http://localhost:3000` in two browser windows.
Set a different port with:

12
compose.yaml Normal file
View File

@@ -0,0 +1,12 @@
services:
tictactics:
build:
context: .
image: tictactics:local
container_name: tictactics
restart: unless-stopped
environment:
PORT: 3000
ports:
- "3000:3000"

View File

@@ -4,7 +4,7 @@
"private": true,
"description": "A notepad-playable capture tic tac toe browser game with simple WebSocket multiplayer.",
"scripts": {
"start": "node server.js"
"start": "node server.js",
"compose": "docker compose up --build"
}
}

View File

@@ -22,6 +22,13 @@ const mimeTypes = {
const server = http.createServer((request, response) => {
const requestUrl = new URL(request.url, `http://${request.headers.host}`);
if (requestUrl.pathname === "/healthz") {
response.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });
response.end(JSON.stringify({ ok: true }));
return;
}
const pathname = requestUrl.pathname === "/" ? "/index.html" : requestUrl.pathname;
const filePath = path.normalize(path.join(root, pathname));