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_REDIRECT_ON_FAILURE=
PLEROMA_MEDIA_PROXY_URL=
PLEROMA_DB_POOL_SIZE=

View File

@ -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')

View File

@ -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)

View File

@ -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