Browse Source

Updating docker configuration

* Fleshed out the Dockerfile
* Updated ignore files
* Removed log files from repository
* Added some logging to the entrypoint.sh
* Updated fields in package.json
* Changed the config module to load files without require
* Added development run script
pull/10/head
Drew Short 5 years ago
parent
commit
be7f2d19ba
  1. 9
      .dockerignore
  2. 6
      .gitignore
  3. 16
      Dockerfile
  4. 5
      bot/config.js
  5. 36
      combined.log
  6. 6
      entrypoint.sh
  7. 0
      error.log
  8. 2
      package.json
  9. 21
      scripts/run_development_docker.sh

9
.dockerignore

@ -1,2 +1,7 @@
data/*config.json
log/
node_modules/
log/
*.swp
pipeline.yml
README.md
CONTRIBUTING.md
test/

6
.gitignore

@ -6,6 +6,10 @@ data/*config.json
# Log files
log/
*.log
# Mac Files
.DS_Store
.DS_Store
# Swap files
*.swp

16
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
ENTRYPOINT [ "./entrypoint.sh" ]
CMD [ "run" ]

5
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);

36
combined.log

@ -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"}

6
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
esac

0
error.log

2
package.json

@ -4,6 +4,8 @@
"main": "index.js",
"author": "Drew Short <warrick@sothr.com>",
"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"
},

21
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
Loading…
Cancel
Save