Update env-config

This commit is contained in:
sn0w 2018-04-08 17:04:06 +02:00
parent 5f59cfd9ae
commit 3b84dfd5cf
4 changed files with 59 additions and 44 deletions

View File

@ -23,3 +23,4 @@ PLEROMA_REGISTRATIONS_OPEN=
PLEROMA_MEDIA_PROXY_ENABLED= PLEROMA_MEDIA_PROXY_ENABLED=
PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE= PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE=
PLEROMA_MEDIA_PROXY_URL= PLEROMA_MEDIA_PROXY_URL=
PLEROMA_DB_POOL_SIZE=

View File

@ -1,7 +1,7 @@
divert(-1) divert(-1)
define(`upcase', `translit($1, `a-z', `A-Z')') define(`upcase', `translit($1, `a-z', `A-Z')')
define(`env', `upcase($1):${upcase($1):?upcase($1)}') define(`env', `upcase($1): ${upcase($1):?upcase($1)}')
define(`env_fb', `upcase($1):-$2') define(`env_fb', `upcase($1): ${upcase($1):-$2}')
define(`env_inline', `${upcase($1):?upcase($1)}') define(`env_inline', `${upcase($1):?upcase($1)}')
divert(1)dnl divert(1)dnl
@ -31,7 +31,7 @@ services:
links: links:
- db - db
environment: environment:
env(`postgres_ip', `db') env_fb(`postgres_ip', `db')
env(`postgres_db') env(`postgres_db')
env(`postgres_user') env(`postgres_user')
env(`postgres_password') env(`postgres_password')
@ -47,6 +47,7 @@ services:
env(`pleroma_media_proxy_enabled') env(`pleroma_media_proxy_enabled')
env(`pleroma_media_proxy_redirect_on_failure') env(`pleroma_media_proxy_redirect_on_failure')
env(`pleroma_media_proxy_url') env(`pleroma_media_proxy_url')
env(`pleroma_db_pool_size')
env_fb(`pleroma_workspace', `/pleroma') env_fb(`pleroma_workspace', `/pleroma')
env_fb(`mix_archives', `/mix/archives') env_fb(`mix_archives', `/mix/archives')

View File

@ -1,33 +1,42 @@
use Mix.Config use Mix.Config
env = fn name -> defmodule Docker do
env_name = "pleroma_" <> Atom.to_string(name) |> String.upcase def env(name, verbatim \\ false) do
System.get_env(env_name) || raise "Could not find #{env_name} in environment. Please define it and try again." 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 end
config :pleroma, Pleroma.Web.Endpoint, config :pleroma, Pleroma.Web.Endpoint,
url: [ url: [
host: env.(:url), host: Docker.env(:url),
scheme: env.(:scheme), scheme: Docker.env(:scheme),
port: env.(:port) port: Docker.env(:port)
], ],
secret_key_base: env.(:secret_key_base) secret_key_base: Docker.env(:secret_key_base)
config :pleroma, :instance, config :pleroma, :instance,
name: env.(:name), name: Docker.env(:name),
email: env.(:admin_email), email: Docker.env(:admin_email),
limit: env.(:user_limit), limit: Docker.env(:user_limit),
registrations_open: env.(:registrations_open) registrations_open: Docker.env(:registrations_open)
config :pleroma, :media_proxy, config :pleroma, :media_proxy,
enabled: env.(:media_proxy_enabled), enabled: Docker.env(:media_proxy_enabled),
redirect_on_failure: env.(:media_proxy_redirect_on_failure), redirect_on_failure: Docker.env(:media_proxy_redirect_on_failure),
base_url: env.(:media_proxy_url) base_url: Docker.env(:media_proxy_url)
config :pleroma, Pleroma.Repo, config :pleroma, Pleroma.Repo,
adapter: Ecto.Adapters.Postgres, adapter: Ecto.Adapters.Postgres,
username: env.(:db_user), username: Docker.env(:postgres_user, true),
password: env.(:db_pass), password: Docker.env(:postgres_password, true),
database: env.(:db_name), database: Docker.env(:postgres_db, true),
hostname: env.(:db_host), hostname: Docker.env(:postgres_ip, true),
pool_size: env.(:db_pool_size) pool_size: Docker.env(:db_pool_size)

View File

@ -23,79 +23,83 @@ function print_help {
Pleroma Maintenance Script Pleroma Maintenance Script
Usage: Usage:
$0 [action] [flags...] $0 [action] [flags]
Actions: Actions:
build Build the pleroma container and all dependencies build Build the pleroma container and all dependencies
configure Runs the interactive configuration script configure Runs the interactive configuration script
run Start pleroma and sibling services run Start pleroma and sibling services
stop Stop pleroma and sibling services stop Stop pleroma and sibling services
logs Show the current container logs
" "
} }
function run_dockerized { function run_dockerized {
log_info "Stopping existing containers (if any)..." log_info "Stopping existing containers (if any)"
docker-compose down docker-compose down
log_info "Rebuilding images..." log_info "Rebuilding images"
docker-compose build docker-compose build
log_info "Running action '$1'..." log_info "Running action '$1'"
docker-compose run server $1 docker-compose run server $1
log_info "Cleaning up.." log_info "Cleaning up.."
docker-compose down docker-compose down
} }
function action__pre {
m4 docker-compose.m4 > docker-compose.yml
}
function action__post {
rm docker-compose.yml
}
function action__build { function action__build {
action__pre
run_dockerized "build" run_dockerized "build"
log_ok "Done" log_ok "Done"
action__post
} }
function action__configure { function action__configure {
action__pre
run_dockerized "configure" run_dockerized "configure"
log_ok "Done" log_ok "Done"
action__post
} }
function action__run { function action__run {
action__pre log_info "Booting pleroma"
log_info "Booting pleroma..."
docker-compose up --remove-orphans -d docker-compose up --remove-orphans -d
log_ok "Done" log_ok "Done"
action__post
} }
function action__stop { function action__stop {
action__pre log_info "Stopping pleroma"
log_info "Stopping pleroma..."
docker-compose down docker-compose down
log_ok "Done" 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 if [[ -z "$1" ]]; then
log_error "No action provided." log_error "No action provided."
print_help print_help
exit 1 exit 1
fi fi
prepare
case "$1" in case "$1" in
build) action__build;; build) action__build;;
configure) action__configure;; configure) action__configure;;
run) action__run;; run) action__run;;
stop) action__stop;; stop) action__stop;;
logs) action__logs;;
*) *)
log_error "The action '$1' is invalid." log_error "The action '$1' is invalid."
print_help print_help