mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
Docker
This commit is contained in:
@@ -76,38 +76,29 @@ docker rm -f 9router
|
|||||||
|
|
||||||
# 🛠 For Developers
|
# 🛠 For Developers
|
||||||
|
|
||||||
## Build image locally
|
## Build image locally (test)
|
||||||
|
|
||||||
```bash
|
|
||||||
# from repo root
|
|
||||||
npm run docker:build
|
|
||||||
```
|
|
||||||
|
|
||||||
Or directly:
|
|
||||||
```bash
|
```bash
|
||||||
cd app && docker build -t 9router .
|
cd app && docker build -t 9router .
|
||||||
```
|
|
||||||
|
|
||||||
Run local build:
|
|
||||||
```bash
|
|
||||||
docker run --rm -p 20128:20128 \
|
docker run --rm -p 20128:20128 \
|
||||||
-v "$HOME/.9router:/app/data" \
|
-v "$HOME/.9router:/app/data" \
|
||||||
-e DATA_DIR=/app/data \
|
-e DATA_DIR=/app/data \
|
||||||
9router
|
9router
|
||||||
```
|
```
|
||||||
|
|
||||||
## Publish to Docker Hub (multi-platform)
|
## Publish (automatic via CI)
|
||||||
|
|
||||||
Triggered automatically by `npm run cli:publish`. Manual:
|
Push a git tag `v*` → GitHub Actions builds multi-platform (amd64+arm64) and pushes to:
|
||||||
|
- `ghcr.io/decolua/9router:v{version}` + `:latest`
|
||||||
|
- `decolua/9router:v{version}` + `:latest`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 1. Login once
|
# Use scripts/release.js (recommended)
|
||||||
docker login
|
node scripts/release.js "Release title" "Notes"
|
||||||
|
|
||||||
# 2. Build amd64 + arm64 + push (tag from app/cli/package.json version)
|
# Or manually
|
||||||
npm run docker:publish
|
git tag v0.4.x && git push origin v0.4.x
|
||||||
```
|
```
|
||||||
|
|
||||||
Tags pushed:
|
Workflow: `app/.github/workflows/docker-publish.yml`
|
||||||
- `decolua/9router:v{version}`
|
|
||||||
- `decolua/9router:latest`
|
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
"dev": "nodemon -I --watch cli.js --watch src --watch hooks --ext js,json cli.js",
|
"dev": "nodemon -I --watch cli.js --watch src --watch hooks --ext js,json cli.js",
|
||||||
"build": "node scripts/build-cli.js",
|
"build": "node scripts/build-cli.js",
|
||||||
"pack:cli": "npm run build && npm pack --pack-destination ../..",
|
"pack:cli": "npm run build && npm pack --pack-destination ../..",
|
||||||
"publish:cli": "npm run build && npm publish && node ../scripts/dockerPublish.js",
|
"publish:cli": "npm run build && npm publish",
|
||||||
"postinstall": "node hooks/postinstall.js",
|
"postinstall": "node hooks/postinstall.js",
|
||||||
"prepublishOnly": "npm run build"
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
// Build Docker image locally for current platform (test/dev).
|
|
||||||
// Usage: node app/scripts/dockerBuild.js
|
|
||||||
|
|
||||||
const { execSync } = require("child_process");
|
|
||||||
const path = require("path");
|
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
const IMAGE = "decolua/9router";
|
|
||||||
const appDir = path.resolve(__dirname, "..");
|
|
||||||
const cliPkgPath = path.resolve(appDir, "cli", "package.json");
|
|
||||||
const version = JSON.parse(fs.readFileSync(cliPkgPath, "utf8")).version;
|
|
||||||
const tag = `v${version}`;
|
|
||||||
|
|
||||||
console.log(`\n🐳 Building ${IMAGE}:${tag} (local platform)...\n`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
execSync(
|
|
||||||
`docker build -t ${IMAGE}:${tag} -t ${IMAGE}:latest .`,
|
|
||||||
{ stdio: "inherit", cwd: appDir }
|
|
||||||
);
|
|
||||||
console.log(`\n✅ Built ${IMAGE}:${tag} + ${IMAGE}:latest`);
|
|
||||||
console.log(`▶️ Run: docker run --rm -p 20128:20128 -v "$HOME/.9router:/app/data" -e DATA_DIR=/app/data ${IMAGE}:${tag}`);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("❌ Docker build failed");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
// Build & push multi-platform Docker image to Docker Hub.
|
|
||||||
// Requires: docker login + buildx (Docker Desktop ships with it).
|
|
||||||
// Usage: node app/scripts/dockerPublish.js
|
|
||||||
|
|
||||||
const { execSync } = require("child_process");
|
|
||||||
const path = require("path");
|
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
const IMAGE = "decolua/9router";
|
|
||||||
const PLATFORMS = "linux/amd64,linux/arm64";
|
|
||||||
const BUILDER = "9router-builder";
|
|
||||||
|
|
||||||
const appDir = path.resolve(__dirname, "..");
|
|
||||||
const cliPkgPath = path.resolve(appDir, "cli", "package.json");
|
|
||||||
const version = JSON.parse(fs.readFileSync(cliPkgPath, "utf8")).version;
|
|
||||||
const tag = `v${version}`;
|
|
||||||
|
|
||||||
function run(cmd, opts = {}) {
|
|
||||||
console.log(`$ ${cmd}`);
|
|
||||||
execSync(cmd, { stdio: "inherit", cwd: appDir, ...opts });
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`\n🐳 Publishing ${IMAGE}:${tag} (${PLATFORMS}) to Docker Hub...\n`);
|
|
||||||
|
|
||||||
// Verify docker login by checking config
|
|
||||||
try {
|
|
||||||
const cfg = path.join(process.env.HOME || "", ".docker", "config.json");
|
|
||||||
if (fs.existsSync(cfg)) {
|
|
||||||
const json = JSON.parse(fs.readFileSync(cfg, "utf8"));
|
|
||||||
if (!json.auths || Object.keys(json.auths).length === 0) {
|
|
||||||
console.error("❌ Not logged in to Docker Hub. Run: docker login");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
|
|
||||||
// Ensure buildx builder exists with multi-arch support
|
|
||||||
try {
|
|
||||||
execSync(`docker buildx inspect ${BUILDER}`, { stdio: "ignore", cwd: appDir });
|
|
||||||
console.log(`✅ Builder "${BUILDER}" exists`);
|
|
||||||
} catch {
|
|
||||||
console.log(`🔧 Creating buildx builder "${BUILDER}"...`);
|
|
||||||
run(`docker buildx create --name ${BUILDER} --driver docker-container --use`);
|
|
||||||
run(`docker buildx inspect --bootstrap`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build + push multi-platform image
|
|
||||||
run(
|
|
||||||
`docker buildx build --builder ${BUILDER} --platform ${PLATFORMS} ` +
|
|
||||||
`-t ${IMAGE}:${tag} -t ${IMAGE}:latest --push .`
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(`\n✅ Published:`);
|
|
||||||
console.log(` - ${IMAGE}:${tag}`);
|
|
||||||
console.log(` - ${IMAGE}:latest`);
|
|
||||||
console.log(`🔗 https://hub.docker.com/r/${IMAGE.replace("/", "/")}`);
|
|
||||||
Reference in New Issue
Block a user