Docker
This commit is contained in:
parent
7ccf8c5e84
commit
7f7b86f70e
4 changed files with 11 additions and 106 deletions
29
DOCKER.md
29
DOCKER.md
|
|
@ -76,38 +76,29 @@ docker rm -f 9router
|
|||
|
||||
# 🛠 For Developers
|
||||
|
||||
## Build image locally
|
||||
## Build image locally (test)
|
||||
|
||||
```bash
|
||||
# from repo root
|
||||
npm run docker:build
|
||||
```
|
||||
|
||||
Or directly:
|
||||
```bash
|
||||
cd app && docker build -t 9router .
|
||||
```
|
||||
|
||||
Run local build:
|
||||
```bash
|
||||
docker run --rm -p 20128:20128 \
|
||||
-v "$HOME/.9router:/app/data" \
|
||||
-e DATA_DIR=/app/data \
|
||||
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
|
||||
# 1. Login once
|
||||
docker login
|
||||
# Use scripts/release.js (recommended)
|
||||
node scripts/release.js "Release title" "Notes"
|
||||
|
||||
# 2. Build amd64 + arm64 + push (tag from app/cli/package.json version)
|
||||
npm run docker:publish
|
||||
# Or manually
|
||||
git tag v0.4.x && git push origin v0.4.x
|
||||
```
|
||||
|
||||
Tags pushed:
|
||||
- `decolua/9router:v{version}`
|
||||
- `decolua/9router:latest`
|
||||
Workflow: `app/.github/workflows/docker-publish.yml`
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
"dev": "nodemon -I --watch cli.js --watch src --watch hooks --ext js,json cli.js",
|
||||
"build": "node scripts/build-cli.js",
|
||||
"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",
|
||||
"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("/", "/")}`);
|
||||
Loading…
Add table
Add a link
Reference in a new issue