From a785e9eff531ef43624b8bc32e83cafe446ee8ad Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 9 Dec 2022 08:31:45 -0700 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ Dockerfile | 28 ++++++++++++++++++ README.rst | 67 ++++++++++++++++++++++++++++++++++++++++++++ config.dist.exs | 67 ++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 34 ++++++++++++++++++++++ docker-entrypoint.sh | 25 +++++++++++++++++ example.env | 10 +++++++ 7 files changed, 234 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.rst create mode 100644 config.dist.exs create mode 100644 docker-compose.yaml create mode 100755 docker-entrypoint.sh create mode 100644 example.env diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec5e5b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# In case you end up running it from this repository +.env +data diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..22693b2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM alpine + +# Install packages +RUN awk 'NR==2' /etc/apk/repositories | sed 's/main/community/' | tee -a /etc/apk/repositories +RUN apk update && apk add curl exiftool ffmpeg imagemagick libmagic openssl1.1-compat postgresql14-client su-exec unzip + +# Create user and directories +RUN addgroup pleroma && adduser --system -G pleroma --shell /bin/false --home /opt/pleroma pleroma +RUN mkdir -p /uploads +RUN mkdir -p /static +RUN mkdir -p /config + +# Download and install Pleroma +RUN curl 'https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/stable/download?job=amd64-musl' -o /tmp/pleroma.zip +RUN unzip /tmp/pleroma.zip -d /tmp/ +RUN mv /tmp/release/* /opt/pleroma +RUN rmdir /tmp/release && rm /tmp/pleroma.zip + +# Add entrypoint script and base config +COPY ./docker-entrypoint.sh /usr/local/bin/ +COPY ./config.dist.exs /opt/pleroma/ + +WORKDIR /opt/pleroma +ENV PLEROMA_CONFIG_PATH=/config/config.exs +VOLUME ["/uploads", "/static", "/config"] +EXPOSE 4000 +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] +CMD ["/opt/pleroma/bin/pleroma", "start"] diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..2794d42 --- /dev/null +++ b/README.rst @@ -0,0 +1,67 @@ +Docker image of Pleroma +======================= + +This is a Pleroma image that I created for myself. Feel free to use it if you wish. + +This image will create the configuration for Pleroma, and then migrate the configuration to the database. + +Set Up +------ + +You'll need an environment file and a Compose file. + + +.env +~~~~ + +.. code-block:: shell + + POSTGRES_HOST=postgres + POSTGRES_USER=pleroma + POSTGRES_PASSWORD=pleroma + POSTGRES_DB=pleroma + DOMAIN=pleroma.yourdomain.com + PORT=443 + SCHEME=https + INSTANCE_NAME=Pleroma + ADMIN_EMAIL=admin@yourdomain.com + NOTIFY_EMAIL=notify@yourdomain.com + +docker-compose.yaml +~~~~~~~~~~~~~~~~~~~ + +.. code-block:: yaml + + version: '3' + services: + postgres: + image: postgres:14 + environment: + - POSTGRES_USER=${POSTGRES_USER:-pleroma} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB:-pleroma} + restart: unless-stopped + volumes: + - "./data/postgres:/var/lib/postgresql" + pleroma: + image: raoulsnyman/pleroma:latest + environment: + - POSTGRES_HOST=${POSTGRES_HOST:-postgres} + - POSTGRES_USER=${POSTGRES_USER:-pleroma} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB:-pleroma} + - DOMAIN=${DOMAIN:-localhost} + - SCHEME=${SCHEME:-http} + - PORT=${PORT:-8001} + - ADMIN_EMAIL=${ADMIN_EMAIL:-info@example.com} + - NOTIFY_EMAIL=${NOTIFY_EMAIL:-info@example.com} + - INSTANCE_NAME=${INSTANCE_NAME:-Pleroma} + restart: unless-stopped + volumes: + - "./data/config:/config" + - "./data/static:/static" + - "./data/uploads:/uploads" + ports: + - "127.0.0.1:8001:4000" + depends_on: + - postgres diff --git a/config.dist.exs b/config.dist.exs new file mode 100644 index 0000000..aef01da --- /dev/null +++ b/config.dist.exs @@ -0,0 +1,67 @@ +import Config + +config :pleroma, Pleroma.Web.Endpoint, + url: [host: System.get_env("DOMAIN", "localhost"), scheme: System.get_env("SCHEME", "http"), port: System.get_env("PORT", "8001")], + http: [ip: {0, 0, 0, 0}, port: 4000] + +config :pleroma, :instance, + name: System.get_env("INSTANCE_NAME", "Pleroma"), + email: System.get_env("ADMIN_EMAIL", "info@example.com"), + notify_email: System.get_env("NOTIFY_EMAIL", "info@example.com"), + limit: 5000, + registrations_open: true, + federating: true, + healthcheck: true + +config :pleroma, :media_proxy, + enabled: false, + redirect_on_failure: true, + base_url: "https://cache.domain.tld" + +config :pleroma, Pleroma.Repo, + adapter: Ecto.Adapters.Postgres, + username: System.get_env("POSTGRES_USER", "pleroma"), + password: System.fetch_env!("POSTGRES_PASSWORD"), + database: System.get_env("POSTGRES_DB", "pleroma"), + hostname: System.get_env("POSTGRES_HOST", "postgres"), + pool_size: 10 + +config :web_push_encryption, :vapid_details, subject: "mailto:#{System.get_env("NOTIFY_EMAIL")}" + +config :pleroma, :database, rum_enabled: false +config :pleroma, :instance, static_dir: "/static" +config :pleroma, Pleroma.Uploaders.Local, uploads: "/uploads" + +if not File.exists?("/config/secret.exs") do + secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) + signing_salt = :crypto.strong_rand_bytes(8) |> Base.encode64() |> binary_part(0, 8) + {web_push_public_key, web_push_private_key} = :crypto.generate_key(:ecdh, :prime256v1) + + secret_file = + EEx.eval_string( + """ + import Config + + config :pleroma, Pleroma.Web.Endpoint, + secret_key_base: "<%= secret %>", + signing_salt: "<%= signing_salt %>" + + config :web_push_encryption, :vapid_details, + public_key: "<%= web_push_public_key %>", + private_key: "<%= web_push_private_key %>" + """, + secret: secret, + signing_salt: signing_salt, + web_push_public_key: Base.url_encode64(web_push_public_key, padding: false), + web_push_private_key: Base.url_encode64(web_push_private_key, padding: false) + ) + + File.write("/config/secret.exs", secret_file) +end + +import_config("/config/secret.exs") + +# For additional user config +if File.exists?("/config/config-override.exs") do + import_config("/config/config-override.exs") +end diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..7655646 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,34 @@ +version: '3' +services: + postgres: + image: postgres:14 + environment: + - POSTGRES_USER=${POSTGRES_USER:-pleroma} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB:-pleroma} + restart: unless-stopped + volumes: + - "./data/postgres:/var/lib/postgresql" + pleroma: + build: + context: . + environment: + - POSTGRES_HOST=${POSTGRES_HOST:-postgres} + - POSTGRES_USER=${POSTGRES_USER:-pleroma} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB:-pleroma} + - DOMAIN=${DOMAIN:-localhost} + - SCHEME=${SCHEME:-http} + - PORT=${PORT:-8001} + - ADMIN_EMAIL=${ADMIN_EMAIL:-info@example.com} + - NOTIFY_EMAIL=${NOTIFY_EMAIL:-info@example.com} + - INSTANCE_NAME=${INSTANCE_NAME:-Pleroma} + restart: unless-stopped + volumes: + - "./data/config:/config" + - "./data/static:/static" + - "./data/uploads:/uploads" + ports: + - "127.0.0.1:8001:4000" + depends_on: + - postgres diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..9c6050b --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/sh +set -e + +# Wait for DB +while ! pg_isready -U ${POSTGRES_USER:-pleroma} -d postgres://${POSTGRES_HOST:-postgres}:${POSTGRES_PORT:-5432}/${POSTGRES_DB:-pleroma} -t 1; do + echo "Waiting for ${POSTGRES_HOST} to come up..." + sleep 1 +done + +# Fix the user on the config directory and re-run the script as the pleroma user +chown pleroma:pleroma -R /config /uploads /static /opt/pleroma + +# Create config file, if necessary +if [ ! -f "/config/config.exs" ]; then + /sbin/su-exec pleroma cp /opt/pleroma/config.dist.exs /config/config.exs + /sbin/su-exec pleroma /opt/pleroma/bin/pleroma_ctl migrate + /sbin/su-exec pleroma /opt/pleroma/bin/pleroma_ctl config migrate_to_db + /sbin/su-exec pleroma echo "config :pleroma, configurable_from_database: true" >> /config/config.exs +fi + +# Migrate database +/sbin/su-exec pleroma /opt/pleroma/bin/pleroma_ctl migrate + +# Run Pleroma as the "pleroma" user +exec /sbin/su-exec pleroma "$@" diff --git a/example.env b/example.env new file mode 100644 index 0000000..9e53359 --- /dev/null +++ b/example.env @@ -0,0 +1,10 @@ +POSTGRES_HOST=postgres +POSTGRES_USER=pleroma +POSTGRES_PASSWORD=pleroma +POSTGRES_DB=pleroma +DOMAIN=pleroma.example.com +PORT=443 +SCHEME=https +INSTANCE_NAME=Pleroma +ADMIN_EMAIL=info@example.com +NOTIFY_EMAIL=info@example.com