Fix new config format

This commit is contained in:
sn0w 2018-12-28 01:44:33 +01:00
parent bdf83f7227
commit 3adfa6642f
6 changed files with 81 additions and 58 deletions

View File

@ -63,3 +63,7 @@ MIX_ENV=prod
# The git tag, revision, or branch to check out on build
PLEROMA_VERSION=develop
# Domain to run at (only relevant for traefik mode)
PLEROMA_URL=coolsite.moe
PLEROMA_MEDIA_PROXY_URL=cdn.coolsite.moe

View File

@ -1,61 +1,67 @@
FROM debian:9-slim
VOLUME /custom.d
EXPOSE 4000
# Set up environment
ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# Register pseudo-entrypoint
ADD ./entrypoint.sh /
# Prepare mounts and entrypoint
VOLUME /custom.d
VOLUME /conf
COPY ./entrypoint.sh /
RUN chmod a+x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# Get build dependencies
# Expose default pleroma port to host
EXPOSE 4000
# Get erlang, elixir, and dependencies
RUN \
apt-get update \
&& apt-get install -y --no-install-recommends apt-utils \
&& apt-get install -y --no-install-recommends git wget ca-certificates gnupg2 build-essential \
&& apt-get install -y --no-install-recommends git wget ca-certificates gnupg2 build-essential ruby \
\
&& wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb \
&& 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/*
# Limit permissions
ARG DOCKER_UID
ARG DOCKER_GID
ARG PLEROMA_UPLOADS_PATH
ARG DOCKER_UID=1000
ARG DOCKER_GID=1000
ARG PLEROMA_UPLOADS_PATH=/uploads
RUN \
groupadd --gid ${DOCKER_GID} pleroma \
&& useradd -m -s /bin/bash --gid ${DOCKER_GID} --uid ${DOCKER_UID} pleroma \
&& mkdir -p /custom.d $PLEROMA_UPLOADS_PATH \
&& chown -R pleroma:pleroma /custom.d $PLEROMA_UPLOADS_PATH
&& chown -R pleroma:pleroma /custom.d /conf $PLEROMA_UPLOADS_PATH
USER pleroma
WORKDIR /home/pleroma
# Get pleroma
# Get pleroma sources
RUN git clone --progress https://git.pleroma.social/pleroma/pleroma.git ./pleroma
WORKDIR /home/pleroma/pleroma
# Get rebar/hex
# Bust the build cache (if needed)
# This works by setting an environment variable with the last
# used version/branch/tag/commitish/... which originates in the script.
# If the host doesn't have the required tool for "smart version detection"
# we'll just use the current timestamp here which forces a rebuild every time.
ARG __BUST_CACHE
ENV __BUST_CACHE $__BUST_CACHE
# Get rebar and hex
RUN \
mix local.hex --force \
&& mix local.rebar --force
# Bust the build cache
ARG __BUST_CACHE
ENV __BUST_CACHE $__BUST_CACHE
# Fetch changes, checkout
ARG PLEROMA_VERSION
RUN \
git fetch --all \
&& git checkout $PLEROMA_VERSION \
@ -66,9 +72,12 @@ RUN \
mix deps.get \
&& mix compile
# Insert overrides and config helper
COPY --chown=pleroma:pleroma ./docker-config.exs /docker-config.exs
COPY --chown=pleroma:pleroma ./custom.d /home/pleroma/pleroma
# Prepare runtime config
RUN \
ln -s /docker-config.exs config/prod.secret.exs \
&& ln -s /docker-config.exs config/dev.secret.exs
ln -sf runtime-config.exs config/prod.secret.exs \
&& ln -sf runtime-config.exs config/dev.secret.exs
# Insert overrides
COPY --chown=pleroma:pleroma ./custom.d /home/pleroma/pleroma
# Recompiles at runtime if custom.d contained elixir code.

View File

@ -6,22 +6,20 @@ version: 1
# You can enter any config in here that you want.
# Pleroma-Docker will try to translate it into elixir for you.
#
# For example:
# <T> is a special member for modifying the YAML->Elixir translation.
# When set to `Array` it causes the generation of a "keyed array" literal instead
# of multiple named parameters to `config`.
#
# :foo:
# Bar.Baz:
# x: true
# <D> is a special prefix that causes a string to be passed <D>irectly without quoting.
# Useful for referencing modules like Ecto adapters or other symbols that are usually wrapped in yaml.
#
# 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).
# Remember to take a look at your config with `./pleroma config`.
#
app:
# The loglevel to use in pleroma.
:logger:
level: info
level: <D>:info
:pleroma:
Pleroma.Repo:
@ -32,6 +30,7 @@ app:
password: pleroma
database: pleroma
pool_size: 16
adapter: <D>Ecto.Adapters.Postgres
Pleroma.Web.Endpoint:
# Location where your instance will be reachable.

View File

@ -3,6 +3,14 @@
require 'yaml'
require 'json'
def getval(val)
if val.is_a?(String)
val.start_with?('<D>') ? val.delete('<D>') : val.to_json()
else
val.to_json()
end
end
config = YAML.load_file(ARGV[0])
if config["version"] != 1
@ -15,8 +23,8 @@ 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"
if !settings.is_a?(Hash)
buf += ": #{getval(settings)}\n"
next
end
@ -27,13 +35,13 @@ config["app"].each do |atom, content|
buf += ", #{name}: ["
value.each do |k, v|
buf += "#{k}: #{v.to_json},"
buf += "#{k}: #{getval(v)},"
end
buf.chop!
buf.chop!()
buf += "]"
else
buf += ", #{name}: #{value.to_json}"
buf += ", #{name}: #{getval(value)}"
end
end

View File

@ -4,7 +4,7 @@ set -e
set -x
# Generate a config file
ruby /config/parser.rb /config/config.yml > runtime-config.exs
ruby /conf/parser.rb /conf/config.yml > config/runtime-config.exs
# Recompile if needed
if [[ ! -z "$RECOMPILE" ]]; then

View File

@ -13,6 +13,8 @@ Usage:
Actions:
build Rebuild the pleroma container.
config [file = config.yml] Print the generated pleroma config to stdout.
dump Dump the generated docker-compose.yml to stdout.
debug [bin] [args...] Launches a new pleroma container but uses \$bin instead of phx.server as entrypoint.
@ -91,6 +93,7 @@ load_env() {
}
action__build() { docker_compose build --build-arg __BUST_CACHE="$(date +%s)" server; }
action__config() { docker run --rm -t -i -v $(pwd):/mnt ruby:alpine sh -c "cd /mnt && ruby config_parser/parser.rb ${1:-config.yml}"; }
action__dump() { cat <(render_template); }
action__enter() { docker_compose exec server ash -c 'cd /pleroma && ash'; }
action__logs() { docker_compose logs -f; }