diff --git a/.dockerignore b/.dockerignore index ba561b3..0c31b8f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,7 @@ -data/*config.json -log/ \ No newline at end of file +node_modules/ +log/ +*.swp +pipeline.yml +README.md +CONTRIBUTING.md +test/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index bc3e975..08a93ea 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ data/*config.json # Log files log/ +*.log # Mac Files -.DS_Store \ No newline at end of file +.DS_Store + +# Swap files +*.swp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e60840b..a1dbcdf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,16 @@ FROM node:12.14-stretch + COPY . /opt/baphomet -RUN npm install + +ENV NODE_ENV=production +ENV LOG_LEVEL=warn + +RUN mkdir /opt/baphomet/log + +RUN cd /opt/baphomet \ + && npm install --only=prod \ + && chmod +x entrypoint.sh + WORKDIR /opt/baphomet -ENTRYPOINT entrypoint.sh -CMD run \ No newline at end of file +ENTRYPOINT [ "./entrypoint.sh" ] +CMD [ "run" ] diff --git a/bot/config.js b/bot/config.js index ad3e471..9c1a7a7 100644 --- a/bot/config.js +++ b/bot/config.js @@ -1,3 +1,4 @@ +let fs = require('fs'); let { logger } = require('./logging'); let loadedConfigs = new Map(); @@ -12,7 +13,9 @@ function sanitizeConfig(config, fields=[]) { function getConfig(configFile, sanitizedFields=[]) { if (!loadedConfigs.has(configFile)) { - let config = require(configFile); + logger.info("Reading config: %s", configFile); + let rawConfigData = fs.readFileSync(configFile); + let config = JSON.parse(rawConfigData); logger.info("Loaded config: %s", configFile); logger.debug("%o", sanitizeConfig(config, sanitizedFields)); loadedConfigs.set(configFile, config); diff --git a/combined.log b/combined.log deleted file mode 100644 index e754a7d..0000000 --- a/combined.log +++ /dev/null @@ -1,36 +0,0 @@ -{"message":"Running with config:","level":"info","service":"user-service"} -{"message":{"baseUrl":"https://matrix.nulloctet.com","userId":"@baphomet-dev:nulloctet.com","accessToken":"******","admins":["@warrick:nulloctet.com"],"anyCanInvite":false,"statusRooms":["!ayFeLNSFDrerMMelCg:nulloctet.com"]},"level":"debug","service":"user-service"} -{"service":"user-service","level":"info","message":"Running version:"} -{"message":"Creating Matrix Client","level":"info","service":"user-service"} -{"message":"Starting Matrix SDK Client","level":"info","service":"user-service"} -{"service":"user-service","level":"debug","message":"Notifying %s"} -{"service":"user-service","level":"debug","message":"Notified %s"} -{"service":"user-service","level":"debug","message":"Notifying %s"} -{"service":"user-service","level":"debug","message":"Notified %s"} -{"message":"Running with config:","level":"info","service":"user-service"} -{"message":{"baseUrl":"https://matrix.nulloctet.com","userId":"@baphomet-dev:nulloctet.com","accessToken":"******","admins":["@warrick:nulloctet.com"],"anyCanInvite":false,"statusRooms":["!ayFeLNSFDrerMMelCg:nulloctet.com"]},"level":"debug","service":"user-service"} -{"service":"user-service","level":"info","message":"Running version:"} -{"message":"Creating Matrix Client","level":"info","service":"user-service"} -{"message":"Starting Matrix SDK Client","level":"info","service":"user-service"} -{"service":"user-service","level":"debug","message":"Notifying %s of startup"} -{"service":"user-service","level":"debug","message":"Notified %s of startup"} -{"service":"user-service","level":"debug","message":"Notifying %s of shutdown"} -{"service":"user-service","level":"debug","message":"Notified %s of shutdown"} -{"message":"Running with config:","level":"info","service":"user-service"} -{"message":{"baseUrl":"https://matrix.nulloctet.com","userId":"@baphomet-dev:nulloctet.com","accessToken":"******","admins":["@warrick:nulloctet.com"],"anyCanInvite":false,"statusRooms":["!ayFeLNSFDrerMMelCg:nulloctet.com"]},"level":"debug","service":"user-service"} -{"service":"user-service","level":"info","message":"Running version:"} -{"message":"Creating Matrix Client","level":"info","service":"user-service"} -{"message":"Starting Matrix SDK Client","level":"info","service":"user-service"} -{"service":"user-service","level":"debug","message":"Notifying %s of startup"} -{"service":"user-service","level":"debug","message":"Notified %s of startup"} -{"service":"user-service","level":"debug","message":"Notifying %s of shutdown"} -{"service":"user-service","level":"debug","message":"Notified %s of shutdown"} -{"message":"Running with config:","level":"info","service":"user-service"} -{"service":"user-service","level":"debug","message":"%o"} -{"service":"user-service","level":"info","message":"Running version: %s"} -{"message":"Creating Matrix Client","level":"info","service":"user-service"} -{"message":"Starting Matrix SDK Client","level":"info","service":"user-service"} -{"service":"user-service","level":"debug","message":"Notifying %s of startup"} -{"service":"user-service","level":"debug","message":"Notified %s of startup"} -{"service":"user-service","level":"debug","message":"Notifying %s of shutdown"} -{"service":"user-service","level":"debug","message":"Notified %s of shutdown"} diff --git a/entrypoint.sh b/entrypoint.sh index 47ea9d7..35d1320 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,6 +3,10 @@ DIR="$( cd "$( dirname "${0}" )" >/dev/null 2>&1 && pwd )" export NODE_PATH="${DIR}" +echo "NODE_ENV: ${NODE_ENV}" +echo "NODE_PATH: ${NODE_PATH}" +echo "LOG_LEVEL: ${LOG_LEVEL}" + case $1 in run) node index.js @@ -10,4 +14,4 @@ run) *) echo "\"$1\" is an unrecognized command" ;; -esac \ No newline at end of file +esac diff --git a/error.log b/error.log deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index 528dff5..b165106 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "main": "index.js", "author": "Drew Short ", "license": "MIT", + "description": "A Matrix bot written on top of the matrix-js-sdk", + "repository": "https://git.nulloctet.com/warricksothr/baphomet-js", "scripts": { "test": "mocha" }, diff --git a/scripts/run_development_docker.sh b/scripts/run_development_docker.sh new file mode 100644 index 0000000..3ca56c6 --- /dev/null +++ b/scripts/run_development_docker.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +pushd "${DIR}/.." + +CONTAINER_NAME=baphomet-dev +IMAGE_NAME=baphomet-js +IMAGE_TAG=dev +IMAGE_BUILD_DIR=. + +docker build -t ${IMAGE_NAME}:${IMAGE_TAG} ${IMAGE_BUILD_DIR} + +docker rm ${CONTAINER_NAME} + +docker run -it \ + -e NODE_ENV=development \ + -e LOG_LEVEL=debug \ + --name ${CONTAINER_NAME} \ + ${IMAGE_NAME}:${IMAGE_TAG} + +popd \ No newline at end of file