From 5c9107b67fff5d03ca8ad05fd255bc369b1db4d8 Mon Sep 17 00:00:00 2001 From: sn0w Date: Mon, 24 Dec 2018 23:20:17 +0100 Subject: [PATCH] Start progress on new config --- .env.dist | 70 +------------------------ Dockerfile | 1 + config.dist.yml | 111 ++++++++++++++++++++++++++++++++++++++++ config_parser/parser.rb | 44 ++++++++++++++++ docker-compose.m4 | 27 ++-------- docker-config.exs | 71 ------------------------- entrypoint.sh | 13 ++++- 7 files changed, 174 insertions(+), 163 deletions(-) create mode 100644 config.dist.yml create mode 100755 config_parser/parser.rb delete mode 100644 docker-config.exs diff --git a/.env.dist b/.env.dist index 51013f6..113a0e8 100644 --- a/.env.dist +++ b/.env.dist @@ -1,18 +1,3 @@ -# -# Note: The values of this file that are passed directly to -# pleroma need type hints to be applied correctly. -# The implemented types are int, bool, and string. -# Typed variables look like this: KEY=type:VALUE. -# Not specifying a type implies a string. -# -# In general: Your instance should work as expected if you leave the types as they are. -# That is: don't remove them, don't add them, don't change them. -# Always just change the values. -# -# You don't need to escape colons in your strings. -# PLEROMA_NAME=string:std::pleroma::coolinstance will work as expected. -# - ######################### # Script settings # ######################### @@ -62,15 +47,12 @@ DOCKER_GID=1000 # Database settings # ########################### -# Leave POSTGRES_IP empty unless you plan to install your own database -# Leave the POSTGRES_DB, POSTGRES_USER and POSTGRES_PASSWORD as-is -# unless you use your own database. +# When you use the managed postgres container +# those will be the credentials the container is generated with. -POSTGRES_IP= POSTGRES_DB=pleroma POSTGRES_USER=pleroma POSTGRES_PASSWORD=pleroma -PLEROMA_DB_POOL_SIZE=int:16 ########################## # Pleroma Settings # @@ -81,51 +63,3 @@ MIX_ENV=prod # The git tag, revision, or branch to check out on build PLEROMA_VERSION=develop - -# The loglevel to use -# (error/warn/info/debug) -PLEROMA_LOGLEVEL=error - -# The domain/scheme where pleroma will be hosted -# URL is a bare TLD -# SCHEME is the protocol without "://" -# PORT is the *external* port (ie that of your reverse proxy) -PLEROMA_URL=coolsite.moe -PLEROMA_SCHEME=https -PLEROMA_PORT=int:443 - -# The seed for your secret keys -# (Enter something as random as possible) -# (On linux you can try something like "dd if=/dev/urandom bs=1 count=64 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev") -PLEROMA_SECRET_KEY_BASE= - -# The name of your instance -# (This is displayed in the top-left in pleroma-fe) -PLEROMA_NAME=string:coolInstance - -# Your contact info -PLEROMA_ADMIN_EMAIL=admin@coolsite.moe - -# How many chars a notice may have at max. -PLEROMA_MAX_NOTICE_CHARS=int:500 - -# Whether your instance accepts new users or not (true/false) -PLEROMA_REGISTRATIONS_OPEN=bool:true - -# Enable media proxy (true/false)? -PLEROMA_MEDIA_PROXY_ENABLED=bool:false - -# The url of your media proxy (if enabled) [with "http(s)://"] -PLEROMA_MEDIA_PROXY_URL=string:https://cdn.coolsite.moe - -# Redirect to source on cache fail? -PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE=bool:true - -# Whether to enable the chat feature or not -PLEROMA_CHAT_ENABLED=bool:true - -# Where to store uploads. -# This is only relevant inside the container. -# The host path is always $DOCKER_DATADIR/uploads. -# So, you probably don't need to change this. -PLEROMA_UPLOADS_PATH=/uploads diff --git a/Dockerfile b/Dockerfile index cbaabbd..5050680 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,7 @@ RUN \ && dpkg -i erlang-solutions_1.0_all.deb \ && apt-get update \ && apt-get install -y --no-install-recommends esl-erlang elixir \ + && apt-get install -y ruby \ \ && rm -rf /var/lib/apt/lists/* diff --git a/config.dist.yml b/config.dist.yml new file mode 100644 index 0000000..14d94a9 --- /dev/null +++ b/config.dist.yml @@ -0,0 +1,111 @@ +version: 1 + +# +# Pleroma settings +# +# You can enter any config in here that you want. +# Pleroma-Docker will try to translate it into elixir for you. +# +# For example: +# +# :foo: +# Bar.Baz: +# x: true +# +# becomes `config :foo, Bar.Baz, x: true`. +# +# It is assumed that all config keys that have to be passed through to +# pleroma must start with an atom on the first layer (eg :pleroma). +# + +app: + # The loglevel to use in pleroma. + :logger: + level: info + + :pleroma: + Pleroma.Repo: + # Credentials for your database. + # You should leave this as-is if you want to use the managed db container. + hostname: db + username: pleroma + password: pleroma + database: pleroma + pool_size: 16 + + Pleroma.Web.Endpoint: + # Location where your instance will be reachable. + url: + : Array + scheme: https + host: coolsite.moe + port: 443 + + # Base for your secret keys. + # Better make this random. + secret_key_base: asdf0815 + + Pleroma.Upload: + # Where to store your uploads. + # You should probably leave this as-is. + # /uploads will be mounted into ::docker::datadir. + uploads: /uploads + + # Remove metadata from uploads? + strip_exif: true + + :chat: + # Enable chat functionality? + enabled: true + + :media_proxy: + # Enable the proxy? + enabled: true + + # Emit a 302 to the original resource when uncached? + redirect_on_failure: true + + # Where your proxy is reachable + base_url: https://media.coolsite.moe + + :instance: + # The name of your instance. + name: super cool stuff club + + # Short description of your instance + description: we do super cool stuff in super cool stuff club + + # The admin's email address. + email: admin@coolsite.moe + + # How many chars a notice may have at max. + limit: 4096 + + # May new members sign up? + registrations_open: true + + # Allow connections to other instances? + # (Turn this off for testing) + federating: true + + # The rewrite policies / quarantines to enable. + # This is a powerful feature which should be used with care. + # Take a look at https://git.pleroma.social/pleroma/pleroma/wikis/Message%20rewrite%20facility%20configuration%20(how%20to%20block%20instances). + # Then uncomment only the things you really need + + # quarantined_instances: + # - badguys.moe + + # rewrite_policy: + # - Pleroma.Web.ActivityPub.MRF.SimplePolicy + + # :mrf_simple: + # media_removal: + # - illegalporn.biz + # media_nsfw: + # - porn.biz + # - porn.business + # reject: + # - spam.com + # federated_timeline_removal: + # - spam.university diff --git a/config_parser/parser.rb b/config_parser/parser.rb new file mode 100755 index 0000000..96f1972 --- /dev/null +++ b/config_parser/parser.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + +require 'yaml' +require 'json' + +config = YAML.load_file(ARGV[0]) + +if config["version"] != 1 + raise "Incompatible config version (#{config["version"]} != 1)" +end + +buf = "use Mix.Config\n\n" + +config["app"].each do |atom, content| + content.each do |sub, settings| + buf += "config :#{atom}, #{sub.is_a?(Symbol) ? ":#{sub}" : sub}" + + if !settings.is_a? Hash + buf += ": #{settings.to_json}\n" + next + end + + settings.each do |name, value| + if value.is_a?(Hash) && value[""] == "Array" + value.delete("") + + buf += ", #{name}: [" + + value.each do |k, v| + buf += "#{k}: #{v.to_json}," + end + buf.chop! + + buf += "]" + else + buf += ", #{name}: #{value.to_json}" + end + end + + buf += "\n" + end +end + +puts buf diff --git a/docker-compose.m4 b/docker-compose.m4 index 1a1b155..d3c445d 100644 --- a/docker-compose.m4 +++ b/docker-compose.m4 @@ -88,7 +88,7 @@ define(, <${upcase($1):-$2}>) "env()", "env()", "env()", - "env_fb(, )", + "env_fb(, )" ] }, "restart": "unless-stopped", @@ -96,31 +96,12 @@ define(, <${upcase($1):-$2}>) ifelse(__SCRIPT_DEPLOY_POSTGRES, true, <"db">) ], "environment": [ - "env_fb(, )", - - "env_fb(, )", - "env()", - "env()", - "env()", - - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env()", - "env_fb(, )" + "env_fb(, )" ], "volumes": [ "./custom.d:/custom.d", + "./config.yml:/conf/config.yml:ro", + "./config_parser/parser.rb:/conf/parser.rb:ro", "env_inline()/uploads:env_inline_fb(, )" ], "labels": [ diff --git a/docker-config.exs b/docker-config.exs deleted file mode 100644 index 5207e38..0000000 --- a/docker-config.exs +++ /dev/null @@ -1,71 +0,0 @@ -use Mix.Config - -defmodule Docker do - def env(shortname, verbatim \\ false) do - # Get var - name = ((if verbatim, do: "", else: "pleroma_") <> Atom.to_string(shortname)) |> String.upcase() - raw_var = System.get_env(name) - - if raw_var == nil do - raise "Could not find #{name} in environment. Please define it and try again." - end - - # Match type and cast if needed - if String.contains?(raw_var, ":") do - var_parts = String.split(raw_var, ":", parts: 2) - - type = Enum.at(var_parts, 0) - var = Enum.at(var_parts, 1) - - func = case type do - "int" -> fn(x) -> Integer.parse(x) |> elem(0) end - "bool" -> fn(x) -> x == "true" end - "string" -> fn(x) -> x end - _ -> if verbatim do - fn(x) -> x end - else - raise "Unknown type #{type} used in variable #{raw_var}." - end - end - - func.(var) - else - raw_var - end - end -end - -config :logger, level: String.to_atom(Docker.env(:loglevel) || "info") - -config :pleroma, Pleroma.Web.Endpoint, - url: [ - host: Docker.env(:url), - scheme: Docker.env(:scheme), - port: Docker.env(:port) - ], - secret_key_base: Docker.env(:secret_key_base) - -config :pleroma, Pleroma.Upload, - uploads: Docker.env(:uploads_path) - -config :pleroma, :chat, - enabled: Docker.env(:chat_enabled) - -config :pleroma, :instance, - name: Docker.env(:name), - email: Docker.env(:admin_email), - limit: Docker.env(:max_notice_chars), - registrations_open: Docker.env(:registrations_open) - -config :pleroma, :media_proxy, - enabled: Docker.env(:media_proxy_enabled), - redirect_on_failure: Docker.env(:media_proxy_redirect_on_failure), - base_url: Docker.env(:media_proxy_url) - -config :pleroma, Pleroma.Repo, - adapter: Ecto.Adapters.Postgres, - username: Docker.env(:postgres_user, true), - password: Docker.env(:postgres_password, true), - database: Docker.env(:postgres_db, true), - hostname: Docker.env(:postgres_ip, true), - pool_size: Docker.env(:db_pool_size) diff --git a/entrypoint.sh b/entrypoint.sh index 35f5365..be5fc93 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,7 +3,18 @@ set -e set -x -mix deps.get +# Generate a config file +ruby /config/parser.rb /config/config.yml > runtime-config.exs + +# Recompile if needed +if [[ ! -z "$RECOMPILE" ]]; then + mix deps.get + mix compile +fi + +# Migrate db mix ecto.create mix ecto.migrate + +# Off we go! exec mix phx.server