ok this is emberassing

Fixes the caching problem and configuration madness.
Startup on a migrated database takes about 1 to 3 seconds instead of
minutes now. I don't know what went through my head when building
the old stuff.

Let's just pretend all commits up until here never happended.
We good? nice~
This commit is contained in:
sn0w 2019-01-09 21:23:53 +01:00
parent 307d6b01d9
commit 04432bfc8a
No known key found for this signature in database
GPG Key ID: DDEDFB9D3FA15727
8 changed files with 85 additions and 220 deletions

View File

@ -1,13 +1,13 @@
FROM debian:9-slim
# Set up environment
ENV MIX_ENV=prod
ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# Prepare mounts
VOLUME /custom.d
VOLUME /conf
# Expose default pleroma port to host
EXPOSE 4000
@ -39,7 +39,7 @@ 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 /conf $PLEROMA_UPLOADS_PATH
&& chown -R pleroma:pleroma /custom.d $PLEROMA_UPLOADS_PATH
USER pleroma
WORKDIR /home/pleroma
@ -56,11 +56,6 @@ WORKDIR /home/pleroma/pleroma
ARG __BUST_CACHE
ENV __BUST_CACHE $__BUST_CACHE
# Get rebar and hex
RUN \
mix local.hex --force \
&& mix local.rebar --force
# Fetch changes, checkout
ARG PLEROMA_VERSION
RUN \
@ -70,12 +65,9 @@ RUN \
# Precompile
RUN \
NO_CONFIG=1 COMPILE_ONLY=1 /entrypoint.sh
# Prepare runtime config
RUN \
ln -sf runtime-config.exs config/prod.secret.exs \
&& ln -sf runtime-config.exs config/dev.secret.exs
cp ./config/dev.exs ./config/prod.secret.exs \
&& BUILDTIME=1 /entrypoint.sh \
&& rm ./config/prod.secret.exs
# Insert overrides
COPY --chown=pleroma:pleroma ./custom.d /home/pleroma/pleroma

14
config.dist.exs Normal file
View File

@ -0,0 +1,14 @@
use Mix.Config
# pleroma/pleroma/pleroma are the default credentials for the
# managed database container. "db" is the default interlinked hostname.
# You shouldn't need to change this unless you modifed .env
config :pleroma, Pleroma.Repo,
adapter: Ecto.Adapters.Postgres,
username: "pleroma",
password: "pleroma",
database: "pleroma",
hostname: "db",
pool_size: 10
# vvv Your awesome config options go here vvv

View File

@ -1,110 +0,0 @@
version: 1
#
# Pleroma settings
#
# You can enter any config in here that you want.
# Pleroma-Docker will try to translate it into elixir for you.
#
# <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`.
#
# <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.
#
# Remember to take a look at your config with `./pleroma config`.
#
app:
# The loglevel to use in pleroma.
:logger:
level: <D>:info
:pleroma:
Pleroma.Repo:
# Credentials for your database.
# You should leave this as-is if you want to use the managed db container.
hostname: db
username: pleroma
password: pleroma
database: pleroma
pool_size: 16
adapter: <D>Ecto.Adapters.Postgres
Pleroma.Web.Endpoint:
# Location where your instance will be reachable.
url:
<T>: Array
scheme: https
host: coolsite.moe
port: 443
# Base for your secret keys.
# Better make this random.
secret_key_base: asdf0815
Pleroma.Upload:
# Where to store your uploads.
# You should probably leave this as-is.
# /uploads will be mounted into ::docker::datadir.
uploads: /uploads
# Remove metadata from uploads?
strip_exif: true
:chat:
# Enable chat functionality?
enabled: true
:media_proxy:
# Enable the proxy?
enabled: true
# Emit a 302 to the original resource when uncached?
redirect_on_failure: true
# Where your proxy is reachable
base_url: https://media.coolsite.moe
:instance:
# The name of your instance.
name: super cool stuff club
# Short description of your instance
description: we do super cool stuff in super cool stuff club
# The admin's email address.
email: admin@coolsite.moe
# How many chars a notice may have at max.
limit: 4096
# May new members sign up?
registrations_open: true
# Allow connections to other instances?
# (Turn this off for testing)
federating: true
# The rewrite policies / quarantines to enable.
# This is a powerful feature which should be used with care.
# Take a look at https://git.pleroma.social/pleroma/pleroma/wikis/Message%20rewrite%20facility%20configuration%20(how%20to%20block%20instances).
# Then uncomment only the things you really need
# quarantined_instances:
# - badguys.moe
# rewrite_policy:
# - Pleroma.Web.ActivityPub.MRF.SimplePolicy
# :mrf_simple:
# media_removal:
# - illegalporn.biz
# media_nsfw:
# - porn.biz
# - porn.business
# reject:
# - spam.com
# federated_timeline_removal:
# - spam.university

14
config.exs Normal file
View File

@ -0,0 +1,14 @@
use Mix.Config
# pleroma/pleroma/pleroma are the default credentials for the
# managed database container. "db" is the default interlinked hostname.
# You shouldn't need to change this unless you modifed .env
config :pleroma, Pleroma.Repo,
adapter: Ecto.Adapters.Postgres,
username: "pleroma",
password: "pleroma",
database: "pleroma",
hostname: "db",
pool_size: 10
# vvv Your awesome config options go here vvv

View File

@ -1,59 +0,0 @@
#!/usr/bin/env ruby
#
# TODO: Write a better translator.
# This is just rough text replacement right now
# but it's already way better than the exs stuff
# we had durin the .env files.
#
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
raise "Incompatible config version (#{config["version"]} != 1)"
end
buf = "use Mix.Config\n\n"
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 += ": #{getval(settings)}\n"
next
end
settings.each do |name, value|
if value.is_a?(Hash) && value["<T>"] == "Array"
value.delete("<T>")
buf += ", #{name}: ["
value.each do |k, v|
buf += "#{k}: #{getval(v)},"
end
buf.chop!()
buf += "]"
else
buf += ", #{name}: #{getval(value)}"
end
end
buf += "\n"
end
end
puts buf

View File

@ -100,9 +100,8 @@ define(<env_inline_fb>, <${upcase($1):-$2}>)
"env_fb(<mix_env>, <prod>)"
],
"volumes": [
"./custom.d:/custom.d",
"./config.yml:/conf/config.yml:ro",
"./config_parser/parser.rb:/conf/parser.rb:ro",
"./custom.d:/custom.d:ro",
"./config.exs:/home/pleroma/pleroma/config/prod.secret.exs:ro",
"env_inline(<docker_datadir>)/uploads:env_inline_fb(<pleroma_uploads_path>, </uploads>)"
],
"labels": [

View File

@ -3,18 +3,15 @@
set -e
set -x
if [[ -z "$NO_CONFIG" ]]; then
ruby /conf/parser.rb /conf/config.yml > config/runtime-config.exs
fi
if [[ -n "$BUILDTIME" ]]; then
mix local.rebar --force
mix local.hex --force
if [[ -n "$COMPILE_ONLY" ]]; then
mix deps.get
mix compile
exit 0
fi
# Assume that dependencies are compiled and ready to go.
# Remove this assumption when https://github.com/erlang/rebar3/issues/1627 is fixed.
mix compile
# Migrate db

72
pleroma
View File

@ -40,6 +40,22 @@ require_command() {
fi
}
require_file() {
if [[ ! -f $1 ]]; then
echo "File missing: '$1' (Example at: '$2')"
FILE_FAILED=1
fi
}
throw_file_errors() {
if [[ -n "$FILE_FAILED" ]]; then
echo ""
echo "Please create the missing files first."
echo "The script will now exit."
exit 1
fi
}
render_template() {
require_command m4
require_command awk
@ -57,12 +73,6 @@ docker_compose() {
}
load_env() {
if [[ ! -f .env ]]; then
echo "Please create a .env file first"
echo "(Copy .env.dist to .env for a template)"
exit 1
fi
while read -r line; do
if [[ "$line" == \#* ]] || [[ -z "$line" ]]; then
continue;
@ -103,12 +113,6 @@ action__build() {
docker_compose build --build-arg __BUST_CACHE="$(date +%s)" server
}
action__config() {
require_command docker
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)
}
@ -241,12 +245,10 @@ print_help() {
Pleroma Maintenance Script
Usage:
$0 [action]
$0 [action] [action-args...]
Actions:
build Rebuild the pleroma container.
config [file = config.yml] Print the generated pleroma config to stdout.
build (Re)build the pleroma container.
dump Dump the generated docker-compose.yml to stdout.
@ -284,8 +286,6 @@ Environment:
SHOPT can be used to modify shell options.
Pass a list of options to this variable like SHOPT='-x -e'.
-e is always on unless you set it to +e.
For setting long options with -o use a colon (:) instead of a space
to seperate the option from -o. For example: SHOPT='-x -e -o:pipefail'.
@ -325,18 +325,36 @@ if [[ -n "$DEBUG" ]]; then
fi
fi
# Check if the option is "help"
case "$1" in
"help"|"h"|"--help"|"-h"|"-?")
print_help
exit 0
;;
esac
# Check if the called command exists
func="action__${1}"
if ! type -t "$func" 1>/dev/null 2>&1; then
echo "Unknown flag or subcommand."
echo "Try '$0 help'"
exit 1
fi
# Fail if mandatory files are missing
require_file ".env" ".env.dist"
require_file "config.exs" "config.dist.exs"
throw_file_errors
# Parse .env
load_env
# Guess function name of current command and call it if present
func="action__${1}"
if type -t "$func" 1>/dev/null 2>&1; then
shift
# Handle DEBUG=2
[[ $DEBUG != 1 ]] || set -x
# Jump to called function
shift
$func "$@"
# Disable debug mode
{ [[ $DEBUG != 1 ]] || set +x; } 2>/dev/null
else
print_help
exit 1
fi