Added basic docker support.
This commit is contained in:
parent
0dcbd0ad2e
commit
748d9de02a
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@ logs/
|
||||
config/*
|
||||
!config/configuration.js
|
||||
!config.schema.js
|
||||
credentials.*
|
||||
credentials.*
|
||||
config*.yml
|
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@ -0,0 +1,17 @@
|
||||
FROM node:18.19.0
|
||||
|
||||
ENV APP_DIR=/app
|
||||
ENV CONFIG_DIR=/config
|
||||
ENV LOGS_DIR=/logs
|
||||
ENV WEB_PORT=9011
|
||||
|
||||
RUN mkdir -p ${APP_DIR}/node_modules
|
||||
|
||||
WORKDIR ${APP_DIR}
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
|
||||
EXPOSE ${WEB_PORT}
|
||||
|
||||
CMD [ "node", "app.js" ]
|
2
app.js
2
app.js
@ -36,7 +36,7 @@ const limiter = rateLimit({
|
||||
app.use(helmet());
|
||||
app.use(limiter);
|
||||
|
||||
const PORT = process.env.PORT || config.web.port || 9111;
|
||||
const PORT = config.web.port || 9011;
|
||||
app.listen(PORT, () => {
|
||||
logger.info("Listening to port " + PORT + ".");
|
||||
});
|
@ -1,7 +1,9 @@
|
||||
const Ajv = require("ajv");
|
||||
const fs = require("fs");
|
||||
const docker = require("../utils/docker");
|
||||
const logger = require("../services/logging");
|
||||
const yaml = require("js-yaml");
|
||||
const { exit } = require("process");
|
||||
|
||||
const configurationBase = {
|
||||
plex: {
|
||||
@ -30,11 +32,12 @@ const configurationBase = {
|
||||
}
|
||||
};
|
||||
|
||||
const configurationFile = yaml.load(fs.readFileSync('config/config.yml'), yaml.JSON_SCHEMA);
|
||||
const isDocker = docker.isRunningOnDocker();
|
||||
const configPath = isDocker ? `${process.env.CONFIG_DIR}/config.yml` : "config.yml";
|
||||
const configurationFile = yaml.load(fs.readFileSync(configPath), yaml.JSON_SCHEMA);
|
||||
|
||||
const ajv = new Ajv({ allErrors: true });
|
||||
const schema = require("./config.schema");
|
||||
const { exit } = require("process");
|
||||
const validation = ajv.compile(schema);
|
||||
const valid = validation(configurationFile);
|
||||
|
||||
@ -44,4 +47,7 @@ if (!valid) {
|
||||
}
|
||||
|
||||
const configuration = { ...configurationBase, ...configurationFile }
|
||||
|
||||
configuration.web.port ||= process.env.WEB_PORT;
|
||||
|
||||
module.exports = configuration;
|
@ -1,5 +1,9 @@
|
||||
const docker = require("../utils/docker");
|
||||
const path = require("path");
|
||||
const pino = require("pino");
|
||||
const logger = pino(pino.destination({ dest: 'logs/.log', sync: false }));
|
||||
|
||||
const directory = docker.isRunningOnDocker() ? process.env.LOGS_DIR : "logs";
|
||||
const logger = pino(pino.destination({ dest: path.join(directory, '.log'), sync: false }));
|
||||
|
||||
const environment = process.env.NODE_ENV || 'development';
|
||||
if (environment == "production") {
|
||||
|
13
utils/docker.js
Normal file
13
utils/docker.js
Normal file
@ -0,0 +1,13 @@
|
||||
const fs = require("fs");
|
||||
|
||||
function isRunningOnDocker() {
|
||||
try {
|
||||
return fs.existsSync("/.dockerenv");
|
||||
} catch { }
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
isRunningOnDocker
|
||||
}
|
Loading…
Reference in New Issue
Block a user