Add Docker Compose deployment
This commit is contained in:
13
.dockerignore
Normal file
13
.dockerignore
Normal 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
17
Dockerfile
Normal 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"]
|
||||
|
||||
18
README.md
18
README.md
@@ -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
12
compose.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
services:
|
||||
tictactics:
|
||||
build:
|
||||
context: .
|
||||
image: tictactics:local
|
||||
container_name: tictactics
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
PORT: 3000
|
||||
ports:
|
||||
- "3000:3000"
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user