From 4450f7463b3e6527ebd17562c6841327108a92c8 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 09:11:02 +0100 Subject: [PATCH] add assistive flags for docker --- docker-resources/generate-instance.sh | 28 +++++++++++++++++++++++++++ lib/mix/tasks/pleroma/instance.ex | 8 ++++++-- priv/templates/sample_psql.eex | 6 +++++- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 docker-resources/generate-instance.sh diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh new file mode 100755 index 000000000..63177216c --- /dev/null +++ b/docker-resources/generate-instance.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -euo pipefail + +mkdir -p pgdata +mkdir -p docker-setup-tmp + +# This is sorta special in that we need the generated_config.exs to make it onto the host +# We can also automate the DB setup here! +docker compose run \ + --rm \ + -e "PLEROMA_CTL_RPC_DISABLED=true" \ + -v ./docker-setup-tmp:/opt/akkoma/config/\ + akkoma ./bin/pleroma_ctl instance gen --no-sql-user --no-db-creation --dbhost db --dbname akkoma --dbuser akkoma --dbpass akkoma --listen-ip 0.0.0.0 --listen-port 4000 --static-dir /opt/akkoma/instance/ --uploads-dir /opt/akkoma/uploads/ --db-configurable true + +echo "" +echo "==========================" +echo "" +echo "Setting up your database!" + +docker compose start db + +docker compose run \ + --rm \ + -e "PGPASSWORD=akkoma" \ + -v "$(pwd)/docker-setup-tmp/setup_db.psql:/docker-entrypoint-initdb.d/setup_db.sql" \ + db + diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 72f4623ce..c07bc7daf 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -37,7 +37,9 @@ defmodule Mix.Tasks.Pleroma.Instance do listen_port: :string, strip_uploads_metadata: :string, read_uploads_description: :string, - anonymize_uploads: :string + anonymize_uploads: :string, + no_sql_user: :boolean, + no_db_creation: :boolean ], aliases: [ o: :output, @@ -260,7 +262,9 @@ defmodule Mix.Tasks.Pleroma.Instance do dbname: dbname, dbuser: dbuser, dbpass: dbpass, - rum_enabled: rum_enabled + rum_enabled: rum_enabled, + no_sql_user: Keyword.get(options, :no_sql_user, false), + no_db_creation: Keyword.get(options, :no_db_creation, false) ) config_dir = Path.dirname(config_path) diff --git a/priv/templates/sample_psql.eex b/priv/templates/sample_psql.eex index 627839a68..a3376c2ec 100644 --- a/priv/templates/sample_psql.eex +++ b/priv/templates/sample_psql.eex @@ -1,5 +1,9 @@ +<%= unless no_sql_user do %> CREATE USER <%= dbuser %> WITH ENCRYPTED PASSWORD '<%= dbpass %>'; -CREATE DATABASE <%= dbname %> OWNER <%= dbuser %>; +<% end %> +<%= unless no_db_creation do %> +CREATE DATABASE IF NOT EXISTS <%= dbname %> OWNER <%= dbuser %>; +<% end %> \c <%= dbname %>; --Extensions made by ecto.migrate that need superuser access CREATE EXTENSION IF NOT EXISTS citext;