From 734b11c92657f5c4955f8ad2f290fae4ec21d3fd Mon Sep 17 00:00:00 2001 From: Alexander Wong Date: Mon, 7 Dec 2020 12:57:20 -0700 Subject: [PATCH] Added support for Docker, Docker-Compose - updated config.js template to support environment variables --- .dockerignore | 1 + Dockerfile | 15 +++++++++++++++ README.md | 10 ++++++++++ config.js.template | 38 +++++++++++++++++++------------------- docker-compose.yml | 24 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 19 deletions(-) create mode 120000 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..00ca38a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# Use LTS nodejs base image +FROM node:14.15.1-alpine + +# video support dependency +RUN apk add ffmpeg + +# install npm dependencies and copy project +WORKDIR /teddit +COPY package.json /teddit/ +COPY package-lock.json /teddit/ +RUN npm install --no-optional +COPY config.js.template /teddit/config.js +COPY . /teddit/ + +CMD npm start diff --git a/README.md b/README.md index 8b54e6d..ed2060d 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,16 @@ Community instances: ## Installation +### Docker + +Using [`docker-compose`](https://github.com/docker/compose): +```bash +docker-compose build +docker-compose up +``` + +### Manual + 1. Install [node.js](https://nodejs.org/en/) 1. It's highly recommended that you install [redis-server](https://redis.io/) because it works as a cache for Reddit API calls. If you want to support videos, install [ffmpeg](https://ffmpeg.org/)\ For example:\ diff --git a/config.js.template b/config.js.template index 4c0e8df..b0a442f 100644 --- a/config.js.template +++ b/config.js.template @@ -1,23 +1,23 @@ const config = { - domain: '127.0.0.1', // Or for example 'teddit.net' - reddit_app_id: 'H6-HjZ5pUPjaFQ', // You should obtain your own Reddit app ID. For testing purposes it's okay to use this project's default app ID. Create your Reddit app here: https://old.reddit.com/prefs/apps/. Make sure to create an "installed app" type of app. - cert_dir: '', // For example '/home/teddit/letsencrypt/live/teddit.net', if you are using https. No trailing slash. - video_enabled: true, - redis_enabled: true, // If disabled, does not cache Reddit API calls - redis_host: '127.0.0.1', - redis_port: 6379, - ssl_port: 8088, - nonssl_port: 8080, - listen_address: '0.0.0.0', - https_enabled: false, - redirect_http_to_https: false, - redirect_www: false, - use_compression: true, - use_view_cache: false, - use_helmet: false, // Recommended to be true when using https - use_helmet_hsts: false, // Recommended to be true when using https - trust_proxy: false, // Enable trust_proxy if you are using reverse proxy like nginx - trust_proxy_address: '127.0.0.1', + domain: process.env.DOMAIN || '127.0.0.1', // Or for example 'teddit.net' + reddit_app_id: process.env.REDDIT_APP_ID || 'H6-HjZ5pUPjaFQ', // You should obtain your own Reddit app ID. For testing purposes it's okay to use this project's default app ID. Create your Reddit app here: https://old.reddit.com/prefs/apps/. Make sure to create an "installed app" type of app. + cert_dir: process.env.CERT_DIR || '', // For example '/home/teddit/letsencrypt/live/teddit.net', if you are using https. No trailing slash. + video_enabled: process.env.VIDEO_ENABLED !== "true" || true, + redis_enabled: process.env.REDIS_ENABLED !== "true" || true, // If disabled, does not cache Reddit API calls + redis_host: process.env.REDIS_HOST || '127.0.0.1', + redis_port: process.env.REDIS_PORT || 6379, + ssl_port: process.env.SSL_PORT || 8088, + nonssl_port: process.env.NONSSL_PORT || 8080, + listen_address: process.env.LISTEN_ADDRESS || '0.0.0.0', + https_enabled: process.env.HTTPS_ENABLED === "true" || false, + redirect_http_to_https: process.env.REDIRECT_HTTP_TO_HTTPS === "true" || false, + redirect_www: process.env.REDIRECT_WWW === "true" || false, + use_compression: process.env.USE_COMPRESSION !== "true" || true, + use_view_cache: process.env.USE_VIEW_CACHE === "true" || false, + use_helmet: process.env.USE_HELMET === "true" || false, // Recommended to be true when using https + use_helmet_hsts: process.env.USE_HELMET_HSTS === "true" || false, // Recommended to be true when using https + trust_proxy: process.env.TRUST_PROXY === "true" || false, // Enable trust_proxy if you are using reverse proxy like nginx + trust_proxy_address: process.env.TRUST_PROXY_ADDRESS || '127.0.0.1', setexs: { /**, * Redis cache expiration values (in seconds). diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..77ec161 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3.8" + +services: + redis: + image: redis:6.0.9-alpine3.12 + command: redis-server + environment: + - REDIS_REPLICATION_MODE=master + ports: + - "6379:6379" + networks: + - teddit_net + web: + build: . + environment: + - REDIS_HOST=redis + ports: + - 8080:8080 + networks: + - teddit_net + depends_on: + - redis +networks: + teddit_net: