Add version to index page

This commit is contained in:
simojenki
2021-08-31 09:12:53 +10:00
parent c73f79532d
commit 00f6a9ff8f
6 changed files with 39 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ FROM node:16.6-alpine as build
WORKDIR /bonob WORKDIR /bonob
COPY .git ./.git
COPY src ./src COPY src ./src
COPY docs ./docs COPY docs ./docs
COPY typings ./typings COPY typings ./typings
@@ -19,8 +20,10 @@ RUN apk add --no-cache --update --virtual .gyp \
vips-dev \ vips-dev \
python3 \ python3 \
make \ make \
git \
g++ && \ g++ && \
yarn install --immutable && \ yarn install --immutable && \
yarn gitinfo && \
yarn test --no-cache && \ yarn test --no-cache && \
yarn build yarn build
@@ -39,6 +42,7 @@ COPY yarn.lock .
COPY --from=build /bonob/build/src ./src COPY --from=build /bonob/build/src ./src
COPY --from=build /bonob/node_modules ./node_modules COPY --from=build /bonob/node_modules ./node_modules
COPY --from=build /bonob/.gitinfo ./
COPY web ./web COPY web ./web
COPY src/Sonoswsdl-1.19.4-20190411.142401-3.wsdl ./src/Sonoswsdl-1.19.4-20190411.142401-3.wsdl COPY src/Sonoswsdl-1.19.4-20190411.142401-3.wsdl ./src/Sonoswsdl-1.19.4-20190411.142401-3.wsdl

View File

@@ -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", "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", "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", "register-dev": "ts-node ./src/register.ts http://$(hostname):4534",
"test": "jest" "test": "jest",
"gitinfo": "git describe --tags > .gitinfo"
} }
} }

View File

@@ -1,3 +1,5 @@
import path from "path";
import fs from "fs";
import server from "./server"; import server from "./server";
import logger from "./logger"; import logger from "./logger";
import { appendMimeTypeToClientFor, DEFAULT, Navidrome } from "./navidrome"; 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( const app = server(
sonosSystem, sonosSystem,
bonob, bonob,
@@ -67,7 +73,8 @@ const app = server(
clock: SystemClock, clock: SystemClock,
iconColors: config.icons, iconColors: config.icons,
applyContextPath: true, applyContextPath: true,
logRequests: true logRequests: true,
version
} }
); );

View File

@@ -79,6 +79,7 @@ export type ServerOpts = {
}; };
applyContextPath: boolean; applyContextPath: boolean;
logRequests: boolean; logRequests: boolean;
version: string
}; };
const DEFAULT_SERVER_OPTS: ServerOpts = { const DEFAULT_SERVER_OPTS: ServerOpts = {
@@ -88,6 +89,7 @@ const DEFAULT_SERVER_OPTS: ServerOpts = {
iconColors: { foregroundColor: undefined, backgroundColor: undefined }, iconColors: { foregroundColor: undefined, backgroundColor: undefined },
applyContextPath: true, applyContextPath: true,
logRequests: false, logRequests: false,
version: "v?"
}; };
function server( function server(
@@ -146,6 +148,7 @@ function server(
removeRegistrationRoute: bonobUrl removeRegistrationRoute: bonobUrl
.append({ pathname: REMOVE_REGISTRATION_ROUTE }) .append({ pathname: REMOVE_REGISTRATION_ROUTE })
.pathname(), .pathname(),
version: opts.version
}); });
} }
); );

View File

@@ -179,6 +179,27 @@ describe("server", () => {
[bonobUrlWithNoContextPath, bonobUrlWithContextPath].forEach((bonobUrl) => { [bonobUrlWithNoContextPath, bonobUrlWithContextPath].forEach((bonobUrl) => {
describe(`a bonobUrl of ${bonobUrl}`, () => { describe(`a bonobUrl of ${bonobUrl}`, () => {
describe("/", () => { 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", () => { describe("when sonos integration is disabled", () => {
const server = makeServer( const server = makeServer(
SONOS_DISABLED, SONOS_DISABLED,

View File

@@ -1,6 +1,7 @@
<% layout('./layout') %> <% layout('./layout') %>
<div id="content"> <div id="content">
<div width="100%" style="text-align:right;color:grey"><%= it.version %></div>
<h1><%= it.bonobService.name %> (<%= it.bonobService.sid %>)</h1> <h1><%= it.bonobService.name %> (<%= it.bonobService.sid %>)</h1>
<h3><%= it.lang("expectedConfig") %></h3> <h3><%= it.lang("expectedConfig") %></h3>
<div><%= JSON.stringify(it.bonobService) %></div> <div><%= JSON.stringify(it.bonobService) %></div>