api: バージョンとデプロイコミットを返す /version エンドポイントを追加
- package.jsonのversionとビルド時注入のコミットSHA(APP_COMMIT)を返す - CoolifyのSOURCE_COMMITをbuild argとして受けるためDockerfile/composeを更新 - authModeも含め、デプロイ状態の切り分けに使えるようにした
This commit is contained in:
@@ -2,6 +2,11 @@ FROM node:22-bookworm
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
# Build-time commit SHA, injected by docker compose (SOURCE_COMMIT) or Coolify.
|
||||
# Exposed to the API at /version for deploy diagnostics.
|
||||
ARG APP_COMMIT=unknown
|
||||
ENV APP_COMMIT=${APP_COMMIT}
|
||||
|
||||
# package-lock.json is committed, so npm ci installs the exact dependency tree.
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import Fastify, { type FastifyReply, type FastifyRequest } from "fastify";
|
||||
import cookie from "@fastify/cookie";
|
||||
import cors from "@fastify/cors";
|
||||
import { z } from "zod";
|
||||
import pkg from "../../../package.json" with { type: "json" };
|
||||
import { buildSourceDocument } from "../../../packages/core/src/index";
|
||||
import type { Identity } from "../../../packages/core/src/index";
|
||||
import { loadConfig } from "./config";
|
||||
@@ -85,6 +86,13 @@ export async function createServer() {
|
||||
await registerAuthRoutes(app, appConfig);
|
||||
|
||||
app.get("/healthz", async () => ({ ok: true, service: "altdock-api", storageMode: appConfig.STORAGE_MODE }));
|
||||
app.get("/version", async () => ({
|
||||
name: "altdock-api",
|
||||
version: pkg.version,
|
||||
commit: process.env.APP_COMMIT || process.env.SOURCE_COMMIT || "unknown",
|
||||
authMode: appConfig.AUTH_MODE,
|
||||
node: process.version,
|
||||
}));
|
||||
|
||||
app.get("/api/v1/me", async (request, reply) => {
|
||||
const identity = await requireIdentity(request, reply, appConfig);
|
||||
|
||||
@@ -19,6 +19,9 @@ x-altdock-app: &altdock-app
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
# Coolify provides SOURCE_COMMIT at build time; falls back to unknown.
|
||||
APP_COMMIT: ${SOURCE_COMMIT:-unknown}
|
||||
working_dir: /workspace
|
||||
restart: unless-stopped
|
||||
|
||||
|
||||
Reference in New Issue
Block a user