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 # The git tag, revision, or branch to check out on build
PLEROMA_VERSION=develop 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 FROM debian:9-slim
VOLUME /custom.d # Set up environment
EXPOSE 4000
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8 ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8 ENV LANG=C.UTF-8
# Register pseudo-entrypoint # Prepare mounts and entrypoint
ADD ./entrypoint.sh / VOLUME /custom.d
VOLUME /conf
COPY ./entrypoint.sh /
RUN chmod a+x /entrypoint.sh RUN chmod a+x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
# Get build dependencies # Expose default pleroma port to host
EXPOSE 4000
# Get erlang, elixir, and dependencies
RUN \ RUN \
apt-get update \ apt-get update \
&& apt-get install -y --no-install-recommends apt-utils \ && 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 \ && wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb \
&& dpkg -i erlang-solutions_1.0_all.deb \ && dpkg -i erlang-solutions_1.0_all.deb \
&& apt-get update \ && apt-get update \
&& apt-get install -y --no-install-recommends esl-erlang elixir \ && apt-get install -y --no-install-recommends esl-erlang elixir \
&& apt-get install -y ruby \
\ \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Limit permissions # Limit permissions
ARG DOCKER_UID ARG DOCKER_UID=1000
ARG DOCKER_GID ARG DOCKER_GID=1000
ARG PLEROMA_UPLOADS_PATH ARG PLEROMA_UPLOADS_PATH=/uploads
RUN \ RUN \
groupadd --gid ${DOCKER_GID} pleroma \ groupadd --gid ${DOCKER_GID} pleroma \
&& useradd -m -s /bin/bash --gid ${DOCKER_GID} --uid ${DOCKER_UID} pleroma \ && useradd -m -s /bin/bash --gid ${DOCKER_GID} --uid ${DOCKER_UID} pleroma \
&& mkdir -p /custom.d $PLEROMA_UPLOADS_PATH \ && 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 USER pleroma
WORKDIR /home/pleroma WORKDIR /home/pleroma
# Get pleroma # Get pleroma sources
RUN git clone --progress https://git.pleroma.social/pleroma/pleroma.git ./pleroma RUN git clone --progress https://git.pleroma.social/pleroma/pleroma.git ./pleroma
WORKDIR /home/pleroma/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 \ RUN \
mix local.hex --force \ mix local.hex --force \
&& mix local.rebar --force && mix local.rebar --force
# Bust the build cache
ARG __BUST_CACHE
ENV __BUST_CACHE $__BUST_CACHE
# Fetch changes, checkout # Fetch changes, checkout
ARG PLEROMA_VERSION ARG PLEROMA_VERSION
RUN \ RUN \
git fetch --all \ git fetch --all \
&& git checkout $PLEROMA_VERSION \ && git checkout $PLEROMA_VERSION \
@ -66,9 +72,12 @@ RUN \
mix deps.get \ mix deps.get \
&& mix compile && mix compile
# Insert overrides and config helper # Prepare runtime config
COPY --chown=pleroma:pleroma ./docker-config.exs /docker-config.exs
COPY --chown=pleroma:pleroma ./custom.d /home/pleroma/pleroma
RUN \ RUN \
ln -s /docker-config.exs config/prod.secret.exs \ ln -sf runtime-config.exs config/prod.secret.exs \
&& ln -s /docker-config.exs config/dev.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. # You can enter any config in here that you want.
# Pleroma-Docker will try to translate it into elixir for you. # 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: # <D> is a special prefix that causes a string to be passed <D>irectly without quoting.
# Bar.Baz: # Useful for referencing modules like Ecto adapters or other symbols that are usually wrapped in yaml.
# x: true
# #
# becomes `config :foo, Bar.Baz, x: true`. # Remember to take a look at your config with `./pleroma config`.
#
# 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: app:
# The loglevel to use in pleroma. # The loglevel to use in pleroma.
:logger: :logger:
level: info level: <D>:info
:pleroma: :pleroma:
Pleroma.Repo: Pleroma.Repo:
@ -32,6 +30,7 @@ app:
password: pleroma password: pleroma
database: pleroma database: pleroma
pool_size: 16 pool_size: 16
adapter: <D>Ecto.Adapters.Postgres
Pleroma.Web.Endpoint: Pleroma.Web.Endpoint:
# Location where your instance will be reachable. # Location where your instance will be reachable.

View File

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

View File

@ -4,7 +4,7 @@ set -e
set -x set -x
# Generate a config file # 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 # Recompile if needed
if [[ ! -z "$RECOMPILE" ]]; then if [[ ! -z "$RECOMPILE" ]]; then

41
pleroma
View File

@ -11,36 +11,38 @@ Usage:
$0 [action] $0 [action]
Actions: Actions:
build Rebuild the pleroma container. build Rebuild the pleroma container.
dump Dump the generated docker-compose.yml to stdout. config [file = config.yml] Print the generated pleroma config to stdout.
debug [bin] [args...] Launches a new pleroma container but uses \$bin instead of phx.server as entrypoint. dump Dump the generated docker-compose.yml to stdout.
**Warning**: This is intended for debugging pleroma with tools like :debugger and :observer.
It thus forwards your X-Server into docker and temporarily fiddles with your xhost
access controls. If this is a security concern for you, please export NO_X_FORWARDING=1
before launching a debugger session.
enter Spawn a shell inside the container for debugging/maintenance. debug [bin] [args...] Launches a new pleroma container but uses \$bin instead of phx.server as entrypoint.
This command does not link to the postgres container. **Warning**: This is intended for debugging pleroma with tools like :debugger and :observer.
If you need that use #debug instead. It thus forwards your X-Server into docker and temporarily fiddles with your xhost
access controls. If this is a security concern for you, please export NO_X_FORWARDING=1
before launching a debugger session.
logs Show the current container logs. enter Spawn a shell inside the container for debugging/maintenance.
This command does not link to the postgres container.
If you need that use #debug instead.
mix [task] [args...] Run a mix task without entering the container. logs Show the current container logs.
mod [file] Creates the file in custom.d and downloads the content from pleroma.social. mix [task] [args...] Run a mix task without entering the container.
The download respects your \$PLEROMA_VERSION from .env.
passthrough / p [...] Pass any custom command to docker-compose. mod [file] Creates the file in custom.d and downloads the content from pleroma.social.
The download respects your \$PLEROMA_VERSION from .env.
restart Executes #stop and #start respectively. passthrough / p [...] Pass any custom command to docker-compose.
start / up Start pleroma and sibling services. restart Executes #stop and #start respectively.
stop / down Stop pleroma and sibling services. start / up Start pleroma and sibling services.
status / ps Show the current container status. stop / down Stop pleroma and sibling services.
status / ps Show the current container status.
Environment: Environment:
DEBUG can be used to modify the loglevel. DEBUG can be used to modify the loglevel.
@ -91,6 +93,7 @@ load_env() {
} }
action__build() { docker_compose build --build-arg __BUST_CACHE="$(date +%s)" server; } 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__dump() { cat <(render_template); }
action__enter() { docker_compose exec server ash -c 'cd /pleroma && ash'; } action__enter() { docker_compose exec server ash -c 'cd /pleroma && ash'; }
action__logs() { docker_compose logs -f; } action__logs() { docker_compose logs -f; }