mirror of
https://github.com/decolua/9router.git
synced 2026-05-08 12:01:28 +00:00
Add Docker support and improve Dockerfile configuration
- Added `DOCKER.md` documentation to guide users on using Docker with the project. - Migrated Dockerfile to use `oven/bun:1-alpine` for performance improvements. - Refined build process and permissions in the container for better compatibility. - Excluded `.idea/` files in `.gitignore`. - Enhanced `.npmignore` to clean redundant blank lines.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -19,6 +19,7 @@
|
|||||||
product
|
product
|
||||||
# production
|
# production
|
||||||
/build
|
/build
|
||||||
|
.idea/
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
29
.npmignore
29
.npmignore
@@ -29,32 +29,3 @@ tsconfig.json
|
|||||||
.next/cache/
|
.next/cache/
|
||||||
.next/standalone/data/
|
.next/standalone/data/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
76
DOCKER.md
Normal file
76
DOCKER.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# Docker
|
||||||
|
|
||||||
|
This project ships with a `Dockerfile` for building and running 9Router in a container.
|
||||||
|
|
||||||
|
## Build image
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t 9router .
|
||||||
|
```
|
||||||
|
|
||||||
|
## Start container
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm \
|
||||||
|
-p 20128:20128 \
|
||||||
|
-v "$HOME/.9router:/app/data" \
|
||||||
|
--name 9router \
|
||||||
|
9router
|
||||||
|
```
|
||||||
|
|
||||||
|
The app listens on port `20128` in the container.
|
||||||
|
|
||||||
|
## What the volume does
|
||||||
|
|
||||||
|
```bash
|
||||||
|
-v "$HOME/.9router:/app/data"
|
||||||
|
```
|
||||||
|
|
||||||
|
This keeps your data outside the container so it survives restarts and image rebuilds.
|
||||||
|
|
||||||
|
## Stop container
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker stop 9router
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run in background
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-p 20128:20128 \
|
||||||
|
-v "$HOME/.9router:/app/data" \
|
||||||
|
--name 9router \
|
||||||
|
9router
|
||||||
|
```
|
||||||
|
|
||||||
|
## View logs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker logs -f 9router
|
||||||
|
```
|
||||||
|
|
||||||
|
## Optional environment variables
|
||||||
|
|
||||||
|
You can override runtime env vars with `-e`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm \
|
||||||
|
-p 20128:20128 \
|
||||||
|
-v "$HOME/.9router:/app/data" \
|
||||||
|
-e PORT=20128 \
|
||||||
|
-e HOSTNAME=0.0.0.0 \
|
||||||
|
-e DEBUG=true \
|
||||||
|
--name 9router \
|
||||||
|
9router
|
||||||
|
```
|
||||||
|
|
||||||
|
## Rebuild after code changes
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t 9router .
|
||||||
|
```
|
||||||
|
|
||||||
|
Then restart the container.
|
||||||
25
Dockerfile
25
Dockerfile
@@ -1,14 +1,20 @@
|
|||||||
FROM node:20-alpine AS builder
|
# syntax=docker/dockerfile:1.7
|
||||||
|
FROM oven/bun:1-alpine AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package*.json ./
|
FROM base AS builder
|
||||||
RUN if [ -f package-lock.json ]; then npm ci --no-audit --no-fund; else npm install --no-audit --no-fund; fi
|
|
||||||
|
RUN apk add --no-cache nodejs npm python3 make g++ linux-headers
|
||||||
|
|
||||||
|
COPY package.json ./
|
||||||
|
RUN --mount=type=cache,target=/root/.npm \
|
||||||
|
npm install
|
||||||
|
|
||||||
COPY . ./
|
COPY . ./
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
RUN npm run build
|
RUN bun run build:bun
|
||||||
|
|
||||||
FROM node:20-alpine AS runner
|
FROM oven/bun:1-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
LABEL org.opencontainers.image.title="9router"
|
LABEL org.opencontainers.image.title="9router"
|
||||||
@@ -27,13 +33,14 @@ COPY --from=builder /app/src/mitm ./src/mitm
|
|||||||
# Standalone node_modules may omit deps only required by the MITM child process.
|
# Standalone node_modules may omit deps only required by the MITM child process.
|
||||||
COPY --from=builder /app/node_modules/node-forge ./node_modules/node-forge
|
COPY --from=builder /app/node_modules/node-forge ./node_modules/node-forge
|
||||||
|
|
||||||
RUN mkdir -p /app/data
|
RUN mkdir -p /app/data && chown -R bun:bun /app
|
||||||
|
|
||||||
# Fix permissions at runtime (handles mounted volumes)
|
# Fix permissions at runtime (handles mounted volumes)
|
||||||
RUN printf '#!/bin/sh\nchown -R node:node /app/data 2>/dev/null; exec su-exec node "$@"\n' > /entrypoint.sh && chmod +x /entrypoint.sh
|
RUN apk add --no-cache su-exec && \
|
||||||
RUN apk add --no-cache su-exec
|
printf '#!/bin/sh\nchown -R bun:bun /app/data 2>/dev/null\nexec su-exec bun "$@"\n' > /entrypoint.sh && \
|
||||||
|
chmod +x /entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 20128
|
EXPOSE 20128
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
CMD ["node", "server.js"]
|
CMD ["bun", "server.js"]
|
||||||
|
|||||||
Reference in New Issue
Block a user