diff --git a/Dockerfile b/Dockerfile index a1953f1..dccb6b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM node:16.6-alpine as build WORKDIR /bonob +COPY .git ./.git COPY src ./src COPY docs ./docs COPY typings ./typings @@ -19,8 +20,10 @@ RUN apk add --no-cache --update --virtual .gyp \ vips-dev \ python3 \ make \ + git \ g++ && \ yarn install --immutable && \ + yarn gitinfo && \ yarn test --no-cache && \ yarn build @@ -39,6 +42,7 @@ COPY yarn.lock . COPY --from=build /bonob/build/src ./src COPY --from=build /bonob/node_modules ./node_modules +COPY --from=build /bonob/.gitinfo ./ COPY web ./web COPY src/Sonoswsdl-1.19.4-20190411.142401-3.wsdl ./src/Sonoswsdl-1.19.4-20190411.142401-3.wsdl diff --git a/package.json b/package.json index 07ff87b..69625d0 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "dev": "BONOB_ICON_FOREGROUND_COLOR=white BONOB_ICON_BACKGROUND_COLOR=darkgrey BONOB_SONOS_SERVICE_NAME=bonobDev BONOB_SONOS_DEVICE_DISCOVERY=true nodemon -V ./src/app.ts", "devr": "BONOB_ICON_FOREGROUND_COLOR=white BONOB_ICON_BACKGROUND_COLOR=darkgrey BONOB_SONOS_SERVICE_NAME=bonobDev BONOB_SONOS_DEVICE_DISCOVERY=true BONOB_SONOS_AUTO_REGISTER=true nodemon -V ./src/app.ts", "register-dev": "ts-node ./src/register.ts http://$(hostname):4534", - "test": "jest" + "test": "jest", + "gitinfo": "git describe --tags > .gitinfo" } } diff --git a/src/app.ts b/src/app.ts index 71837c9..8252b92 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,3 +1,5 @@ +import path from "path"; +import fs from "fs"; import server from "./server"; import logger from "./logger"; import { appendMimeTypeToClientFor, DEFAULT, Navidrome } from "./navidrome"; @@ -56,6 +58,10 @@ const featureFlagAwareMusicService: MusicService = { }), }; +export const GIT_INFO = path.join(__dirname, "..", ".gitinfo"); + +const version = fs.existsSync(GIT_INFO) ? fs.readFileSync(GIT_INFO).toString().trim() : "v??" + const app = server( sonosSystem, bonob, @@ -67,7 +73,8 @@ const app = server( clock: SystemClock, iconColors: config.icons, applyContextPath: true, - logRequests: true + logRequests: true, + version } ); diff --git a/src/server.ts b/src/server.ts index f9612bf..38f9ddf 100644 --- a/src/server.ts +++ b/src/server.ts @@ -79,6 +79,7 @@ export type ServerOpts = { }; applyContextPath: boolean; logRequests: boolean; + version: string }; const DEFAULT_SERVER_OPTS: ServerOpts = { @@ -88,6 +89,7 @@ const DEFAULT_SERVER_OPTS: ServerOpts = { iconColors: { foregroundColor: undefined, backgroundColor: undefined }, applyContextPath: true, logRequests: false, + version: "v?" }; function server( @@ -146,6 +148,7 @@ function server( removeRegistrationRoute: bonobUrl .append({ pathname: REMOVE_REGISTRATION_ROUTE }) .pathname(), + version: opts.version }); } ); diff --git a/tests/server.test.ts b/tests/server.test.ts index 156b51e..721be91 100644 --- a/tests/server.test.ts +++ b/tests/server.test.ts @@ -179,6 +179,27 @@ describe("server", () => { [bonobUrlWithNoContextPath, bonobUrlWithContextPath].forEach((bonobUrl) => { describe(`a bonobUrl of ${bonobUrl}`, () => { describe("/", () => { + describe("displaying of version", () => { + const server = makeServer( + SONOS_DISABLED, + aService(), + bonobUrl, + new InMemoryMusicService(), + { + version: "v123.456" + } + ); + + it("should display it", async () => { + const res = await request(server) + .get(bonobUrl.append({ pathname: "/" }).pathname()) + .send(); + + expect(res.status).toEqual(200); + expect(res.text).toMatch(/v123\.456/); + }); + }); + describe("when sonos integration is disabled", () => { const server = makeServer( SONOS_DISABLED, diff --git a/web/views/index.eta b/web/views/index.eta index 615e37e..97e0f1e 100644 --- a/web/views/index.eta +++ b/web/views/index.eta @@ -1,6 +1,7 @@ <% layout('./layout') %>