From 99f025986799303d0761ee556386e8176205cb6f Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Fri, 11 Nov 2022 15:08:42 +0000 Subject: [PATCH] started rebased build - using main dockerfile from soapbox repo --- .gitignore | 5 ++ 00-create-pod.sh | 3 +- 10-build-rebased.sh | 14 +++++ 10-create-db.sh | 22 -------- 20-build-pleroma.sh | 10 ---- 20-create-db.sh | 15 +++++ 30-run-rebased.sh | 28 ++++++++++ 35-gen-config.sh | 5 ++ 40-install-soapbox.sh | 8 +++ 90-run-pleroma.sh | 35 ------------ Containerfile | 43 --------------- config.exs | 76 -------------------------- config/{secret.exs => prod.secret.exs} | 0 podman-run.sh | 62 --------------------- script_config.sh | 11 ++++ 15 files changed, 87 insertions(+), 250 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 00-create-pod.sh create mode 100755 10-build-rebased.sh delete mode 100644 10-create-db.sh delete mode 100755 20-build-pleroma.sh create mode 100755 20-create-db.sh create mode 100755 30-run-rebased.sh create mode 100755 35-gen-config.sh create mode 100755 40-install-soapbox.sh delete mode 100755 90-run-pleroma.sh delete mode 100644 Containerfile delete mode 100644 config.exs rename config/{secret.exs => prod.secret.exs} (100%) delete mode 100755 podman-run.sh create mode 100644 script_config.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a93f212 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +static +uploads +postgres +build +soapbox.zip diff --git a/00-create-pod.sh b/00-create-pod.sh old mode 100644 new mode 100755 index 35d4be5..56ead99 --- a/00-create-pod.sh +++ b/00-create-pod.sh @@ -6,7 +6,6 @@ touch config.exs chown -R 911:911 ./uploads podman pod create \ - --name pleroma-pod \ + --name rebased-pod \ -p 4000:4000 -bash ./10-create-db.sh diff --git a/10-build-rebased.sh b/10-build-rebased.sh new file mode 100755 index 0000000..3720b94 --- /dev/null +++ b/10-build-rebased.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +source ./script_config.sh + +if [ ! -d ./build ]; then + git clone https://gitlab.com/soapbox-pub/rebased.git ./build + cd ./build +else + cd ./build + git pull +fi + +podman build -f Dockerfile --build-arg="BUILD_DATE=$DATE" --build-arg="VCS_REF=$REBASED_VER" -t $REBASED_IMG + diff --git a/10-create-db.sh b/10-create-db.sh deleted file mode 100644 index 657d2aa..0000000 --- a/10-create-db.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -first=false -if [[ ! -d ./postgres ]]; then - mkdir ./postgres - $first=true - -fi -podman run -d \ - --name pleroma-db \ - --pod pleroma-pod \ - -e POSTGRES_USER=pleroma \ - -e POSTGRES_PASSWORD=CHANGHEME \ - -e POSTGRES_DB=pleroma \ - -v ./postgres:/var/lib/postgresql/data \ - postgres:12.1-alpine - -if [[ $first == true ]]; then - podman exec -i pleroma-db psql -U pleroma -c "CREATE EXTENSION IF NOT EXISTS citext;" - exit 0 -fi - diff --git a/20-build-pleroma.sh b/20-build-pleroma.sh deleted file mode 100755 index d793dff..0000000 --- a/20-build-pleroma.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -commit="$1" -if [[ "$1" == "" ]]; then - echo "No commit ID provided" - $commit="develop" - exit -fi -dt=$(date +"%Y%m%d") -podman build -f Containerfile --build-arg="PLEROMA_VER=$commit" -t pleroma:run-$dt-$commit diff --git a/20-create-db.sh b/20-create-db.sh new file mode 100755 index 0000000..386502c --- /dev/null +++ b/20-create-db.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +source ./script_config.sh + +mkdir ./postgres -p + +podman run -d \ + --name rebased-db \ + --pod rebased-pod \ + -e POSTGRES_USER=$PG_USER \ + -e POSTGRES_PASSWORD=$PG_PASS \ + -e POSTGRES_DB=$PG_NAME \ + -v ./postgres:/var/lib/postgresql/data \ + postgres:14.6-alpine + diff --git a/30-run-rebased.sh b/30-run-rebased.sh new file mode 100755 index 0000000..23c64a2 --- /dev/null +++ b/30-run-rebased.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +source ./script_config.sh + +echo Stopping old `rebased-web` container... +podman stop rebased-web +podman rm rebased-web + +echo Creating new `rebased-web` container... +podman run -d \ + --name rebased-web \ + --pod rebased-pod \ + -v ./uploads:/var/lib/pleroma/uploads:z \ + -v ./static:/var/lib/pleroma/static:z \ + -v ./config:/var/lib/pleroma/config:z \ + -v ./config.exs:/etc/pleroma/config.exs:ro \ + -e DOMAIN=social.example.com \ + -e INSTANCE_NAME=rebased \ + -e ADMIN_EMAIL=admin@example.com \ + -e NOTIFY_EMAIL=notify@example.com \ + -e DB_USER=rebased \ + -e DB_PASS=rebased \ + -e DB_NAME=rebased \ + -e DB_HOST=localhost \ + -e POSTGRES_HOST=localhost \ + $REBASED_IMG + + diff --git a/35-gen-config.sh b/35-gen-config.sh new file mode 100755 index 0000000..59b2a90 --- /dev/null +++ b/35-gen-config.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +source ./script_config.sh + +podman exec -it rebased-web /opt/pleroma/bin/pleroma_ctl instance gen diff --git a/40-install-soapbox.sh b/40-install-soapbox.sh new file mode 100755 index 0000000..b70ccc3 --- /dev/null +++ b/40-install-soapbox.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +curl -L https://gitlab.com/soapbox-pub/soapbox/-/jobs/artifacts/develop/download?job=build-production -o soapbox.zip +unzip soapbox.zip -d ./static +mv ./static/static/* ./static/ +mv ./static/static/.* ./static/ +rm ./static/static -r + diff --git a/90-run-pleroma.sh b/90-run-pleroma.sh deleted file mode 100755 index 227832e..0000000 --- a/90-run-pleroma.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -if [[ $1 == "" ]]; then - echo "No Image tag provided" - exit -fi -echo Creating directories... -mkdir ./postgres -mkdir ./uploads -mkdir ./static -touch config.exs -chown -R 911:911 ./uploads - -echo Stopping old `pleroma-web` container... -podman stop pleroma-web -podman rm pleroma-web - -echo Creating new `pleroma-web` container... -podman run -d \ - --name pleroma-web \ - --pod pleroma-pod \ - -v ./uploads:/var/lib/pleroma/uploads:z \ - -v ./static:/var/lib/pleroma/static:z \ - -v ./config.exs:/etc/pleroma/config.exs:ro \ - -e DOMAIN=social.example.com \ - -e INSTANCE_NAME=Pleroma \ - -e ADMIN_EMAIL=admin@example.com \ - -e NOTIFY_EMAIL=notify@example.com \ - -e DB_USER=pleroma \ - -e DB_PASS=pleroma \ - -e DB_NAME=pleroma \ - -e DB_HOST=localhost \ - -e POSTGRES_HOST=localhost \ - pleroma:$1 - - diff --git a/Containerfile b/Containerfile deleted file mode 100644 index 86cca6f..0000000 --- a/Containerfile +++ /dev/null @@ -1,43 +0,0 @@ -FROM elixir:1.11.4-alpine - -ENV UID=911 GID=911 \ - MIX_ENV=prod - -ARG PLEROMA_VER=develop -ENV UID=911 GID=911 MIX_ENV=prod - -ENV MIX_ENV=prod - -RUN echo "http://nl.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories \ - && apk update \ - && apk add git gcc g++ musl-dev make cmake file-dev \ - exiftool imagemagick libmagic ncurses postgresql-client ffmpeg - -RUN addgroup -g ${GID} pleroma \ - && adduser -h /pleroma -s /bin/false -D -G pleroma -u ${UID} pleroma - -ARG DATA=/var/lib/pleroma -RUN mkdir -p /etc/pleroma \ - && chown -R pleroma /etc/pleroma \ - && mkdir -p ${DATA}/uploads \ - && mkdir -p ${DATA}/static \ - && chown -R pleroma ${DATA} - -USER pleroma -WORKDIR /pleroma - -RUN git clone -b develop https://git.pleroma.social/pleroma/pleroma.git /pleroma \ - && git checkout ${PLEROMA_VER} - -RUN echo "import Mix.Config" > config/prod.secret.exs \ - && mix local.hex --force \ - && mix local.rebar --force \ - && mix deps.get --only prod \ - && mkdir release \ - && mix release --path /pleroma - -COPY ./config.exs /etc/pleroma/config.exs - -EXPOSE 4000 - -ENTRYPOINT ["/pleroma/docker-entrypoint.sh"] diff --git a/config.exs b/config.exs deleted file mode 100644 index 8aee4b9..0000000 --- a/config.exs +++ /dev/null @@ -1,76 +0,0 @@ -import Config - -config :pleroma, Pleroma.Web.Endpoint, - url: [host: System.get_env("DOMAIN", "localhost"), scheme: "https", port: 443], - http: [ip: {0, 0, 0, 0}, port: 4000] - -config :pleroma, :instance, - name: System.get_env("INSTANCE_NAME", "Pleroma"), - email: System.get_env("ADMIN_EMAIL"), - notify_email: System.get_env("NOTIFY_EMAIL"), - limit: 5000, - registrations_open: false, - federating: true, - healthcheck: true - -config :pleroma, configurable_from_database: true - -config :pleroma, :media_proxy, - enabled: false, - redirect_on_failure: true, - base_url: "https://example.tld" - -config :pleroma, Pleroma.Repo, - adapter: Ecto.Adapters.Postgres, - username: System.get_env("DB_USER", "pleroma"), - password: System.fetch_env!("DB_PASS"), - database: System.get_env("DB_NAME", "pleroma"), - hostname: System.get_env("DB_HOST", "localhost"), - pool_size: 10 - -# Configure web push notifications -config :web_push_encryption, :vapid_details, subject: "mailto:#{System.get_env("NOTIFY_EMAIL")}" - -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" - -# 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) - 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("/var/lib/pleroma/secret.exs", secret_file) -end - -import_config("/var/lib/pleroma/secret.exs") - -# For additional user config -if File.exists?("/var/lib/pleroma/config.exs"), - do: import_config("/var/lib/pleroma/config.exs"), - else: - File.write("/var/lib/pleroma/config.exs", """ - import Config - - # For additional configuration outside of environmental variables - """) diff --git a/config/secret.exs b/config/prod.secret.exs similarity index 100% rename from config/secret.exs rename to config/prod.secret.exs diff --git a/podman-run.sh b/podman-run.sh deleted file mode 100755 index a950004..0000000 --- a/podman-run.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -mkdir ./postgres -mkdir ./uploads -mkdir ./static -touch config.exs -chown -R 911:911 ./uploads - -podman pod create \ - --name pleroma-pod \ - -p 4000:4000 - -podman run -d \ - --name pleroma-db \ - --pod pleroma-pod \ - -e POSTGRES_USER=pleroma \ - -e POSTGRES_PASSWORD=CHANGHEME \ - -e POSTGRES_DB=pleroma \ - -v ./postgres:/var/lib/postgresql/data \ - postgres:12.1-alpine - -if [[ $1 == "db-setup" ]]; then - podman exec -i pleroma-db psql -U pleroma -c "CREATE EXTENSION IF NOT EXISTS citext;" - exit 0 -fi -runvars="pleroma:" -runmode="-d" -if [[ $1 == "build-setup" ]]; then - podman build -f Dockerfile -t pleroma:$1 - runvars=$runvars$1" mix ecto.migrate" - runmode="--rm" -elif [[ $1 == "final-build" ]]; then - podman build -f Dockerfile -t pleroma:run - runvars=$runvars"run" -fi - - - -podman run $runmode \ - --name pleroma-web \ - --pod pleroma-pod \ - -v ./uploads:/var/lib/pleroma/uploads \ - -v ./static:/var/lib/pleroma/static \ - -v ./config.exs:/etc/pleroma/config.exs:ro \ - -e DOMAIN=example.tld \ - -e INSTANCE_NAME=Pleroma \ - -e ADMIN_EMAIL=admin@example.tld \ - -e NOTIFY_EMAIL=notify@example.tld \ - -e DB_USER=pleroma \ - -e DB_PASS=CHANGEME \ - -e DB_NAME=pleroma \ - -e DB_HOST=localhost \ - -e POSTGRES_HOST=localhost \ - $runvars - -if [[ $1 == "build-setup" ]]; then - podman exec pleroma-web /pleroma/bin/pleroma_ctl config migrate_to_db -fi - -if [[ $1 == "gen-keypair" ]]; then - podman exec pleroma-web mix web_push.gen.keypair -fi diff --git a/script_config.sh b/script_config.sh new file mode 100644 index 0000000..f9f1c57 --- /dev/null +++ b/script_config.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +DATE=$(date +"%Y-%m-%d") +PG_USER=rebased +PG_PASS=rebased +PG_HOST=localhost +PG_NAME=rebased +REBASED_VER=develop + +REBASED_IMG="rebased-$REBASED_VER-$DATE" +echo $REBASED_IMG