mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
M004: close Docker and deployment workflow
This commit is contained in:
1 parent
3cca211ae9
commit
3397e90749
9 files changed
+238
-7
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
.git
|
||||||
|
.github
|
||||||
|
.claude
|
||||||
|
node_modules
|
||||||
|
web/node_modules
|
||||||
|
dist
|
||||||
|
web/dist
|
||||||
|
data
|
||||||
|
certs
|
||||||
|
release-artifacts
|
||||||
|
*.tar.gz
|
||||||
|
*.tar.xz
|
||||||
|
claude.pem
|
||||||
|
config.json
|
||||||
|
*.log
|
||||||
@@ -26,12 +26,16 @@ jobs:
|
|||||||
web/package-lock.json
|
web/package-lock.json
|
||||||
- name: Build application
|
- name: Build application
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
|
env:
|
||||||
|
RELEASE_VERSION: ${{ inputs.version }}
|
||||||
run: |
|
run: |
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
npm ci --no-audit --no-fund
|
npm ci --no-audit --no-fund
|
||||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||||
npm --prefix web ci --no-audit --no-fund
|
npm --prefix web ci --no-audit --no-fund
|
||||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||||
|
npm version --no-git-tag-version $env:RELEASE_VERSION
|
||||||
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||||
npm --prefix web run build
|
npm --prefix web run build
|
||||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||||
npm run build
|
npm run build
|
||||||
@@ -71,7 +75,7 @@ jobs:
|
|||||||
$smokeRoot = Join-Path $env:RUNNER_TEMP ($packageName + "-smoke")
|
$smokeRoot = Join-Path $env:RUNNER_TEMP ($packageName + "-smoke")
|
||||||
Copy-Item -Recurse -LiteralPath $packageRoot -Destination $smokeRoot
|
Copy-Item -Recurse -LiteralPath $packageRoot -Destination $smokeRoot
|
||||||
@{
|
@{
|
||||||
port = 31440
|
port = 3040
|
||||||
tsHost = "203.0.113.10"
|
tsHost = "203.0.113.10"
|
||||||
tsPort = 9987
|
tsPort = 9987
|
||||||
tsServerPassword = ""
|
tsServerPassword = ""
|
||||||
@@ -85,7 +89,7 @@ jobs:
|
|||||||
$health = $null
|
$health = $null
|
||||||
for ($attempt = 0; $attempt -lt 30 -and -not $health; $attempt++) {
|
for ($attempt = 0; $attempt -lt 30 -and -not $health; $attempt++) {
|
||||||
Start-Sleep -Milliseconds 500
|
Start-Sleep -Milliseconds 500
|
||||||
try { $health = Invoke-RestMethod -Uri "http://127.0.0.1:31440/api/health" -TimeoutSec 2 } catch {}
|
try { $health = Invoke-RestMethod -Uri "http://127.0.0.1:3040/api/health" -TimeoutSec 2 } catch {}
|
||||||
}
|
}
|
||||||
if (-not $health -or $health.status -ne "ok" -or $health.version -ne $env:RELEASE_VERSION) {
|
if (-not $health -or $health.status -ne "ok" -or $health.version -ne $env:RELEASE_VERSION) {
|
||||||
throw "Windows release health check failed"
|
throw "Windows release health check failed"
|
||||||
@@ -113,10 +117,13 @@ jobs:
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
web/package-lock.json
|
web/package-lock.json
|
||||||
- name: Build application
|
- name: Build application
|
||||||
|
env:
|
||||||
|
RELEASE_VERSION: ${{ inputs.version }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
npm ci --no-audit --no-fund
|
npm ci --no-audit --no-fund
|
||||||
npm --prefix web ci --no-audit --no-fund
|
npm --prefix web ci --no-audit --no-fund
|
||||||
|
npm version --no-git-tag-version "$RELEASE_VERSION"
|
||||||
npm --prefix web run build
|
npm --prefix web run build
|
||||||
npm run build
|
npm run build
|
||||||
npm prune --omit=dev --no-audit --no-fund
|
npm prune --omit=dev --no-audit --no-fund
|
||||||
@@ -148,7 +155,7 @@ jobs:
|
|||||||
cp -a "$package_root" "$smoke_root"
|
cp -a "$package_root" "$smoke_root"
|
||||||
cat > "$smoke_root/config.json" <<'CONFIG'
|
cat > "$smoke_root/config.json" <<'CONFIG'
|
||||||
{
|
{
|
||||||
"port": 31441,
|
"port": 3040,
|
||||||
"tsHost": "203.0.113.10",
|
"tsHost": "203.0.113.10",
|
||||||
"tsPort": 9987,
|
"tsPort": 9987,
|
||||||
"tsServerPassword": "",
|
"tsServerPassword": "",
|
||||||
@@ -164,7 +171,7 @@ jobs:
|
|||||||
trap 'kill "$app_pid" 2>/dev/null || true; wait "$app_pid" 2>/dev/null || true' EXIT
|
trap 'kill "$app_pid" 2>/dev/null || true; wait "$app_pid" 2>/dev/null || true' EXIT
|
||||||
health=""
|
health=""
|
||||||
for _ in $(seq 1 30); do
|
for _ in $(seq 1 30); do
|
||||||
health="$(curl -fsS --max-time 2 http://127.0.0.1:31441/api/health 2>/dev/null || true)"
|
health="$(curl -fsS --max-time 2 http://127.0.0.1:3040/api/health 2>/dev/null || true)"
|
||||||
if grep -q '"status":"ok"' <<<"$health" && grep -q "\"version\":\"$RELEASE_VERSION\"" <<<"$health"; then break; fi
|
if grep -q '"status":"ok"' <<<"$health" && grep -q "\"version\":\"$RELEASE_VERSION\"" <<<"$health"; then break; fi
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
name: Continuous integration
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
verify:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 22.22.2
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: |
|
||||||
|
package-lock.json
|
||||||
|
web/package-lock.json
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
npm ci --no-audit --no-fund
|
||||||
|
npm --prefix web ci --no-audit --no-fund
|
||||||
|
- name: Test and build
|
||||||
|
run: |
|
||||||
|
npm test
|
||||||
|
npm run build
|
||||||
|
npm --prefix web run build
|
||||||
|
|
||||||
|
docker-smoke:
|
||||||
|
needs: verify
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Build image
|
||||||
|
run: docker build --tag webspeak:ci .
|
||||||
|
- name: Run health smoke test
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
docker run --detach --name webspeak-ci --publish 3040:3040 webspeak:ci
|
||||||
|
trap 'docker logs webspeak-ci; docker rm --force webspeak-ci' EXIT
|
||||||
|
for attempt in $(seq 1 30); do
|
||||||
|
if curl --fail --silent http://127.0.0.1:3040/health | grep -q '"status":"ok"'; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
exit 1
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
name: Publish Docker image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
tags: ["v*.*.*"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE_NAME: ghcr.io/echosixhiya/webspeak
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Log in to GHCR
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Docker metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
type=ref,event=tag
|
||||||
|
type=sha
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
FROM node:22-bookworm-slim AS build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends python3 make g++ \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
COPY web/package.json web/package-lock.json ./web/
|
||||||
|
RUN npm ci
|
||||||
|
RUN npm --prefix web ci
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN npm --prefix web run build \
|
||||||
|
&& npm run build \
|
||||||
|
&& npm prune --omit=dev \
|
||||||
|
&& rm -rf web/node_modules
|
||||||
|
|
||||||
|
FROM node:22-bookworm-slim AS runtime
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends ca-certificates libstdc++6 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& mkdir -p /data \
|
||||||
|
&& chown node:node /data
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV WEBSPEAK_DATA_DIR=/data
|
||||||
|
|
||||||
|
COPY --from=build --chown=node:node /app/package.json /app/package-lock.json ./
|
||||||
|
COPY --from=build --chown=node:node /app/node_modules ./node_modules
|
||||||
|
COPY --from=build --chown=node:node /app/dist ./dist
|
||||||
|
COPY --from=build --chown=node:node /app/web/dist ./web/dist
|
||||||
|
|
||||||
|
USER node
|
||||||
|
VOLUME ["/data"]
|
||||||
|
EXPOSE 3040
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
||||||
|
CMD node -e "fetch('http://127.0.0.1:3040/health').then(r => { if (!r.ok) process.exit(1) }).catch(() => process.exit(1))"
|
||||||
|
|
||||||
|
CMD ["node", "dist/index.js"]
|
||||||
@@ -29,6 +29,28 @@ WebSpeak 是一个自托管的 TeamSpeak 浏览器客户端与访客接入网关
|
|||||||
- 可访问的 TeamSpeak 3 或 TeamSpeak 6 服务器。
|
- 可访问的 TeamSpeak 3 或 TeamSpeak 6 服务器。
|
||||||
- 较新的 Chrome 或 Edge;生产环境应使用 HTTPS。
|
- 较新的 Chrome 或 Edge;生产环境应使用 HTTPS。
|
||||||
|
|
||||||
|
### Docker 部署(推荐)
|
||||||
|
|
||||||
|
全新 Linux 主机只需要 Docker:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name webspeak \
|
||||||
|
--restart unless-stopped \
|
||||||
|
-p 3040:3040 \
|
||||||
|
-v webspeak-data:/data \
|
||||||
|
ghcr.io/EchoSixHIYA/webspeak:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
容器内部端口固定为 `3040`,SQLite 数据库、主密钥和日志持久化在 `/data`。启动后打开 `http://你的地址:3040/admin`,使用 `admin/admin` 登录并按页面要求修改密码。生产环境请在前面配置 HTTPS 反向代理。
|
||||||
|
|
||||||
|
也可以使用仓库附带的 `docker-compose.yml`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
docker logs webspeak
|
||||||
|
```
|
||||||
|
|
||||||
Ubuntu / Debian:
|
Ubuntu / Debian:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -212,6 +234,28 @@ WebSpeak is a self-hosted TeamSpeak web client and guest gateway. Every browser
|
|||||||
- A reachable TS3 or TS6 server.
|
- A reachable TS3 or TS6 server.
|
||||||
- A recent Chrome or Edge browser; use HTTPS in production.
|
- A recent Chrome or Edge browser; use HTTPS in production.
|
||||||
|
|
||||||
|
### Docker deployment (recommended)
|
||||||
|
|
||||||
|
On a fresh Linux host, Docker is the only requirement:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name webspeak \
|
||||||
|
--restart unless-stopped \
|
||||||
|
-p 3040:3040 \
|
||||||
|
-v webspeak-data:/data \
|
||||||
|
ghcr.io/EchoSixHIYA/webspeak:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
The container always listens on `3040`. SQLite, the installation master key, and logs persist under `/data`. Open `http://your-host:3040/admin`, sign in with `admin/admin`, and change the password when prompted. Put an HTTPS reverse proxy in front of the container for production microphone access.
|
||||||
|
|
||||||
|
The repository also includes `docker-compose.yml`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
docker logs webspeak
|
||||||
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install
|
npm install
|
||||||
npm --prefix web install
|
npm --prefix web install
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
services:
|
||||||
|
webspeak:
|
||||||
|
image: ghcr.io/EchoSixHIYA/webspeak:latest
|
||||||
|
container_name: webspeak
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "3040:3040"
|
||||||
|
volumes:
|
||||||
|
- webspeak-data:/data
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
webspeak-data:
|
||||||
+15
-2
@@ -1,5 +1,5 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { existsSync, unlinkSync } from "node:fs";
|
import { existsSync, readFileSync, unlinkSync } from "node:fs";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import { createLogger } from "./logger.js";
|
import { createLogger } from "./logger.js";
|
||||||
import { createWebServer } from "./server/server.js";
|
import { createWebServer } from "./server/server.js";
|
||||||
@@ -13,9 +13,12 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|||||||
const ROOT_DIR = path.resolve(__dirname, "..");
|
const ROOT_DIR = path.resolve(__dirname, "..");
|
||||||
const CONFIG_PATH = path.join(ROOT_DIR, "config.json");
|
const CONFIG_PATH = path.join(ROOT_DIR, "config.json");
|
||||||
const CERT_DIR = path.join(ROOT_DIR, "certs");
|
const CERT_DIR = path.join(ROOT_DIR, "certs");
|
||||||
const DATA_DIR = path.join(ROOT_DIR, "data");
|
// Production images mount the persistent volume at /data. Source installs
|
||||||
|
// keep the historical project-local data directory unless overridden.
|
||||||
|
const DATA_DIR = process.env.WEBSPEAK_DATA_DIR?.trim() || path.join(ROOT_DIR, "data");
|
||||||
const LOG_DIR = path.join(DATA_DIR, "logs");
|
const LOG_DIR = path.join(DATA_DIR, "logs");
|
||||||
const STATIC_DIR = path.join(ROOT_DIR, "web", "dist");
|
const STATIC_DIR = path.join(ROOT_DIR, "web", "dist");
|
||||||
|
const APP_VERSION = readPackageVersion();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const logger = createLogger(LOG_DIR);
|
const logger = createLogger(LOG_DIR);
|
||||||
@@ -37,6 +40,7 @@ async function main() {
|
|||||||
|
|
||||||
const webServer = createWebServer({
|
const webServer = createWebServer({
|
||||||
port: APP_PORT,
|
port: APP_PORT,
|
||||||
|
version: APP_VERSION,
|
||||||
staticDir: STATIC_DIR,
|
staticDir: STATIC_DIR,
|
||||||
certDir: hasCert ? CERT_DIR : undefined,
|
certDir: hasCert ? CERT_DIR : undefined,
|
||||||
voiceBridgeOptions: {
|
voiceBridgeOptions: {
|
||||||
@@ -59,6 +63,15 @@ async function main() {
|
|||||||
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readPackageVersion(): string {
|
||||||
|
try {
|
||||||
|
const packageJson = JSON.parse(readFileSync(path.join(ROOT_DIR, "package.json"), "utf8")) as { version?: unknown };
|
||||||
|
return typeof packageJson.version === "string" && packageJson.version ? packageJson.version : "0.1.0";
|
||||||
|
} catch {
|
||||||
|
return "0.1.0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function removeObsoleteBootstrapFile(): void {
|
function removeObsoleteBootstrapFile(): void {
|
||||||
try {
|
try {
|
||||||
unlinkSync(path.join(DATA_DIR, "bootstrap"));
|
unlinkSync(path.join(DATA_DIR, "bootstrap"));
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { resolveSafeOpenTarget } from "../security/open-target-policy.js";
|
|||||||
|
|
||||||
export interface WebServerOptions {
|
export interface WebServerOptions {
|
||||||
port: number;
|
port: number;
|
||||||
|
version?: string;
|
||||||
staticDir?: string;
|
staticDir?: string;
|
||||||
certDir?: string; // path to cert.pem + key.pem for HTTPS
|
certDir?: string; // path to cert.pem + key.pem for HTTPS
|
||||||
voiceBridgeOptions: VoiceBridgeOptions;
|
voiceBridgeOptions: VoiceBridgeOptions;
|
||||||
@@ -47,7 +48,7 @@ export function createWebServer(options: WebServerOptions): WebServer {
|
|||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
|
|
||||||
const healthHandler: express.RequestHandler = (_request, response) => {
|
const healthHandler: express.RequestHandler = (_request, response) => {
|
||||||
response.json({ status: "ok", version: "0.1.0" });
|
response.json({ status: "ok", version: options.version ?? "0.1.0" });
|
||||||
};
|
};
|
||||||
app.get("/health", healthHandler);
|
app.get("/health", healthHandler);
|
||||||
app.get("/api/health", healthHandler);
|
app.get("/api/health", healthHandler);
|
||||||
|
|||||||
Reference in new issue
Block a user