From 091eee03633cf9306fe2a17e3df2f36176ec27f6 Mon Sep 17 00:00:00 2001 From: Travis Shivers Date: Tue, 21 Jul 2020 16:28:48 -0500 Subject: [PATCH] Dynamic runtime config --- .gitignore | 2 +- Dockerfile | 9 ++-- config/clisaveconfig.js | 6 +++ config/defaults.js | 2 - config/index.js | 66 ++++++++++++++---------- docker-entrypoint.sh | 4 ++ settings.json | 10 ++++ src/App.vue | 23 +++++---- src/components/sidebars/rightsidebar.vue | 2 - src/main.js | 3 +- src/store/actions.js | 7 +++ src/store/getters.js | 3 -- src/store/modules/plex/getters.js | 5 +- src/store/modules/plexservers/getters.js | 5 +- src/store/mutations.js | 4 ++ src/store/state.js | 2 +- vue.config.js | 7 ++- 17 files changed, 99 insertions(+), 61 deletions(-) create mode 100755 config/clisaveconfig.js create mode 100755 docker-entrypoint.sh create mode 100644 settings.json diff --git a/.gitignore b/.gitignore index e6b45283..33e785af 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ db.sqlite # Optional npm cache directory .npm -settings.json \ No newline at end of file +public/config.json \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c6a093db..226ebce7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,14 +5,13 @@ COPY package*.json ./ RUN npm install COPY . . - ARG SERVERS='{"name":"Local Server","location":"Local","url":"/","image":"synclounge-white.png"}' RUN npm run build # production environment FROM node:current-alpine as production-stage WORKDIR /app -COPY --from=build-stage /app/dist . -RUN npm install -g syncloungesocket@2.0.5 -ARG BASE_URL -ENTRYPOINT ["syncloungesocket", "--static_path", "."] +COPY config config +COPY --from=build-stage /app/dist dist +RUN npm install -g syncloungesocket@2.0.5 nconf fs +ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/config/clisaveconfig.js b/config/clisaveconfig.js new file mode 100755 index 00000000..e9c5ba32 --- /dev/null +++ b/config/clisaveconfig.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +const saveConfig = require('./index'); + +const config = saveConfig('dist/config.json'); +console.log(config); diff --git a/config/defaults.js b/config/defaults.js index b9512287..e1a15cbe 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -1,6 +1,4 @@ const defaults = { - base_url: '/', - servers: [ { name: 'SyncLounge AU1', diff --git a/config/index.js b/config/index.js index 45382948..c7d48dbb 100644 --- a/config/index.js +++ b/config/index.js @@ -1,33 +1,47 @@ const nconf = require('nconf'); +const fs = require('fs'); + const defaults = require('./defaults'); -nconf - .argv({ - separator: '__', - parseValues: true, - }) - .env({ - separator: '__', - lowerCase: true, - parseValues: true, - whitelist: Object.keys(defaults).concat([ - 'autojoin__server', - 'autojoin__room', - 'autojoin__password', - 'authentication__mechanism', - 'authentication__type', - 'authentication__authorized', +// Parses, saves, and returns the config +const saveConfig = (file) => { + nconf + .argv({ + separator: '__', + parseValues: true, + }) + .env({ + separator: '__', + lowerCase: true, + parseValues: true, + whitelist: Object.keys(defaults).concat([ + 'autojoin__server', + 'autojoin__room', + 'autojoin__password', + 'authentication__mechanism', + 'authentication__type', + 'authentication__authorized', - 'custom_server__name', - 'custom_server__location', - 'custom_server__url', - 'custom_server__image', + 'custom_server__name', + 'custom_server__location', + 'custom_server__url', + 'custom_server__image', - 'default_slplayer_quality', - ]), - }) - .file({ file: 'settings.json' }); + 'default_slplayer_quality', + ]), + }) + .file({ file }); -nconf.defaults(defaults); + nconf.defaults(defaults); -module.exports = nconf; + // Filter out the weird stuff + const { + type, $0: firstArg, _: command, modern, ...config + } = nconf.get(); + + fs.writeFileSync(file, JSON.stringify(config)); + + return config; +}; + +module.exports = saveConfig; diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 00000000..2a663b91 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/sh +echo "Testtt" +./config/clisaveconfig.js +exec syncloungesocket --static_path dist \ No newline at end of file diff --git a/settings.json b/settings.json new file mode 100644 index 00000000..6f985c0e --- /dev/null +++ b/settings.json @@ -0,0 +1,10 @@ +{ + "servers": [ + { + "name": "Custom Server 1", + "location": "Custom Location", + "url": "http://vps.conicaw.me:9999", + "image": "https://mycustomserver.com/logo.png" + } + ] +} \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 5f773af5..aa8bd65e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,7 +1,7 @@