From 655f2af45ad35b9f44b74e8c86a7aaf248983f74 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 17:33:01 +0200 Subject: [PATCH 01/17] script for turning env-vars into config.js --- docker-entrypoint.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 docker-entrypoint.sh diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..d9a99a1 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# We use this file to translate environmental variables to .env files used by the application + +set -e +function create_document_string () { + IFS=',' read -ra doc_array <<< "$DOCUMENTS" + document_string="{" + + for i in "${doc_array[@]}" + do + IFS='=' read -ra document <<< "$i" + document_string+="\"${document[0]}\": \"${document[1]}\"," + done + + # Remove trailing "," + [[ "$document_string" == *, ]] && document_string=${document_string::${#document_string}-1} + document_string+="}" + echo $document_string +} + +document_string=$(create_document_string) + +echo " +{ + + \"host\": \"$HOST\", + \"port\": ${PORT}, + + \"keyLength\": $KEY_LENGTH, + + \"maxLength\": $MAX_LENGTH, + + \"staticMaxAge\": $STATIC_MAX_AGE, + + \"recompressStaticAssets\": $RECOMPRESS_STATIC_ASSETS, + + \"logging\": [ + { + \"level\": \"$LOGGING_LEVEL\", + \"type\": \"$LOGGING_TYPE\", + \"colorize\": $LOGGING_COLORIZE + } + ], + + \"keyGenerator\": { + \"type\": \"$KEYGENERATOR_TYPE\" + }, + + \"rateLimits\": { + + \"categories\": { + \"normal\": { + \"totalRequests\": $RATELIMITS_NORMAL_TOTAL_REQUESTS, + \"every\": $RATELIMITS_NORMAL_EVERY_SECONDS + }, + \"whitelist\": { + \"totalRequests\": $RATELIMITS_WHITELIST_TOTAL_REQUESTS, + \"every\": $RATELIMITS_WHITELIST_EVERY_SECONDS + }, + \"blacklist\": { + \"totalRequests\": $RATELIMITS_BLACKLIST_TOTAL_REQUESTS, + \"every\": $RATELIMITS_BLACKLIST_EVERY_SECONDS + } + } + }, + + \"storage\": { + \"type\": \"$STORAGE_TYPE\", + \"host\": \"$STORAGE_HOST\", + \"port\": $STORAGE_PORT, + \"expire\": $STORAGE_EXPIRE_SECONDS, + \"db\": $STORAGE_DB + }, + + \"documents\": $document_string + +} +" > config.js + + + +exec "$@" \ No newline at end of file From 064680003d2634a5e9a06750336dd93c4941d445 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 17:33:19 +0200 Subject: [PATCH 02/17] basic dockerfile with default env vars --- Dockerfile | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d3e42c1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +FROM node:latest + +RUN mkdir -p /usr/src/app && \ + chown node:node /usr/src/app + +USER node:node + +WORKDIR /usr/src/app + +COPY --chown=node:node . . + +RUN npm install && \ + npm install redis && \ + npm install pg && \ + npm install memcached + +ENV STORAGE_TYPE=memcached \ + STORAGE_HOST=127.0.0.1 \ + STORAGE_PORT=11211\ + STORAGE_EXPIRE_SECONDS=2592000\ + STORAGE_DB=2 \ + STORAGE_CONNECTION_URL= \ + STORAGE_BUCKET= \ + STORAGE_REGION= + +ENV LOGGING_LEVEL=verbose \ + LOGGING_TYPE=Console \ + LOGGING_COLORIZE=true + +ENV HOST=0.0.0.0\ + PORT=7777\ + KEY_LENGTH=10\ + MAX_LENGTH=400000\ + STATIC_MAX_AGE=86400\ + RECOMPRESS_STATIC_ASSETS=true + +ENV KEYGENERATOR_TYPE=phonetic \ + KEYGENERATOR_KEYSPACE= + +ENV RATELIMITS_NORMAL_TOTAL_REQUESTS=500\ + RATELIMITS_NORMAL_EVERY_SECONDS=60000 \ + RATELIMITS_WHITELIST_TOTAL_REQUESTS=500\ + RATELIMITS_WHITELIST_EVERY_SECONDS=60000 \ + # comma separated list for the whitelisted \ + RATELIMITS_WHITELIST= \ + \ + RATELIMITS_BLACKLIST_TOTAL_REQUESTS=60000 \ + RATELIMITS_BLACKLIST_EVERY_SECONDS=500 \ + # comma separated list for the blacklisted \ + RATELIMITS_BLACKLIST=example.com,example.org +ENV DOCUMENTS=about=./about.md + +EXPOSE 7777 + +ENTRYPOINT [ "bash", "docker-entrypoint.sh" ] + +CMD ["npm", "start"] From 0612ba001ec2ad8cc30a1c11fda58003b95ab4eb Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 17:33:40 +0200 Subject: [PATCH 03/17] basic docker-compose for running the project together with memcached --- docker-compose.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 docker-compose.yaml diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..8365c5d --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,19 @@ +version: '3.0' +services: + haste-server: + build: . + networks: + - db-network + environment: + - STORAGE_TYPE=memcached + - STORAGE_HOST=memcached + - STORAGE_PORT=11211 + ports: + - 7777:7777 + memcached: + image: memcached:latest + networks: + - db-network + +networks: + db-network: From edd428ff3734ebb0ce6d4d824d11b4ae7d9ce0e5 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 20:43:39 +0200 Subject: [PATCH 04/17] fix some names for env vars --- Dockerfile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index d3e42c1..4f0a949 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,10 @@ ENV STORAGE_TYPE=memcached \ STORAGE_EXPIRE_SECONDS=2592000\ STORAGE_DB=2 \ STORAGE_CONNECTION_URL= \ - STORAGE_BUCKET= \ - STORAGE_REGION= + STORAGE_AWS_BUCKET= \ + STORAGE_AWS_REGION= \ + STORAGE_PG_PASSWORD= \ + STORAGE_PG_USERNAME= ENV LOGGING_LEVEL=verbose \ LOGGING_TYPE=Console \ @@ -39,15 +41,15 @@ ENV KEYGENERATOR_TYPE=phonetic \ ENV RATELIMITS_NORMAL_TOTAL_REQUESTS=500\ RATELIMITS_NORMAL_EVERY_SECONDS=60000 \ - RATELIMITS_WHITELIST_TOTAL_REQUESTS=500\ - RATELIMITS_WHITELIST_EVERY_SECONDS=60000 \ + RATELIMITS_WHITELIST_TOTAL_REQUESTS= \ + RATELIMITS_WHITELIST_EVERY_SECONDS= \ # comma separated list for the whitelisted \ - RATELIMITS_WHITELIST= \ + RATELIMITS_WHITELIST=example1.whitelist,example2.whitelist \ \ - RATELIMITS_BLACKLIST_TOTAL_REQUESTS=60000 \ - RATELIMITS_BLACKLIST_EVERY_SECONDS=500 \ + RATELIMITS_BLACKLIST_TOTAL_REQUESTS= \ + RATELIMITS_BLACKLIST_EVERY_SECONDS= \ # comma separated list for the blacklisted \ - RATELIMITS_BLACKLIST=example.com,example.org + RATELIMITS_BLACKLIST=example1.blacklist,example2.blacklist ENV DOCUMENTS=about=./about.md EXPOSE 7777 From 36c854ef1bdc3305c8f10c55688c137e6bb5e8c4 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 20:44:32 +0200 Subject: [PATCH 05/17] move creating the config file to a js file --- docker-entrypoint.js | 105 +++++++++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 76 +------------------------------ 2 files changed, 106 insertions(+), 75 deletions(-) create mode 100644 docker-entrypoint.js diff --git a/docker-entrypoint.js b/docker-entrypoint.js new file mode 100644 index 0000000..d902fb8 --- /dev/null +++ b/docker-entrypoint.js @@ -0,0 +1,105 @@ +const { promisify } = require("util"); +const { + HOST, + PORT, + KEY_LENGTH, + MAX_LENGTH, + STATIC_MAX_AGE, + RECOMPRESS_STATIC_ASSETS, + STORAGE_TYPE, + STORAGE_HOST, + STORAGE_PORT, + STORAGE_EXPIRE_SECONDS, + STORAGE_DB, + STORAGE_AWS_BUCKET, + STORAGE_AWS_REGION, + STORAGE_PG_PASSWORD, + STORAGE_PG_USERNAME, + LOGGING_LEVEL, + LOGGING_TYPE, + LOGGING_COLORIZE, + KEYGENERATOR_TYPE, + KEY_GENERATOR_KEYSPACE, + RATE_LIMITS_NORMAL_TOTAL_REQUESTS, + RATE_LIMITS_NORMAL_EVERY_SECONDS, + RATE_LIMITS_WHITELIST_TOTAL_REQUESTS, + RATE_LIMITS_WHITELIST_EVERY_SECONDS, + RATE_LIMITS_WHITELIST, + RATE_LIMITS_BLACKLIST_TOTAL_REQUESTS, + RATE_LIMITS_BLACKLIST_EVERY_SECONDS, + RATE_LIMITS_BLACKLIST, + DOCUMENTS, +} = process.env; + +const config = { + host: HOST, + port: PORT, + + keyLength: KEY_LENGTH, + + maxLength: MAX_LENGTH, + + staticMaxAge: STATIC_MAX_AGE, + + recompressStaticAssets: RECOMPRESS_STATIC_ASSETS, + + logging: [ + { + level: LOGGING_LEVEL, + type: LOGGING_TYPE, + colorize: LOGGING_COLORIZE, + }, + ], + + keyGenerator: { + type: KEYGENERATOR_TYPE, + keyspace: KEY_GENERATOR_KEYSPACE, + }, + + rateLimits: { + whitelist: RATE_LIMITS_WHITELIST ? RATE_LIMITS_WHITELIST.split(",") : [], + blacklist: RATE_LIMITS_BLACKLIST ? RATE_LIMITS_BLACKLIST.split(",") : [], + categories: { + normal: { + totalRequests: RATE_LIMITS_NORMAL_TOTAL_REQUESTS, + every: RATE_LIMITS_NORMAL_EVERY_SECONDS, + }, + whitelist: + RATE_LIMITS_WHITELIST_EVERY_SECONDS || + RATE_LIMITS_WHITELIST_TOTAL_REQUESTS + ? { + totalRequests: RATE_LIMITS_WHITELIST_TOTAL_REQUESTS, + every: RATE_LIMITS_WHITELIST_EVERY_SECONDS, + } + : null, + blacklist: + RATE_LIMITS_BLACKLIST_EVERY_SECONDS || + RATE_LIMITS_BLACKLIST_TOTAL_REQUESTS + ? { + totalRequests: RATE_LIMITS_WHITELIST_TOTAL_REQUESTS, + every: RATE_LIMITS_BLACKLIST_EVERY_SECONDS, + } + : null, + }, + }, + + storage: { + type: STORAGE_TYPE, + host: STORAGE_HOST, + port: STORAGE_PORT, + expire: STORAGE_EXPIRE_SECONDS, + bucket: STORAGE_AWS_BUCKET, + region: STORAGE_AWS_REGION, + connectionUrl: `postgres://${STORAGE_PG_USERNAME}:${STORAGE_PG_PASSWORD}@${STORAGE_HOST}:${STORAGE_PORT}/${STORAGE_DB}`, + db: STORAGE_DB, + }, + + documents: DOCUMENTS + ? DOCUMENTS.split(",").reduce((acc, item) => { + const keyAndValueArray = item.replace(/\s/g, "").split("="); + return { ...acc, [keyAndValueArray[0]]: keyAndValueArray[1] }; + }, {}) + : null, +}; + +console.log(JSON.stringify(config)); diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index d9a99a1..8e4e5a1 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -3,81 +3,7 @@ # We use this file to translate environmental variables to .env files used by the application set -e -function create_document_string () { - IFS=',' read -ra doc_array <<< "$DOCUMENTS" - document_string="{" - - for i in "${doc_array[@]}" - do - IFS='=' read -ra document <<< "$i" - document_string+="\"${document[0]}\": \"${document[1]}\"," - done - - # Remove trailing "," - [[ "$document_string" == *, ]] && document_string=${document_string::${#document_string}-1} - document_string+="}" - echo $document_string -} - -document_string=$(create_document_string) - -echo " -{ - - \"host\": \"$HOST\", - \"port\": ${PORT}, - - \"keyLength\": $KEY_LENGTH, - - \"maxLength\": $MAX_LENGTH, - - \"staticMaxAge\": $STATIC_MAX_AGE, - - \"recompressStaticAssets\": $RECOMPRESS_STATIC_ASSETS, - - \"logging\": [ - { - \"level\": \"$LOGGING_LEVEL\", - \"type\": \"$LOGGING_TYPE\", - \"colorize\": $LOGGING_COLORIZE - } - ], - - \"keyGenerator\": { - \"type\": \"$KEYGENERATOR_TYPE\" - }, - - \"rateLimits\": { - - \"categories\": { - \"normal\": { - \"totalRequests\": $RATELIMITS_NORMAL_TOTAL_REQUESTS, - \"every\": $RATELIMITS_NORMAL_EVERY_SECONDS - }, - \"whitelist\": { - \"totalRequests\": $RATELIMITS_WHITELIST_TOTAL_REQUESTS, - \"every\": $RATELIMITS_WHITELIST_EVERY_SECONDS - }, - \"blacklist\": { - \"totalRequests\": $RATELIMITS_BLACKLIST_TOTAL_REQUESTS, - \"every\": $RATELIMITS_BLACKLIST_EVERY_SECONDS - } - } - }, - - \"storage\": { - \"type\": \"$STORAGE_TYPE\", - \"host\": \"$STORAGE_HOST\", - \"port\": $STORAGE_PORT, - \"expire\": $STORAGE_EXPIRE_SECONDS, - \"db\": $STORAGE_DB - }, - - \"documents\": $document_string - -} -" > config.js - +node ./docker-entrypoint.js > ./config.js exec "$@" \ No newline at end of file From aef4bb5edbc98b245280ccd1db7c766ca294d438 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 20:45:27 +0200 Subject: [PATCH 06/17] add dockerignore file --- .dockerignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a865156 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +npm-debug.log +node_modules +*.swp +*.swo +data +*.DS_Store From 0f145b4444f8c35c35aba8818c355c15c168ebf4 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 20:48:32 +0200 Subject: [PATCH 07/17] pin versions --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f0a949..136b5b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:latest +FROM node:14.8.0-stretch RUN mkdir -p /usr/src/app && \ chown node:node /usr/src/app @@ -10,9 +10,9 @@ WORKDIR /usr/src/app COPY --chown=node:node . . RUN npm install && \ - npm install redis && \ - npm install pg && \ - npm install memcached + npm install redis@0.8.1 && \ + npm install pg@4.1.1 && \ + npm install memcached@2.2.2 ENV STORAGE_TYPE=memcached \ STORAGE_HOST=127.0.0.1 \ From 5a8d52a5e3e76e735cf135e33596f70cc548b138 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 20:56:11 +0200 Subject: [PATCH 08/17] add healthcheck, and stopsignal, plus export the correct port --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 136b5b6..bcbfe43 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,8 +52,10 @@ ENV RATELIMITS_NORMAL_TOTAL_REQUESTS=500\ RATELIMITS_BLACKLIST=example1.blacklist,example2.blacklist ENV DOCUMENTS=about=./about.md -EXPOSE 7777 - +EXPOSE ${PORT} +STOPSIGNAL SIGINT ENTRYPOINT [ "bash", "docker-entrypoint.sh" ] +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s \ + --retries=3 CMD [ "curl" , "-f" "localhost:${PORT}", "||", "exit", "1"] CMD ["npm", "start"] From 5c9311fb85292d7a563287b99ea5f190d855205a Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 20:56:45 +0200 Subject: [PATCH 09/17] remove unused import --- docker-entrypoint.js | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-entrypoint.js b/docker-entrypoint.js index d902fb8..e9e7ead 100644 --- a/docker-entrypoint.js +++ b/docker-entrypoint.js @@ -1,4 +1,3 @@ -const { promisify } = require("util"); const { HOST, PORT, From 9f419935668aa429f4bc1c7694ef4f6edfb9d2ee Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 21:06:02 +0200 Subject: [PATCH 10/17] also install rethinkdb and aws-sdk --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bcbfe43..76b87f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,9 @@ COPY --chown=node:node . . RUN npm install && \ npm install redis@0.8.1 && \ npm install pg@4.1.1 && \ - npm install memcached@2.2.2 + npm install memcached@2.2.2 && \ + npm install aws-sdk@2.738.0 && \ + npm install rethinkdbdash@2.3.31 ENV STORAGE_TYPE=memcached \ STORAGE_HOST=127.0.0.1 \ From 69cf505a9041a47f35d30ce4150e0c47f71473b7 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 21:29:41 +0200 Subject: [PATCH 11/17] remove pg connect string, add rethink user and password --- Dockerfile | 5 +++-- docker-entrypoint.js | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 76b87f3..f4f2527 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,11 +21,12 @@ ENV STORAGE_TYPE=memcached \ STORAGE_PORT=11211\ STORAGE_EXPIRE_SECONDS=2592000\ STORAGE_DB=2 \ - STORAGE_CONNECTION_URL= \ STORAGE_AWS_BUCKET= \ STORAGE_AWS_REGION= \ STORAGE_PG_PASSWORD= \ - STORAGE_PG_USERNAME= + STORAGE_PG_USERNAME= \ + STORAGE_RETHINK_USER= \ + STORAGE_RETHINK_PASSWORD= ENV LOGGING_LEVEL=verbose \ LOGGING_TYPE=Console \ diff --git a/docker-entrypoint.js b/docker-entrypoint.js index e9e7ead..d661fbf 100644 --- a/docker-entrypoint.js +++ b/docker-entrypoint.js @@ -14,6 +14,8 @@ const { STORAGE_AWS_REGION, STORAGE_PG_PASSWORD, STORAGE_PG_USERNAME, + STORAGE_RETHINK_USER, + STORAGE_RETHINK_PASSWORD, LOGGING_LEVEL, LOGGING_TYPE, LOGGING_COLORIZE, @@ -91,6 +93,8 @@ const config = { region: STORAGE_AWS_REGION, connectionUrl: `postgres://${STORAGE_PG_USERNAME}:${STORAGE_PG_PASSWORD}@${STORAGE_HOST}:${STORAGE_PORT}/${STORAGE_DB}`, db: STORAGE_DB, + user: STORAGE_RETHINK_USER, + password: STORAGE_RETHINK_USER, }, documents: DOCUMENTS From 05ecc90764dce2b6e24e8f8be3da707e8d77679f Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 21:47:48 +0200 Subject: [PATCH 12/17] add file path --- Dockerfile | 3 ++- docker-entrypoint.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f4f2527..3b1f0e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,8 @@ ENV STORAGE_TYPE=memcached \ STORAGE_PG_PASSWORD= \ STORAGE_PG_USERNAME= \ STORAGE_RETHINK_USER= \ - STORAGE_RETHINK_PASSWORD= + STORAGE_RETHINK_PASSWORD= \ + STORAGE_FILEPATH= ENV LOGGING_LEVEL=verbose \ LOGGING_TYPE=Console \ diff --git a/docker-entrypoint.js b/docker-entrypoint.js index d661fbf..60be55d 100644 --- a/docker-entrypoint.js +++ b/docker-entrypoint.js @@ -16,6 +16,7 @@ const { STORAGE_PG_USERNAME, STORAGE_RETHINK_USER, STORAGE_RETHINK_PASSWORD, + STORAGE_FILEPATH, LOGGING_LEVEL, LOGGING_TYPE, LOGGING_COLORIZE, @@ -95,6 +96,7 @@ const config = { db: STORAGE_DB, user: STORAGE_RETHINK_USER, password: STORAGE_RETHINK_USER, + path: STORAGE_FILEPATH, }, documents: DOCUMENTS From 342f56ce1a9513716249ec54d4b62e09401cb97c Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 21:56:58 +0200 Subject: [PATCH 13/17] use same password and username env vars for all types --- Dockerfile | 6 ++---- docker-entrypoint.js | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3b1f0e2..34a06e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,10 +23,8 @@ ENV STORAGE_TYPE=memcached \ STORAGE_DB=2 \ STORAGE_AWS_BUCKET= \ STORAGE_AWS_REGION= \ - STORAGE_PG_PASSWORD= \ - STORAGE_PG_USERNAME= \ - STORAGE_RETHINK_USER= \ - STORAGE_RETHINK_PASSWORD= \ + STORAGE_USENAMER= \ + STORAGE_PASSWORD= \ STORAGE_FILEPATH= ENV LOGGING_LEVEL=verbose \ diff --git a/docker-entrypoint.js b/docker-entrypoint.js index 60be55d..f8912de 100644 --- a/docker-entrypoint.js +++ b/docker-entrypoint.js @@ -92,10 +92,10 @@ const config = { expire: STORAGE_EXPIRE_SECONDS, bucket: STORAGE_AWS_BUCKET, region: STORAGE_AWS_REGION, - connectionUrl: `postgres://${STORAGE_PG_USERNAME}:${STORAGE_PG_PASSWORD}@${STORAGE_HOST}:${STORAGE_PORT}/${STORAGE_DB}`, + connectionUrl: `postgres://${STORAGE_USERNAME}:${STORAGE_PASSWORD}@${STORAGE_HOST}:${STORAGE_PORT}/${STORAGE_DB}`, db: STORAGE_DB, - user: STORAGE_RETHINK_USER, - password: STORAGE_RETHINK_USER, + user: STORAGE_USERNAME, + password: STORAGE_PASSWORD, path: STORAGE_FILEPATH, }, From a4dc29fb2bc7fff3eb1231e576883d1101c03b0d Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 22:12:54 +0200 Subject: [PATCH 14/17] its supposed to be milliseconds --- Dockerfile | 6 +++--- docker-entrypoint.js | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 34a06e3..dd53efc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,14 +42,14 @@ ENV KEYGENERATOR_TYPE=phonetic \ KEYGENERATOR_KEYSPACE= ENV RATELIMITS_NORMAL_TOTAL_REQUESTS=500\ - RATELIMITS_NORMAL_EVERY_SECONDS=60000 \ + RATELIMITS_NORMAL_EVERY_MILLISECONDS=60000 \ RATELIMITS_WHITELIST_TOTAL_REQUESTS= \ - RATELIMITS_WHITELIST_EVERY_SECONDS= \ + RATELIMITS_WHITELIST_EVERY_MILLISECONDS= \ # comma separated list for the whitelisted \ RATELIMITS_WHITELIST=example1.whitelist,example2.whitelist \ \ RATELIMITS_BLACKLIST_TOTAL_REQUESTS= \ - RATELIMITS_BLACKLIST_EVERY_SECONDS= \ + RATELIMITS_BLACKLIST_EVERY_MILLISECONDS= \ # comma separated list for the blacklisted \ RATELIMITS_BLACKLIST=example1.blacklist,example2.blacklist ENV DOCUMENTS=about=./about.md diff --git a/docker-entrypoint.js b/docker-entrypoint.js index f8912de..05b29da 100644 --- a/docker-entrypoint.js +++ b/docker-entrypoint.js @@ -23,12 +23,12 @@ const { KEYGENERATOR_TYPE, KEY_GENERATOR_KEYSPACE, RATE_LIMITS_NORMAL_TOTAL_REQUESTS, - RATE_LIMITS_NORMAL_EVERY_SECONDS, + RATE_LIMITS_NORMAL_EVERY_MILLISECONDS, RATE_LIMITS_WHITELIST_TOTAL_REQUESTS, - RATE_LIMITS_WHITELIST_EVERY_SECONDS, + RATE_LIMITS_WHITELIST_EVERY_MILLISECONDS, RATE_LIMITS_WHITELIST, RATE_LIMITS_BLACKLIST_TOTAL_REQUESTS, - RATE_LIMITS_BLACKLIST_EVERY_SECONDS, + RATE_LIMITS_BLACKLIST_EVERY_MILLISECONDS, RATE_LIMITS_BLACKLIST, DOCUMENTS, } = process.env; @@ -64,22 +64,22 @@ const config = { categories: { normal: { totalRequests: RATE_LIMITS_NORMAL_TOTAL_REQUESTS, - every: RATE_LIMITS_NORMAL_EVERY_SECONDS, + every: RATE_LIMITS_NORMAL_EVERY_MILLISECONDS, }, whitelist: - RATE_LIMITS_WHITELIST_EVERY_SECONDS || + RATE_LIMITS_WHITELIST_EVERY_MILLISECONDS || RATE_LIMITS_WHITELIST_TOTAL_REQUESTS ? { totalRequests: RATE_LIMITS_WHITELIST_TOTAL_REQUESTS, - every: RATE_LIMITS_WHITELIST_EVERY_SECONDS, + every: RATE_LIMITS_WHITELIST_EVERY_MILLISECONDS, } : null, blacklist: - RATE_LIMITS_BLACKLIST_EVERY_SECONDS || + RATE_LIMITS_BLACKLIST_EVERY_MILLISECONDS || RATE_LIMITS_BLACKLIST_TOTAL_REQUESTS ? { totalRequests: RATE_LIMITS_WHITELIST_TOTAL_REQUESTS, - every: RATE_LIMITS_BLACKLIST_EVERY_SECONDS, + every: RATE_LIMITS_BLACKLIST_EVERY_MILLISECONDS, } : null, }, From bb7b9571a7b7eb1c845d2d4c41f685e7ef2e2574 Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 22:22:08 +0200 Subject: [PATCH 15/17] write some documentation for the Docker solution --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/README.md b/README.md index 23ca077..1cb06f7 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,88 @@ your bucket: } ``` +## Docker + +### Build image + +```bash +docker build --tag haste-server . +``` + +### Run container + +For this example we will run haste-server, and connect it to a redis server + +```bash +docker run --name haste-server-container --env STORAGE_TYPE=redis --env STORAGE_HOST=redis-server --env STORAGE_PORT=6379 haste-server +``` + +### Use docker-compose example + +There is an example `docker-compose.yml` which runs haste-server together with memcached + +```bash +docker-compose up +``` + +### Configuration + +The docker image is configured using environmental variables as you can see in the example above. + +Here is a list of all the environment variables + +### Storage + +| Name | Default value | Description | +| :--------------------: | :-----------: | :-----------------------------------------------------------------------------------------------------------: | +| STORAGE_TYPE | memcached | Type of storage . Accepted values: "memcached","redis","postgres","rethinkdb", "amazon-s3", and "file" | +| STORAGE_HOST | 127.0.0.1 | Storage host. Applicable for types: memcached, redis, postgres, and rethinkdb | +| STORAGE_PORT | 11211 | Port on the storage host. Applicable for types: memcached, redis, postgres, and rethinkdb | +| STORAGE_EXPIRE_SECONDS | 2592000 | Number of seconds to expire keys in. Applicable for types. Redis, postgres, memcached. `expire` option to the | +| STORAGE_DB | 2 | The name of the database. Applicable for redis, postgres, and rethinkdb | +| STORAGE_PASSWORD | | Password for database. Applicable for redis, postges, rethinkdb . | +| STORAGE_USERNAME | | Database username. Applicable for postgres, and rethinkdb | +| STORAGE_AWS_BUCKET | | Applicable for amazon-s3. This is the name of the S3 bucket | +| STORAGE_AWS_REGION | | Applicable for amazon-s3. The region in which the bucket is located | +| STORAGE_FILEPATH | | Path to file to save data to. Applicable for type file | + +### Logging + +| Name | Default value | Description | +| :---------------: | :-----------: | :---------: | +| LOGGING_LEVEL | verbose | | +| LOGGING_TYPE= | Console | +| LOGGING_COLORIZE= | true | + +### Basics + +| Name | Default value | Description | +| :----------------------: | :--------------: | :---------------------------------------------------------------------------------------: | +| HOST | 0.0.0.0 | The hostname which the server answers on | +| PORT | 7777 | The port on which the server is running | +| KEY_LENGTH | 10 | the length of the keys to user | +| MAX_LENGTH | 400000 | maximum length of a paste | +| STATIC_MAX_AGE | 86400 | max age for static assets | +| RECOMPRESS_STATIC_ASSETS | true | whether or not to compile static js assets | +| KEYGENERATOR_TYPE | phonetic | Type of key generator. Acceptable values: "phonetic", or "random" | +| KEYGENERATOR_KEYSPACE | | keySpace argument is a string of acceptable characters | +| DOCUMENTS | about=./about.md | Comma separated list of static documents to serve. ex: \n about=./about.md,home=./home.md | + +### Rate limits + +| Name | Default value | Description | +| :----------------------------------: | :-----------------------------------: | :--------------------------------------------------------------------------------------: | +| RATELIMITS_NORMAL_TOTAL_REQUESTS | 500 | By default anyone uncategorized will be subject to 500 requests in the defined timespan. | +| RATELIMITS_NORMAL_EVERY_MILLISECONDS | 60000 | The timespan to allow the total requests for uncategorized users | +| RATELIMITS_WHITELIST_TOTAL_REQUESTS | | By default client names in the whitelist will not have their requests limited. | +| RATELIMITS_WHITELIST_EVERY_SECONDS | | By default client names in the whitelist will not have their requests limited. | +| RATELIMITS_WHITELIST | example1.whitelist,example2.whitelist | Comma separated list of the clients which are in the whitelist pool | +| RATELIMITS_BLACKLIST_TOTAL_REQUESTS | | By default client names in the blacklist will be subject to 0 requests per hours. | +| RATELIMITS_BLACKLIST_EVERY_SECONDS | | By default client names in the blacklist will be subject to 0 requests per hours | +| RATELIMITS_BLACKLIST | example1.blacklist,example2.blacklist | Comma separated list of the clients which are in the blacklistpool. | + + + ## Author John Crepezzi From bae6387bb71bd3bffd28bbafc2ff38c3f665e84e Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 22:25:10 +0200 Subject: [PATCH 16/17] forgot to rename some vars --- docker-entrypoint.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docker-entrypoint.js b/docker-entrypoint.js index 05b29da..5afff14 100644 --- a/docker-entrypoint.js +++ b/docker-entrypoint.js @@ -12,10 +12,8 @@ const { STORAGE_DB, STORAGE_AWS_BUCKET, STORAGE_AWS_REGION, - STORAGE_PG_PASSWORD, - STORAGE_PG_USERNAME, - STORAGE_RETHINK_USER, - STORAGE_RETHINK_PASSWORD, + STORAGE_PASSWORD, + STORAGE_USERNAME, STORAGE_FILEPATH, LOGGING_LEVEL, LOGGING_TYPE, From 139df62ec4c3ca959db327e265751a740257f83b Mon Sep 17 00:00:00 2001 From: emil-lengman Date: Sat, 22 Aug 2020 22:27:05 +0200 Subject: [PATCH 17/17] add newline to stop github complaining --- docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 8e4e5a1..0b089d8 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -6,4 +6,4 @@ set -e node ./docker-entrypoint.js > ./config.js -exec "$@" \ No newline at end of file +exec "$@"