From c8bd871ba780407ba54255fb8ce9f1831a1423db Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Mon, 9 Oct 2023 08:26:13 +0200 Subject: [PATCH] Use environment variables to configure the exporter. --- src/exporter.js | 4 ++-- src/lib/prometheus.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/exporter.js b/src/exporter.js index 54f59f26..84eb8689 100644 --- a/src/exporter.js +++ b/src/exporter.js @@ -5,7 +5,7 @@ const path = require('path'); const logger = require('./lib/logger'); // Check if there is a `apps.json` in the config folder -if (!fs.existsSync(path.resolve(__dirname, '../config/apps.json'))) { +if (!process.env.APPS && !fs.existsSync(path.resolve(__dirname, '../config/apps.json'))) { logger.error( 'Please copy the file "src/examples/apps.json" => "config/apps.json"', ); @@ -13,7 +13,7 @@ if (!fs.existsSync(path.resolve(__dirname, '../config/apps.json'))) { } // Check if there is a `config.json` in the config folder -if (!fs.existsSync(path.resolve(__dirname, '../config/config.json'))) { +if (!process.env.CONFIG && !fs.existsSync(path.resolve(__dirname, '../config/config.json'))) { logger.error( 'Please copy the file "src/examples/config.json" => "config/config.json"', ); diff --git a/src/lib/prometheus.js b/src/lib/prometheus.js index 165b8282..722f860e 100644 --- a/src/lib/prometheus.js +++ b/src/lib/prometheus.js @@ -4,10 +4,10 @@ const client = require('prom-client'); const itunes = require('app-store-scraper'); const gplay = require('google-play-scraper'); -// Config files -const config = require('../../config/config.json'); -const apps = require('../../config/apps.json'); -const metrics = require('../config/metrics.json'); +// get config from docker environment variables or config files +const config = process.env.CONFIG ? JSON.parse(process.env.CONFIG) : require('../../config/config.json'); +const apps = process.env.APPS ? JSON.parse(process.env.APPS) : require('../../config/apps.json'); +const metrics = process.env.METRICS ? JSON.parse(process.env.METRICS) : require('../config/metrics.json'); const register = new client.Registry();