From 3b84dfd5cf3aa605b654f1dd9b757869e69d1b7b Mon Sep 17 00:00:00 2001 From: sn0w Date: Sun, 8 Apr 2018 17:04:06 +0200 Subject: [PATCH] Update env-config --- .env.dist | 1 + docker-compose.m4 | 7 ++++--- docker-config.exs | 47 +++++++++++++++++++++++++++------------------- pleroma.sh | 48 +++++++++++++++++++++++++---------------------- 4 files changed, 59 insertions(+), 44 deletions(-) diff --git a/.env.dist b/.env.dist index a126285..f74f5f2 100644 --- a/.env.dist +++ b/.env.dist @@ -23,3 +23,4 @@ PLEROMA_REGISTRATIONS_OPEN= PLEROMA_MEDIA_PROXY_ENABLED= PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE= PLEROMA_MEDIA_PROXY_URL= +PLEROMA_DB_POOL_SIZE= diff --git a/docker-compose.m4 b/docker-compose.m4 index c0f875b..308731c 100644 --- a/docker-compose.m4 +++ b/docker-compose.m4 @@ -1,7 +1,7 @@ divert(-1) define(`upcase', `translit($1, `a-z', `A-Z')') -define(`env', `upcase($1):${upcase($1):?upcase($1)}') -define(`env_fb', `upcase($1):-$2') +define(`env', `upcase($1): ${upcase($1):?upcase($1)}') +define(`env_fb', `upcase($1): ${upcase($1):-$2}') define(`env_inline', `${upcase($1):?upcase($1)}') divert(1)dnl @@ -31,7 +31,7 @@ services: links: - db environment: - env(`postgres_ip', `db') + env_fb(`postgres_ip', `db') env(`postgres_db') env(`postgres_user') env(`postgres_password') @@ -47,6 +47,7 @@ services: env(`pleroma_media_proxy_enabled') env(`pleroma_media_proxy_redirect_on_failure') env(`pleroma_media_proxy_url') + env(`pleroma_db_pool_size') env_fb(`pleroma_workspace', `/pleroma') env_fb(`mix_archives', `/mix/archives') diff --git a/docker-config.exs b/docker-config.exs index 45e5469..e98f76c 100644 --- a/docker-config.exs +++ b/docker-config.exs @@ -1,33 +1,42 @@ use Mix.Config -env = fn name -> - env_name = "pleroma_" <> Atom.to_string(name) |> String.upcase - System.get_env(env_name) || raise "Could not find #{env_name} in environment. Please define it and try again." +defmodule Docker do + def env(name, verbatim \\ false) do + env_name = (if verbatim, do: "", else: "pleroma_") <> Atom.to_string(name) |> String.upcase + env_var = System.get_env(env_name) + + if env_var == nil do + raise "Could not find #{env_name} in environment. Please define it and try again." + end + + System.put_env(env_name, "") + env_var + end end config :pleroma, Pleroma.Web.Endpoint, url: [ - host: env.(:url), - scheme: env.(:scheme), - port: env.(:port) + host: Docker.env(:url), + scheme: Docker.env(:scheme), + port: Docker.env(:port) ], - secret_key_base: env.(:secret_key_base) + secret_key_base: Docker.env(:secret_key_base) config :pleroma, :instance, - name: env.(:name), - email: env.(:admin_email), - limit: env.(:user_limit), - registrations_open: env.(:registrations_open) + name: Docker.env(:name), + email: Docker.env(:admin_email), + limit: Docker.env(:user_limit), + registrations_open: Docker.env(:registrations_open) config :pleroma, :media_proxy, - enabled: env.(:media_proxy_enabled), - redirect_on_failure: env.(:media_proxy_redirect_on_failure), - base_url: env.(:media_proxy_url) + 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: env.(:db_user), - password: env.(:db_pass), - database: env.(:db_name), - hostname: env.(:db_host), - pool_size: env.(:db_pool_size) + 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/pleroma.sh b/pleroma.sh index d6926ad..52c314d 100755 --- a/pleroma.sh +++ b/pleroma.sh @@ -23,79 +23,83 @@ function print_help { Pleroma Maintenance Script Usage: - $0 [action] [flags...] + $0 [action] [flags] Actions: build Build the pleroma container and all dependencies configure Runs the interactive configuration script run Start pleroma and sibling services stop Stop pleroma and sibling services + logs Show the current container logs " } function run_dockerized { - log_info "Stopping existing containers (if any)..." + log_info "Stopping existing containers (if any)" docker-compose down - log_info "Rebuilding images..." + log_info "Rebuilding images" docker-compose build - log_info "Running action '$1'..." + log_info "Running action '$1'" docker-compose run server $1 log_info "Cleaning up.." docker-compose down } -function action__pre { - m4 docker-compose.m4 > docker-compose.yml -} - -function action__post { - rm docker-compose.yml -} - function action__build { - action__pre run_dockerized "build" log_ok "Done" - action__post } function action__configure { - action__pre run_dockerized "configure" log_ok "Done" - action__post } function action__run { - action__pre - log_info "Booting pleroma..." + log_info "Booting pleroma" docker-compose up --remove-orphans -d log_ok "Done" - action__post } function action__stop { - action__pre - log_info "Stopping pleroma..." + log_info "Stopping pleroma" docker-compose down log_ok "Done" - action__post } +function action__logs { + docker-compose logs -f +} + +function prepare { + log_info "Preparing script" + m4 docker-compose.m4 > docker-compose.yml +} + +function cleanup { + log_info "Cleaning up" + rm docker-compose.yml +} + +trap "cleanup" INT TERM EXIT + if [[ -z "$1" ]]; then log_error "No action provided." print_help exit 1 fi +prepare + case "$1" in build) action__build;; configure) action__configure;; run) action__run;; stop) action__stop;; +logs) action__logs;; *) log_error "The action '$1' is invalid." print_help