]> Untitled Git - lemmy.git/commitdiff
update documentation, docker and ansible files
authorFelix Ableitner <me@nutomic.com>
Tue, 17 Dec 2019 21:35:48 +0000 (22:35 +0100)
committerFelix Ableitner <me@nutomic.com>
Fri, 27 Dec 2019 16:28:46 +0000 (17:28 +0100)
16 files changed:
.gitignore
README.md
ansible/lemmy.yml
ansible/templates/config.hjson [new file with mode: 0644]
ansible/templates/env
docker/dev/.env
docker/dev/Dockerfile
docker/dev/Dockerfile.aarch64
docker/dev/Dockerfile.armv7hf
docker/dev/Dockerfile.libc
docker/dev/config/config.hjson [new file with mode: 0644]
docker/dev/docker-compose.yml
docker/k8s/lemmy.yml
docker/prod/.env
docker/prod/docker-compose.yml
server/src/settings.rs

index 4cb8939f5f67c82a2011fa209332ca0f4b444ffe..e36af1295cd05c382da5a5c7b71f77dcb74d32af 100644 (file)
@@ -2,3 +2,4 @@ ansible/inventory
 ansible/passwords/
 build/
 .idea/
+docker/dev/config/config.hjson
index 0e8dd6014347fc7aa4018bd3c3d844f676ed7e20..fa35788d9c97aa581711b4c8e33b4cd2c580a1e1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -54,6 +54,7 @@ Front Page|Post
     + [Requirements](#requirements)
     + [Set up Postgres DB](#set-up-postgres-db)
     + [Running](#running)
+- [Configuration](#configuration)
 - [Documentation](#documentation)
 - [Support](#support)
 - [Translations](#translations)
@@ -222,6 +223,19 @@ cd lemmy
 # cd server && cargo watch -x run
 ```
 
+## Configuration
+
+The configuration is based on the file [defaults.hjson](server/config/defaults.hjson). This file also contains
+documentation for all the available options. To override the defaults, you can copy the options you want to change
+into your local `config.hjson` file. 
+
+Additionally, you can override any config files with environment variables. These have the same name as the config
+options, and are prefixed with `LEMMY_`. For example, you can override the `database.password` with 
+`LEMMY_DATABASE_PASSWORD=my_password`.
+
+An additional option `LEMMY_DATABASE_URL` is available, which can be used with a PostgreSQL connection string like
+`postgres://lemmy:password@lemmy_db:5432/lemmy`, passing all connection details at once.
+
 ## Documentation
 
 - [Websocket API for App developers](docs/api.md)
index 4ba80e90a4686a423e7ec75ceee134be8819a675..acdb6b06b09e16e8abf3786a8ee2bc25d22cf6d0 100644 (file)
@@ -33,6 +33,7 @@
     template: src={{item.src}} dest={{item.dest}}
     with_items:
       - { src: 'templates/env', dest: '/lemmy/.env' }
+      - { src: 'templates/config.hjson', dest: '/lemmy/config.hjson' }
       - { src: '../docker/prod/docker-compose.yml', dest: '/lemmy/docker-compose.yml' }
       - { src: 'templates/nginx.conf', dest: '/etc/nginx/sites-enabled/lemmy.conf' }
     vars:
diff --git a/ansible/templates/config.hjson b/ansible/templates/config.hjson
new file mode 100644 (file)
index 0000000..adfaf33
--- /dev/null
@@ -0,0 +1,13 @@
+{
+  database: {
+    password: "{{ postgres_password }}"
+  }
+  hostname: "{{ domain }}"
+  jwt_secret: "{{ jwt_password }}"
+  email: {
+    smtp_server: "{{ smtp_server }}"
+    smtp_login: "{{ smtp_login }}"
+    smtp_password: "{{ smtp_password }}"
+    smtp_from_address: "{{ smtp_from_address }}"
+  }
+}
index 22e9bedacc8949b1ee4a5f92bfde73e92d647e5e..c2b15f579f5853cd0658ad9488c4be689f237c10 100644 (file)
@@ -1,14 +1,2 @@
-DOMAIN={{ domain }}
 DATABASE_PASSWORD={{ postgres_password }}
-DATABASE_URL=postgres://lemmy:{{ postgres_password }}@lemmy_db:5432/lemmy
-JWT_SECRET={{ jwt_password }}
-RATE_LIMIT_MESSAGE=30
-RATE_LIMIT_MESSAGE_PER_SECOND=60
-RATE_LIMIT_POST=3
-RATE_LIMIT_POST_PER_SECOND=600
-RATE_LIMIT_REGISTER=3
-RATE_LIMIT_REGISTER_PER_SECOND=3600
-SMTP_SERVER={{ smtp_server }}
-SMTP_LOGIN={{ smtp_login }}
-SMTP_PASSWORD={{ smtp_password }}
-SMTP_FROM_ADDRESS={{ smtp_from_address }}
+LEMMY_FRONT_END_DIR=/app/dist
index 014ce5c33982bf16bdc758a394eb0150b3b0212a..4e1bf7f65f9deb3cc45d72ad28d3c7e0046c4ea6 100644 (file)
@@ -1,17 +1,5 @@
-DOMAIN=my_domain
-DATABASE_PASSWORD=password
-DATABASE_URL=postgres://lemmy:password@lemmy_db:5432/lemmy
-JWT_SECRET=changeme
-
-RATE_LIMIT_MESSAGE=30
-RATE_LIMIT_MESSAGE_PER_SECOND=60
-RATE_LIMIT_POST=6
-RATE_LIMIT_POST_PER_SECOND=600
-RATE_LIMIT_REGISTER=3
-RATE_LIMIT_REGISTER_PER_SECOND=3600
-
-# Optional email fields
-SMTP_SERVER=
-SMTP_LOGIN=
-SMTP_PASSWORD=
-SMTP_FROM_ADDRESS=Domain.com Lemmy Admin <notifications@domain.com>
+LEMMY_DOMAIN=my_domain
+LEMMY_DATABASE_PASSWORD=password
+LEMMY_DATABASE_URL=postgres://lemmy:password@lemmy_db:5432/lemmy
+LEMMY_JWT_SECRET=changeme
+LEMMY_FRONT_END_DIR=/app/dist
index 203643e1d8143bfc6d1aa3948ca79bfcb3362315..080b7fb3e938ac3c70a39ce15fee8b53ca6c25f8 100644 (file)
@@ -38,8 +38,10 @@ FROM alpine:3.10
 RUN apk add libpq
 
 # Copy resources
+COPY server/config /config
 COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
 COPY --from=node /app/ui/dist /app/dist
+
 RUN addgroup -g 1000 lemmy
 RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
 RUN chown lemmy:lemmy /app/lemmy
index dbbafbd383dbc6ffd5f24fa19d7cf1fb36ee3c60..1b08c64e57cf5f850b35b2ce73d615800aefa3ad 100644 (file)
@@ -69,6 +69,7 @@ RUN addgroup --gid 1000 lemmy
 RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
 
 # Copy resources
+COPY server/config /app/config
 COPY --from=rust /app/server/ready /app/lemmy
 COPY --from=node /app/ui/dist /app/dist
 
index 3770dfd71c38fd76b362ab637b5da7f8aebf8eb1..67067a18a45c9d0b74d332858f726f4aed841988 100644 (file)
@@ -69,6 +69,7 @@ RUN addgroup --gid 1000 lemmy
 RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
 
 # Copy resources
+COPY server/config /config
 COPY --from=rust /app/server/ready /app/lemmy
 COPY --from=node /app/ui/dist /app/dist
 
index 3603d5287b97205ce16f27f3cb2a7703c967b1ef..22d8d910043434635cb7c39cd30038e690c9c713 100644 (file)
@@ -65,8 +65,10 @@ RUN addgroup --gid 1000 lemmy
 RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
 
 # Copy resources
+COPY server/config /app/config
 COPY --from=rust /app/server/ready /app/lemmy
 COPY --from=node /app/ui/dist /app/dist
+
 RUN chown lemmy:lemmy /app/lemmy
 USER lemmy
 EXPOSE 8536
diff --git a/docker/dev/config/config.hjson b/docker/dev/config/config.hjson
new file mode 100644 (file)
index 0000000..2c63c08
--- /dev/null
@@ -0,0 +1,2 @@
+{
+}
index 4f8e536442c1e446672852dcc780b2f6abf98aff..92a8ee45096dea6116166589e7aa8a90f969c8c9 100644 (file)
@@ -5,7 +5,7 @@ services:
     image: postgres:12-alpine
     environment:
       - POSTGRES_USER=lemmy
-      - POSTGRES_PASSWORD=${DATABASE_PASSWORD}
+      - POSTGRES_PASSWORD=${LEMMY_DATABASE_PASSWORD}
       - POSTGRES_DB=lemmy
     volumes:
       - lemmy_db:/var/lib/postgresql/data
@@ -16,22 +16,11 @@ services:
       dockerfile: docker/dev/Dockerfile
     ports:
       - "127.0.0.1:8536:8536"
-    environment:
-      - LEMMY_FRONT_END_DIR=/app/dist
-      - DATABASE_URL=${DATABASE_URL}
-      - JWT_SECRET=${JWT_SECRET}
-      - HOSTNAME=${DOMAIN}
-      - RATE_LIMIT_MESSAGE=${RATE_LIMIT_MESSAGE}
-      - RATE_LIMIT_MESSAGE_PER_SECOND=${RATE_LIMIT_MESSAGE_PER_SECOND}
-      - RATE_LIMIT_POST=${RATE_LIMIT_POST}
-      - RATE_LIMIT_POST_PER_SECOND=${RATE_LIMIT_POST_PER_SECOND}
-      - RATE_LIMIT_REGISTER=${RATE_LIMIT_REGISTER}
-      - RATE_LIMIT_REGISTER_PER_SECOND=${RATE_LIMIT_REGISTER_PER_SECOND}
-      - SMTP_SERVER=${SMTP_SERVER}
-      - SMTP_LOGIN=${SMTP_LOGIN}
-      - SMTP_PASSWORD=${SMTP_PASSWORD}
-      - SMTP_FROM_ADDRESS=${SMTP_FROM_ADDRESS}
+    env_file:
+      - .env
     restart: always
+    volumes:
+      - ./config/config.hjson:/config/config.hjson:ro
     depends_on: 
       - lemmy_db
   lemmy_pictshare:
index f05b172e8112d3fe4cda8da7d223f777259f15e8..8e105d605bca7df723b376400589ecaf8afe6fc9 100644 (file)
@@ -14,13 +14,13 @@ spec:
     spec:
       containers:
       - env:
-        - name: DATABASE_URL
+        - name: LEMMY_DATABASE_URL
           # example: 'postgres://lemmy:password@db:5432/lemmy'
           value: CHANGE_ME
-        - name: HOSTNAME
+        - name: LEMMY_HOSTNAME
           # example: 'lemmy.example.com'
           value: CHANGE_ME
-        - name: JWT_SECRET
+        - name: LEMMY_JWT_SECRET
           # example: 'very-super-good-secret'
           value: CHANGE_ME
         - name: LEMMY_FRONT_END_DIR
index 014ce5c33982bf16bdc758a394eb0150b3b0212a..4e1bf7f65f9deb3cc45d72ad28d3c7e0046c4ea6 100644 (file)
@@ -1,17 +1,5 @@
-DOMAIN=my_domain
-DATABASE_PASSWORD=password
-DATABASE_URL=postgres://lemmy:password@lemmy_db:5432/lemmy
-JWT_SECRET=changeme
-
-RATE_LIMIT_MESSAGE=30
-RATE_LIMIT_MESSAGE_PER_SECOND=60
-RATE_LIMIT_POST=6
-RATE_LIMIT_POST_PER_SECOND=600
-RATE_LIMIT_REGISTER=3
-RATE_LIMIT_REGISTER_PER_SECOND=3600
-
-# Optional email fields
-SMTP_SERVER=
-SMTP_LOGIN=
-SMTP_PASSWORD=
-SMTP_FROM_ADDRESS=Domain.com Lemmy Admin <notifications@domain.com>
+LEMMY_DOMAIN=my_domain
+LEMMY_DATABASE_PASSWORD=password
+LEMMY_DATABASE_URL=postgres://lemmy:password@lemmy_db:5432/lemmy
+LEMMY_JWT_SECRET=changeme
+LEMMY_FRONT_END_DIR=/app/dist
index 56a9053467b969247f2dd979826a1d5d809b6f22..9df9f19a13618cc693d137945bc9bb068d83924a 100644 (file)
@@ -14,22 +14,11 @@ services:
     image: dessalines/lemmy:v0.5.0.3
     ports:
       - "127.0.0.1:8536:8536"
-    environment:
-      - LEMMY_FRONT_END_DIR=/app/dist
-      - DATABASE_URL=${DATABASE_URL}
-      - JWT_SECRET=${JWT_SECRET}
-      - HOSTNAME=${DOMAIN}
-      - RATE_LIMIT_MESSAGE=${RATE_LIMIT_MESSAGE}
-      - RATE_LIMIT_MESSAGE_PER_SECOND=${RATE_LIMIT_MESSAGE_PER_SECOND}
-      - RATE_LIMIT_POST=${RATE_LIMIT_POST}
-      - RATE_LIMIT_POST_PER_SECOND=${RATE_LIMIT_POST_PER_SECOND}
-      - RATE_LIMIT_REGISTER=${RATE_LIMIT_REGISTER}
-      - RATE_LIMIT_REGISTER_PER_SECOND=${RATE_LIMIT_REGISTER_PER_SECOND}
-      - SMTP_SERVER=${SMTP_SERVER}
-      - SMTP_LOGIN=${SMTP_LOGIN}
-      - SMTP_PASSWORD=${SMTP_PASSWORD}
-      - SMTP_FROM_ADDRESS=${SMTP_FROM_ADDRESS}
+    env_file:
+      - .env
     restart: always
+    volumes:
+      - ./config.hjson:/config/config.hjson:ro
     depends_on:
       - lemmy_db
   lemmy_pictshare:
index 7d558c5e17579a32d539085d99043cb34a26c79e..a7203a1eea0568446a1452141bdd548f6bbfbb28 100644 (file)
@@ -5,7 +5,7 @@ use std::env;
 use std::net::IpAddr;
 
 static CONFIG_FILE_DEFAULTS: &str = "config/defaults.hjson";
-static CONFIG_FILE_COSTUMIZED: &str = "config/custom.hjson";
+static CONFIG_FILE: &str = "config/config.hjson";
 
 #[derive(Debug, Deserialize)]
 pub struct Settings {
@@ -59,21 +59,18 @@ impl Settings {
   
   /// Reads config from the files and environment.
   /// First, defaults are loaded from CONFIG_FILE_DEFAULTS, then these values can be overwritten
-  /// from CONFIG_FILE_COSTUMIZED (optional). Finally, values from the environment
-  /// (with prefix LEMMY) are added to the config.
+  /// from CONFIG_FILE (optional). Finally, values from the environment (with prefix LEMMY) are
+  /// added to the config.
   fn init() -> Result<Self, ConfigError> {
     let mut s = Config::new();
 
-    // Start off by merging in the "default" configuration file
     s.merge(File::with_name(CONFIG_FILE_DEFAULTS))?;
 
-    // TODO: we could also automatically load dev/prod configs based on environment
-    // https://github.com/mehcode/config-rs/blob/master/examples/hierarchical-env/src/settings.rs#L49
-    s.merge(File::with_name(CONFIG_FILE_COSTUMIZED).required(false))?;
+    s.merge(File::with_name(CONFIG_FILE).required(false))?;
 
     // Add in settings from the environment (with a prefix of LEMMY)
     // Eg.. `LEMMY_DEBUG=1 ./target/app` would set the `debug` key
-    s.merge(Environment::with_prefix("LEMMY"))?;
+    s.merge(Environment::with_prefix("LEMMY").separator("_"))?;
 
     return s.try_into();
   }