Browse Source

transfer config to database, add instructions on persisting things properly

master
Pasture Pastureson 4 months ago
parent
commit
337d0c605d
5 changed files with 43 additions and 19 deletions
  1. +2
    -2
      Dockerfile
  2. +9
    -8
      README.md
  3. +26
    -5
      docker-entrypoint.sh
  4. +2
    -0
      docker.exs
  5. +4
    -4
      postgres.sh

+ 2
- 2
Dockerfile View File

@ -98,7 +98,7 @@ COPY --from=build --chown=pleroma:0 /src/release ${HOME}
COPY ./docker.exs /etc/pleroma/config.exs
USER caddy
COPY ./Caddyfile /caddy/Caddyfile
COPY ./Caddyfile /etc/Caddyfile
USER root
COPY ./docker-entrypoint.sh /run/docker-entrypoint.sh
@ -108,7 +108,7 @@ COPY ./postgres.sh /run/postgres.sh
RUN chmod 755 /run/postgres.sh
VOLUME "/caddy"
VOLUME "/var/lib/postgresql/14/main"
VOLUME "/var/lib/postgresql/14/pleroma"
VOLUME "${DATA}/static"
VOLUME "${DATA}/uploads"


+ 9
- 8
README.md View File

@ -17,17 +17,18 @@ docker build . -t rebased-omnibus:latest
## Run it
First, point your domain name at the public IP of your instance, so Caddy can get a proper TLS certificate. Then, boot up Docker:
First, point your domain name at the public IP of your server, so Caddy can get a proper TLS certificate. Then, boot up Docker:
```
docker run -it \
-e DOMAIN=your.domain.tld \
-e INSTANCE_NAME=yourdomaintld \
-e ADMIN_EMAIL=me@your.domain.tld \
-e NOTIFY_EMAIL=notify@your.domain.tld \
-v ./caddy:/caddy \
-v ./db:/var/lib/postgresql/14/main \
-v ./uploads:/var/lib/pleroma/uploads \
-e DOMAIN=pl.your.domain \
-e INSTANCE_NAME=Soapbox \
-e ADMIN_EMAIL=me@your.domain \
-e NOTIFY_EMAIL=notify@your.domain \
-v /home/omnibus/caddy:/caddy \
-v /home/omnibus/db:/var/lib/postgresql/14/pleroma \
-v /home/omnibus/uploads:/var/lib/pleroma/uploads \
-v /home/omnibus/static:/var/lib/pleroma/static \
-p 0.0.0.0:80:80 \
-p 0.0.0.0:443:443 \
rebased-omnibus:latest


+ 26
- 5
docker-entrypoint.sh View File

@ -2,18 +2,39 @@
set -e
export DATABASE_URL="postgres://pleroma:bleromer@localhost:5432/pleroma"
export DATABASE_URL="postgres://pleroma:bleromer@localhost:5433/pleroma"
echo "-- Setting up PostgreSQL..."
pg_ctlcluster 14 main start
chown -R postgres:postgres /var/lib/postgresql/14
chmod -R 750 /var/lib/postgresql/14
set +e
pg_createcluster 14 pleroma
cp /etc/postgresql/14/pleroma/*.conf /var/lib/postgresql/14/pleroma
set -e
pg_ctlcluster 14 pleroma start
gosu postgres /run/postgres.sh
echo "-- Starting Caddy..."
sed -i -e "s/{{domain}}/$DOMAIN/" /caddy/Caddyfile
gosu caddy caddy start --config /caddy/Caddyfile
chown -R caddy:caddy /caddy
sed -i -e "s/{{domain}}/$DOMAIN/" /etc/Caddyfile
gosu caddy caddy start --config /etc/Caddyfile
echo "-- Running migrations..."
gosu pleroma sh -c "/opt/pleroma/bin/pleroma_ctl migrate"
if [ ! -f "/var/lib/pleroma/static/.migrated" ]; then
echo "-- Transferring config to database"
gosu pleroma sh -c "/opt/pleroma/bin/pleroma start" &
sleep 10
gosu pleroma sh -c "/opt/pleroma/bin/pleroma_ctl config migrate_to_db"
gosu pleroma sh -c "/opt/pleroma/bin/pleroma stop" &
echo "migrated" > /var/lib/pleroma/static/.migrated
sleep 10
else
echo "-- Already migrated config to DB. Skipping."
fi
echo "-- Starting!"
gosu pleroma sh -c "/opt/pleroma/bin/pleroma start"
gosu pleroma sh -c "/opt/pleroma/bin/pleroma start"

+ 2
- 0
docker.exs View File

@ -32,6 +32,8 @@ config :pleroma, :database, rum_enabled: false
config :pleroma, :instance, static_dir: "/var/lib/pleroma/static"
config :pleroma, Pleroma.Uploaders.Local, uploads: "/var/lib/pleroma/uploads"
config :pleroma, configurable_from_database: true
# We can't store the secrets in this file, since this is baked into the docker image
if not File.exists?("/var/lib/pleroma/secret.exs") do
secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)


+ 4
- 4
postgres.sh View File

@ -7,11 +7,11 @@ while ! pg_isready -d $DATABASE_URL -t 1; do
sleep 1s
done
COUNT=$(psql -q -c "select count(datname) from pg_catalog.pg_database where datname = 'pleroma'" -t -A | tr -d '\n');
COUNT=$(psql -p 5433 -q -c "select count(datname) from pg_catalog.pg_database where datname = 'pleroma'" -t -A | tr -d '\n');
if [ "$COUNT" -lt "1" ]; then
echo "Creating database..."
psql -q -c "create user pleroma with encrypted password 'bleromer'"
psql -q -c "create database pleroma with owner = 'pleroma'"
psql -q -c "grant all privileges on database pleroma to pleroma"
psql -p 5433 -q -c "create user pleroma with encrypted password 'bleromer'"
psql -p 5433 -q -c "create database pleroma with owner = 'pleroma'"
psql -p 5433 -q -c "grant all privileges on database pleroma to pleroma"
fi

Loading…
Cancel
Save