From 23da9903d51d09f146c8632f8d249e3753869168 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 28 May 2024 12:12:38 +0100 Subject: [PATCH 01/36] add test docker build --- .woodpecker/build-docker.yml | 32 ++++++++++++++++++++++++ Dockerfile | 48 ++++++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 .woodpecker/build-docker.yml diff --git a/.woodpecker/build-docker.yml b/.woodpecker/build-docker.yml new file mode 100644 index 000000000..5efd546a6 --- /dev/null +++ b/.woodpecker/build-docker.yml @@ -0,0 +1,32 @@ +labels: + platform: linux/amd64 + +variables: + - &on-release + when: + event: + - push + - tag + branch: + - develop + - stable + - &on-stable + when: + event: + - push + - tag + branch: + - stable + +steps: + build: + image: woodpeckerci/plugin-docker-buildx:latest + secrets: [docker_username, docker_password] + settings: + repo: woodpeckerci/woodpecker-agent + dockerfile: docker/Dockerfile.agent.multiarch + platforms: linux/amd64 + tag: next + when: + branch: customizable-docker-db + event: push \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index aadd08f7a..94b044458 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,37 @@ -FROM hexpm/elixir:1.15.4-erlang-26.0.2-alpine-3.18.2 +#################################### +# BUILD CONTAINER +#################################### + +FROM hexpm/elixir:1.16.3-erlang-26.2.5-alpine-3.19.1 AS BUILD ENV MIX_ENV=prod -ENV ERL_EPMD_ADDRESS=127.0.0.1 -ARG HOME=/opt/akkoma +RUN mkdir /src +WORKDIR /src +RUN apk add git gcc g++ musl-dev make cmake file-dev exiftool ffmpeg imagemagick libmagic ncurses postgresql-client +RUN mix local.hex --force &&\ + mix local.rebar --force + +ADD mix.exs /src/mix.exs +ADD mix.lock /src/mix.lock +ADD lib/ /src/lib/ +ADD priv/ /src/priv/ +ADD config/ /src/config/ +ADD rel/ /src/rel/ +ADD restarter/ /src/restarter/ +ADD docs/ /src/docs/ +ADD installation/ /src/installation/ + +RUN mix deps.get --only=prod +RUN mix release --path docker-release + +################################# +# RUNTIME CONTAINER +################################# + +FROM alpine:3.19.1 + +RUN apk add file-dev exiftool ffmpeg imagemagick libmagic postgresql-client LABEL org.opencontainers.image.title="akkoma" \ org.opencontainers.image.description="Akkoma for Docker" \ @@ -14,8 +42,7 @@ LABEL org.opencontainers.image.title="akkoma" \ org.opencontainers.image.revision=$VCS_REF \ org.opencontainers.image.created=$BUILD_DATE -RUN apk add git gcc g++ musl-dev make cmake file-dev exiftool ffmpeg imagemagick libmagic ncurses postgresql-client - +ARG HOME=/opt/akkoma EXPOSE 4000 ARG UID=1000 @@ -27,8 +54,15 @@ RUN adduser -u $UID -G $UNAME -D -h $HOME $UNAME WORKDIR /opt/akkoma +COPY --from=BUILD /src/docker-release/ $HOME +RUN ln -s $HOME/bin/pleroma /bin/pleroma +# it's nice you know +RUN ln -s $HOME/bin/pleroma /bin/akkoma +RUN ln -s $HOME/bin/pleroma_ctl /bin/pleroma_ctl +RUN ln -s $HOME/bin/pleroma_ctl /bin/akkoma_ctl + +ADD docker-entrypoint.sh $HOME/docker-entrypoint.sh + USER $UNAME -RUN mix local.hex --force &&\ - mix local.rebar --force CMD ["/opt/akkoma/docker-entrypoint.sh"] -- 2.43.0 From 5fc47d4b80e6f83bcf96e6b3fffd52439d4d95b5 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 28 May 2024 12:15:10 +0100 Subject: [PATCH 02/36] i am a moron --- .woodpecker/build-docker.yml | 2 +- docker-compose.yml | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.woodpecker/build-docker.yml b/.woodpecker/build-docker.yml index 5efd546a6..e901a7fd6 100644 --- a/.woodpecker/build-docker.yml +++ b/.woodpecker/build-docker.yml @@ -24,7 +24,7 @@ steps: secrets: [docker_username, docker_password] settings: repo: woodpeckerci/woodpecker-agent - dockerfile: docker/Dockerfile.agent.multiarch + dockerfile: Dockerfile platforms: linux/amd64 tag: next when: diff --git a/docker-compose.yml b/docker-compose.yml index 6c0e2a7e1..dd3f60fa7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,11 @@ -version: "3.7" - services: db: image: akkoma-db:latest build: ./docker-resources/database shm_size: 4gb restart: unless-stopped - user: ${DOCKER_USER} + env_file: + - .env environment: { # This might seem insecure but is usually not a problem. # You should leave this at the "akkoma" default. @@ -18,8 +17,6 @@ services: POSTGRES_USER: akkoma, POSTGRES_PASSWORD: akkoma, } - env_file: - - .env volumes: - type: bind source: ./pgdata @@ -27,7 +24,6 @@ services: akkoma: image: akkoma:latest - build: . restart: unless-stopped env_file: - .env -- 2.43.0 From 23c7271f05e2417d3a524137860c5c973c1556b0 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 28 May 2024 12:23:13 +0100 Subject: [PATCH 03/36] am i baka? maybe --- .woodpecker/build-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/build-docker.yml b/.woodpecker/build-docker.yml index e901a7fd6..c3eb606c4 100644 --- a/.woodpecker/build-docker.yml +++ b/.woodpecker/build-docker.yml @@ -23,7 +23,7 @@ steps: image: woodpeckerci/plugin-docker-buildx:latest secrets: [docker_username, docker_password] settings: - repo: woodpeckerci/woodpecker-agent + repo: akkoma/akkoma dockerfile: Dockerfile platforms: linux/amd64 tag: next -- 2.43.0 From 2b6c5c94f9e494b011df59a067c022616953db30 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:00:33 +0100 Subject: [PATCH 04/36] add docker-compose file to tune database --- docker-compose.pgsql-tuning.yml | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker-compose.pgsql-tuning.yml diff --git a/docker-compose.pgsql-tuning.yml b/docker-compose.pgsql-tuning.yml new file mode 100644 index 000000000..ac284c024 --- /dev/null +++ b/docker-compose.pgsql-tuning.yml @@ -0,0 +1,36 @@ +services: + db: + command: + - "postgres" + - "-c" + - "max_connections=40" + - "-c" + - "shared_buffers=1GB" + - "-c" + - "effective_cache_size=3GB" + - "-c" + - "maintenance_work_mem=512MB" + - "-c" + - "checkpoint_completion_target=0.9" + - "-c" + - "wal_buffers=16MB" + - "-c" + - "default_statistics_target=500" + - "-c" + - "random_page_cost=1.1" + - "-c" + - "effective_io_concurrency=200" + - "-c" + - "work_mem=6553kB" + - "-c" + - "min_wal_size=4GB" + - "-c" + - "max_wal_size=16GB" + - "-c" + - "max_worker_processes=4" + - "-c" + - "max_parallel_workers_per_gather=2" + - "-c" + - "max_parallel_workers=4" + - "-c" + - "max_parallel_maintenance_workers=2" -- 2.43.0 From a2dfab971d273d6664f58097e77d48fb99ae3199 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:01:18 +0100 Subject: [PATCH 05/36] add shm_size in overrides --- docker-compose.pgsql-tuning.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.pgsql-tuning.yml b/docker-compose.pgsql-tuning.yml index ac284c024..7ac8c5ecd 100644 --- a/docker-compose.pgsql-tuning.yml +++ b/docker-compose.pgsql-tuning.yml @@ -1,5 +1,8 @@ services: db: + # If you use a config generator, use the value below for your + # "ram" size + shm_size: 4gb command: - "postgres" - "-c" -- 2.43.0 From 38d93a0f978fc2324cd4256714c1932454968a1e Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:19:46 +0100 Subject: [PATCH 06/36] add script to migrate postgres versions --- .../migrate-postgresql-version.sh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 docker-resources/migrate-postgresql-version.sh diff --git a/docker-resources/migrate-postgresql-version.sh b/docker-resources/migrate-postgresql-version.sh new file mode 100755 index 000000000..579a76a9f --- /dev/null +++ b/docker-resources/migrate-postgresql-version.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# USAGE: +# migrate-postgresql-version.sh + +if [ "$#" -ne 3 ]; then + echo "USAGE: migrate-postgresql-version.sh " + echo "Example: migrate-postgresql-version.sh pgdata 14 16" + exit 1 +fi + +data_directory=$1 +old_version=$2 +new_version=$3 + +# Start a PostgreSQL 14 container +docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$old_version + +# Dump the db from the old container +docker exec pg14 pg_dumpall -U postgres > dump.sql + +# Stop the old container +docker stop pg14 + +# move the data directory to a new location so we can overwrite it +mv $data_directory $data_directory.bak + +# Start a PostgreSQL 16 container +docker run --rm -d --name pg16 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$new_version + +# Load the db into the new container +docker exec -i pg16 psql -U postgres < dump.sql + +# Stop the new container +docker stop pg16 + +# Remove the dump file +rm dump.sql + +echo "Migration complete! You can delete your old data directory by running 'rm -rf $data_directory.bak'" -- 2.43.0 From 995225b7838e60247b4986a5a2e12b7818331bb6 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:20:20 +0100 Subject: [PATCH 07/36] use alpine containers --- docker-resources/migrate-postgresql-version.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-resources/migrate-postgresql-version.sh b/docker-resources/migrate-postgresql-version.sh index 579a76a9f..a22aa6a0f 100755 --- a/docker-resources/migrate-postgresql-version.sh +++ b/docker-resources/migrate-postgresql-version.sh @@ -14,7 +14,7 @@ old_version=$2 new_version=$3 # Start a PostgreSQL 14 container -docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$old_version +docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$old_version-alpine # Dump the db from the old container docker exec pg14 pg_dumpall -U postgres > dump.sql @@ -26,7 +26,7 @@ docker stop pg14 mv $data_directory $data_directory.bak # Start a PostgreSQL 16 container -docker run --rm -d --name pg16 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$new_version +docker run --rm -d --name pg16 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$new_version-alpine # Load the db into the new container docker exec -i pg16 psql -U postgres < dump.sql -- 2.43.0 From 8f8c7c76dcc542a6e75ad9736f5d94c7f87cac4b Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:30:54 +0100 Subject: [PATCH 08/36] correct migration script --- docker-resources/migrate-postgresql-version.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docker-resources/migrate-postgresql-version.sh b/docker-resources/migrate-postgresql-version.sh index a22aa6a0f..6cfa3cbd4 100755 --- a/docker-resources/migrate-postgresql-version.sh +++ b/docker-resources/migrate-postgresql-version.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + # USAGE: # migrate-postgresql-version.sh @@ -14,7 +16,10 @@ old_version=$2 new_version=$3 # Start a PostgreSQL 14 container -docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$old_version-alpine +docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$old_version-alpine + +# wait a bit for the container to start +sleep 10 # Dump the db from the old container docker exec pg14 pg_dumpall -U postgres > dump.sql @@ -22,11 +27,8 @@ docker exec pg14 pg_dumpall -U postgres > dump.sql # Stop the old container docker stop pg14 -# move the data directory to a new location so we can overwrite it -mv $data_directory $data_directory.bak - # Start a PostgreSQL 16 container -docker run --rm -d --name pg16 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$new_version-alpine +docker run --rm -d --name pg16 -v $(pwd)/$data_directory.new:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$new_version-alpine # Load the db into the new container docker exec -i pg16 psql -U postgres < dump.sql @@ -37,4 +39,7 @@ docker stop pg16 # Remove the dump file rm dump.sql -echo "Migration complete! You can delete your old data directory by running 'rm -rf $data_directory.bak'" +echo "Migration complete! Your new database folder is $data_directory.new - you can now move your old data and replace it" + +echo "mv $data_directory $data_directory.old" +echo "mv $data_directory.new $data_directory" \ No newline at end of file -- 2.43.0 From 770913f9aaa06b2951ef2c20820cc408e30b0fc8 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:31:34 +0100 Subject: [PATCH 09/36] update pg version to 16 --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index dd3f60fa7..3cb3a75f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ services: db: - image: akkoma-db:latest - build: ./docker-resources/database + image: postgres:16-alpine shm_size: 4gb restart: unless-stopped env_file: -- 2.43.0 From 9e480ab73eca9edb3782853ec3c03e7c1aca0563 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:33:39 +0100 Subject: [PATCH 10/36] add config volume --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3cb3a75f3..bb2d06486 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,7 @@ services: target: /var/lib/postgresql/data akkoma: - image: akkoma:latest + image: akkoma/akkoma:latest restart: unless-stopped env_file: - .env @@ -39,7 +39,7 @@ services: "127.0.0.1:4000:4000", ] volumes: - - .:/opt/akkoma + - ./config/prod.secret.exs:/opt/akkoma/config.exs # Copy this into docker-compose.override.yml and uncomment there if you want to use a reverse proxy #proxy: -- 2.43.0 From f3c2aae62b50789e9d4d46608a210f861501cc28 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:36:52 +0100 Subject: [PATCH 11/36] mount config file in the right place --- Dockerfile | 3 +++ docker-compose.yml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 94b044458..9b3f2d31c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,6 +61,9 @@ RUN ln -s $HOME/bin/pleroma /bin/akkoma RUN ln -s $HOME/bin/pleroma_ctl /bin/pleroma_ctl RUN ln -s $HOME/bin/pleroma_ctl /bin/akkoma_ctl +RUN mkdir -p /etc/akkoma +ENV AKKOMA_CONFIG_PATH=/etc/akkoma/config.exs + ADD docker-entrypoint.sh $HOME/docker-entrypoint.sh USER $UNAME diff --git a/docker-compose.yml b/docker-compose.yml index bb2d06486..50c3ed37a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: "127.0.0.1:4000:4000", ] volumes: - - ./config/prod.secret.exs:/opt/akkoma/config.exs + - ./config/prod.secret.exs:/etc/akkoma/config.exs # Copy this into docker-compose.override.yml and uncomment there if you want to use a reverse proxy #proxy: -- 2.43.0 From df40ab683117a02d7023be587400b6504c69e004 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:02:20 +0100 Subject: [PATCH 12/36] use real db user --- docker-compose.yml | 4 -- .../migrate-postgresql-version.sh | 51 ++++++++++++++++--- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 50c3ed37a..71e8f43d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,6 @@ services: image: postgres:16-alpine shm_size: 4gb restart: unless-stopped - env_file: - - .env environment: { # This might seem insecure but is usually not a problem. # You should leave this at the "akkoma" default. @@ -24,8 +22,6 @@ services: akkoma: image: akkoma/akkoma:latest restart: unless-stopped - env_file: - - .env links: - db ports: [ diff --git a/docker-resources/migrate-postgresql-version.sh b/docker-resources/migrate-postgresql-version.sh index 6cfa3cbd4..7d5015b2c 100755 --- a/docker-resources/migrate-postgresql-version.sh +++ b/docker-resources/migrate-postgresql-version.sh @@ -14,32 +14,67 @@ fi data_directory=$1 old_version=$2 new_version=$3 +new_data_directory=$data_directory.new + +# we'll need the credentials to create the new container +echo "Please provide the credentials for your database" +echo "If you set a different password for the old container, you'll need to provide it here! Check your config file if you're not sure" +echo "" + +echo "Database user (default 'akkoma'):" +read DB_USER +echo "Database password (default: 'akkoma'):" +read DB_PASS +echo "Database name (default: 'akkoma'):" +read DB_NAME + +echo "" +echo "Ok! Using user:$DB_USER to migrate db:$DB_NAME from version $old_version to $new_version" + +trap "docker stop pg$old_version pg$new_version" INT TERM # Start a PostgreSQL 14 container -docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$old_version-alpine +docker run --rm -d --name pg$old_version \ + -v $(pwd)/$data_directory:/var/lib/postgresql/data \ + -e "POSTGRES_PASSWORD=$DB_PASS" \ + -e "POSTGRES_USER=$DB_USER" \ + -e "POSTGRES_DB=$DB_NAME" \ + postgres:$old_version-alpine # wait a bit for the container to start sleep 10 # Dump the db from the old container -docker exec pg14 pg_dumpall -U postgres > dump.sql +echo "Dumping your old database..." + +docker exec pg$old_version pg_dumpall -U $DB_USER > dump.sql # Stop the old container -docker stop pg14 +echo "Stopping the old database..." +docker stop pg$old_version # Start a PostgreSQL 16 container -docker run --rm -d --name pg16 -v $(pwd)/$data_directory.new:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$new_version-alpine +echo "Creating a new database with version $new_version..." +docker run --rm -d --name pg$new_version \ + -v $(pwd)/$new_data_directory:/var/lib/postgresql/data \ + -e "POSTGRES_PASSWORD=password" \ + -e "POSTGRES_USER=$DB_USER" \ + -e "POSTGRES_DB=$DB_NAME" \ + postgres:$new_version-alpine + +# wait for it +sleep 10 # Load the db into the new container -docker exec -i pg16 psql -U postgres < dump.sql +docker exec -i pg$new_version psql -U $DB_USER < dump.sql # Stop the new container -docker stop pg16 +docker stop pg$new_version # Remove the dump file -rm dump.sql +# rm dump.sql echo "Migration complete! Your new database folder is $data_directory.new - you can now move your old data and replace it" echo "mv $data_directory $data_directory.old" -echo "mv $data_directory.new $data_directory" \ No newline at end of file +echo "mv $new_data_directory $data_directory" \ No newline at end of file -- 2.43.0 From 0a7b0745084712ecf5c91337890e168f4fe5d04a Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:07:35 +0100 Subject: [PATCH 13/36] bind instance and uploads volumes --- Dockerfile | 4 ++++ docker-compose.yml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index 9b3f2d31c..84f9d474f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -68,4 +68,8 @@ ADD docker-entrypoint.sh $HOME/docker-entrypoint.sh USER $UNAME +VOLUME uploads /opt/akkoma/uploads +VOLUME instance /opt/akkoma/instance +VOLUME config /etc/akkoma/config.exs + CMD ["/opt/akkoma/docker-entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 71e8f43d7..953cc6920 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,6 +36,8 @@ services: ] volumes: - ./config/prod.secret.exs:/etc/akkoma/config.exs + - ./uploads:/opt/akkoma/uploads + - ./instance:/opt/akkoma/instance # Copy this into docker-compose.override.yml and uncomment there if you want to use a reverse proxy #proxy: -- 2.43.0 From c777a97f6095dcb14acf468958b1728b8ab4e4a9 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:10:20 +0100 Subject: [PATCH 14/36] remove now-unused files --- docker-resources/build.sh | 4 ---- docker-resources/database/Dockerfile | 10 ---------- docker-resources/env.example | 5 ----- docker-resources/manage.sh | 2 +- 4 files changed, 1 insertion(+), 20 deletions(-) delete mode 100755 docker-resources/build.sh delete mode 100644 docker-resources/database/Dockerfile delete mode 100644 docker-resources/env.example diff --git a/docker-resources/build.sh b/docker-resources/build.sh deleted file mode 100755 index ce4f30f8d..000000000 --- a/docker-resources/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -docker compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g) akkoma -docker compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g) db diff --git a/docker-resources/database/Dockerfile b/docker-resources/database/Dockerfile deleted file mode 100644 index 2a38dd16b..000000000 --- a/docker-resources/database/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM postgres:14-alpine - -ARG UID=1000 -ARG GID=1000 -ARG UNAME=akkoma - -RUN addgroup -g $GID $UNAME -RUN adduser -u $UID -G $UNAME -D -h $HOME $UNAME - -USER akkoma diff --git a/docker-resources/env.example b/docker-resources/env.example deleted file mode 100644 index 23ca15221..000000000 --- a/docker-resources/env.example +++ /dev/null @@ -1,5 +0,0 @@ -MIX_ENV=prod -ERL_EPMD_ADDRESS=127.0.0.1 -DB_NAME=akkoma -DB_USER=akkoma -DB_PASS=akkoma diff --git a/docker-resources/manage.sh b/docker-resources/manage.sh index acb6618c3..b1338c100 100755 --- a/docker-resources/manage.sh +++ b/docker-resources/manage.sh @@ -1,3 +1,3 @@ #!/bin/sh -docker compose run --rm akkoma $@ +docker compose run --rm akkoma ./bin/pleroma $@ -- 2.43.0 From f2d59a2922722f25986863e142417d5614e9382b Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:11:03 +0100 Subject: [PATCH 15/36] manage should use ctl --- docker-resources/manage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-resources/manage.sh b/docker-resources/manage.sh index b1338c100..137857b30 100755 --- a/docker-resources/manage.sh +++ b/docker-resources/manage.sh @@ -1,3 +1,3 @@ #!/bin/sh -docker compose run --rm akkoma ./bin/pleroma $@ +docker compose run --rm akkoma ./bin/pleroma_ctl $@ -- 2.43.0 From c38555de5c6a4c23393801977bb5c0fb8baf18dc Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:12:23 +0100 Subject: [PATCH 16/36] don't require RPC --- docker-resources/manage.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-resources/manage.sh b/docker-resources/manage.sh index 137857b30..847cd0788 100755 --- a/docker-resources/manage.sh +++ b/docker-resources/manage.sh @@ -1,3 +1,4 @@ #!/bin/sh -docker compose run --rm akkoma ./bin/pleroma_ctl $@ +# this should all be done without needing a running instance +docker compose run --rm -e "PLEROMA_CTL_RPC_DISABLED=true" akkoma ./bin/pleroma_ctl $@ -- 2.43.0 From bf90bc0c17e68a7ce75b08201dca837768ec05c7 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:13:46 +0100 Subject: [PATCH 17/36] use next tag --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 953cc6920..8a754acf6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: target: /var/lib/postgresql/data akkoma: - image: akkoma/akkoma:latest + image: akkoma/akkoma:next restart: unless-stopped links: - db -- 2.43.0 From 212686ae9fbe27a93af62ee0e48687b69c522284 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:15:01 +0100 Subject: [PATCH 18/36] use proper commands --- docker-entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 778ef08e2..3b8ee56a4 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -8,7 +8,7 @@ while ! pg_isready -U ${DB_USER:-pleroma} -d postgres://${DB_HOST:-db}:5432/${DB done echo "-- Running migrations..." -mix ecto.migrate +/opt/akkoma/bin/akkoma_ctl migrate echo "-- Starting!" -mix phx.server +/opt/akkoma/bin/akkoma start -- 2.43.0 From 5e3c58ae799fbe662406f3268c21513c4e332dea Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:23:17 +0100 Subject: [PATCH 19/36] crie --- docker-entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 3b8ee56a4..49319bfa9 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -8,7 +8,7 @@ while ! pg_isready -U ${DB_USER:-pleroma} -d postgres://${DB_HOST:-db}:5432/${DB done echo "-- Running migrations..." -/opt/akkoma/bin/akkoma_ctl migrate +/opt/akkoma/bin/pleroma_ctl migrate echo "-- Starting!" -/opt/akkoma/bin/akkoma start +/opt/akkoma/bin/pleroma start -- 2.43.0 From 7522735b2a627e26fd8ce504324c5f73d6f45a1f Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 06:24:30 +0100 Subject: [PATCH 20/36] support aarch64 in docker --- .woodpecker/build-docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.woodpecker/build-docker.yml b/.woodpecker/build-docker.yml index c3eb606c4..74ce7045d 100644 --- a/.woodpecker/build-docker.yml +++ b/.woodpecker/build-docker.yml @@ -25,8 +25,8 @@ steps: settings: repo: akkoma/akkoma dockerfile: Dockerfile - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64/v8 tag: next when: branch: customizable-docker-db - event: push \ No newline at end of file + event: push -- 2.43.0 From 2f1569b931a6e9bcd8f5d85e902efe9074dc625c Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 08:29:44 +0100 Subject: [PATCH 21/36] use standard user --- Dockerfile | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 84f9d474f..bb10abbea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,13 +45,6 @@ LABEL org.opencontainers.image.title="akkoma" \ ARG HOME=/opt/akkoma EXPOSE 4000 -ARG UID=1000 -ARG GID=1000 -ARG UNAME=akkoma - -RUN addgroup -g $GID $UNAME -RUN adduser -u $UID -G $UNAME -D -h $HOME $UNAME - WORKDIR /opt/akkoma COPY --from=BUILD /src/docker-release/ $HOME @@ -66,7 +59,8 @@ ENV AKKOMA_CONFIG_PATH=/etc/akkoma/config.exs ADD docker-entrypoint.sh $HOME/docker-entrypoint.sh -USER $UNAME +RUN adduser --system --home /opt/akkoma akkoma +USER akkoma VOLUME uploads /opt/akkoma/uploads VOLUME instance /opt/akkoma/instance -- 2.43.0 From 4450f7463b3e6527ebd17562c6841327108a92c8 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 09:11:02 +0100 Subject: [PATCH 22/36] 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 @@ def run(["gen" | rest]) 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 @@ def run(["gen" | rest]) 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; -- 2.43.0 From cb678e86595772b99c93341fc6d8dc18324bc6d8 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 09:31:17 +0100 Subject: [PATCH 23/36] only build amd64 for now --- .woodpecker/build-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/build-docker.yml b/.woodpecker/build-docker.yml index 74ce7045d..7c4cef2e4 100644 --- a/.woodpecker/build-docker.yml +++ b/.woodpecker/build-docker.yml @@ -25,7 +25,7 @@ steps: settings: repo: akkoma/akkoma dockerfile: Dockerfile - platforms: linux/amd64,linux/arm64/v8 + platforms: linux/amd64 tag: next when: branch: customizable-docker-db -- 2.43.0 From 863630eb7324fde673d8425a1068642b8e5cc0e6 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 10:06:06 +0100 Subject: [PATCH 24/36] don't set config file in dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bb10abbea..980620a24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,6 @@ RUN ln -s $HOME/bin/pleroma_ctl /bin/pleroma_ctl RUN ln -s $HOME/bin/pleroma_ctl /bin/akkoma_ctl RUN mkdir -p /etc/akkoma -ENV AKKOMA_CONFIG_PATH=/etc/akkoma/config.exs ADD docker-entrypoint.sh $HOME/docker-entrypoint.sh -- 2.43.0 From 5e0c61fa8f5a2438431ef17cd1640161b51ff67a Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 10:43:34 +0100 Subject: [PATCH 25/36] fix setup script --- Dockerfile | 7 +++---- docker-resources/generate-instance.sh | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 980620a24..94346edcf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,15 +54,14 @@ RUN ln -s $HOME/bin/pleroma /bin/akkoma RUN ln -s $HOME/bin/pleroma_ctl /bin/pleroma_ctl RUN ln -s $HOME/bin/pleroma_ctl /bin/akkoma_ctl -RUN mkdir -p /etc/akkoma - ADD docker-entrypoint.sh $HOME/docker-entrypoint.sh -RUN adduser --system --home /opt/akkoma akkoma +RUN adduser --system --home $HOME akkoma USER akkoma +ENV AKKOMA_CONFIG_PATH=/opt/akkoma/config/config.exs VOLUME uploads /opt/akkoma/uploads VOLUME instance /opt/akkoma/instance -VOLUME config /etc/akkoma/config.exs +VOLUME config /opt/akkoma/config CMD ["/opt/akkoma/docker-entrypoint.sh"] diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh index 63177216c..a5fc6a018 100755 --- a/docker-resources/generate-instance.sh +++ b/docker-resources/generate-instance.sh @@ -10,7 +10,7 @@ mkdir -p docker-setup-tmp docker compose run \ --rm \ -e "PLEROMA_CTL_RPC_DISABLED=true" \ - -v ./docker-setup-tmp:/opt/akkoma/config/\ + -v $(pwd)/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 "" -- 2.43.0 From 1c06f6de29d031df4b8c62cc74fb4e0a6f0846aa Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 10:52:19 +0100 Subject: [PATCH 26/36] use z flag --- docker-compose.yml | 11 +++++------ docker-resources/generate-instance.sh | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8a754acf6..896ff4e90 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,9 +15,8 @@ services: POSTGRES_PASSWORD: akkoma, } volumes: - - type: bind - source: ./pgdata - target: /var/lib/postgresql/data + - ./pgdata:/var/lib/postgresql/data:z + akkoma: image: akkoma/akkoma:next @@ -35,9 +34,9 @@ services: "127.0.0.1:4000:4000", ] volumes: - - ./config/prod.secret.exs:/etc/akkoma/config.exs - - ./uploads:/opt/akkoma/uploads - - ./instance:/opt/akkoma/instance + - ./config/prod.secret.exs:/etc/akkoma/config.exs:z + - ./uploads:/opt/akkoma/uploads:z + - ./instance:/opt/akkoma/instance:z # Copy this into docker-compose.override.yml and uncomment there if you want to use a reverse proxy #proxy: diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh index a5fc6a018..373a559fa 100755 --- a/docker-resources/generate-instance.sh +++ b/docker-resources/generate-instance.sh @@ -4,14 +4,15 @@ set -euo pipefail mkdir -p pgdata mkdir -p docker-setup-tmp +chmod a+w 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 $(pwd)/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 + -v $(pwd)/docker-setup-tmp:/opt/akkoma/config/:z \ + 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 --output /opt/akkoma/config/generated_config.exs --output-psql /opt/akkoma/config/setup_db.psql echo "" echo "==========================" -- 2.43.0 From 616c9878a5f877812d56a25a333774c1d1ae90bf Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 10:53:41 +0100 Subject: [PATCH 27/36] don't chmod --- docker-resources/generate-instance.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh index 373a559fa..a2f331d2d 100755 --- a/docker-resources/generate-instance.sh +++ b/docker-resources/generate-instance.sh @@ -4,7 +4,6 @@ set -euo pipefail mkdir -p pgdata mkdir -p docker-setup-tmp -chmod a+w 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! -- 2.43.0 From f5409783b6edb6fe1da93ead46221b996b610e82 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 10:54:48 +0100 Subject: [PATCH 28/36] let the compose file handle mounts --- docker-resources/generate-instance.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh index a2f331d2d..387975100 100755 --- a/docker-resources/generate-instance.sh +++ b/docker-resources/generate-instance.sh @@ -10,7 +10,6 @@ mkdir -p docker-setup-tmp docker compose run \ --rm \ -e "PLEROMA_CTL_RPC_DISABLED=true" \ - -v $(pwd)/docker-setup-tmp:/opt/akkoma/config/:z \ 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 --output /opt/akkoma/config/generated_config.exs --output-psql /opt/akkoma/config/setup_db.psql echo "" -- 2.43.0 From e8b7ab5e1e607d4a0d69230d3350b3b7c346968b Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 10:56:16 +0100 Subject: [PATCH 29/36] mount entire config directory --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 896ff4e90..0d31ba881 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,7 +34,7 @@ services: "127.0.0.1:4000:4000", ] volumes: - - ./config/prod.secret.exs:/etc/akkoma/config.exs:z + - ./config:/etc/akkoma/config:z - ./uploads:/opt/akkoma/uploads:z - ./instance:/opt/akkoma/instance:z -- 2.43.0 From 44a5d0507bdf339e49578b62e8a7af257cd7c947 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 1 Jun 2024 10:56:46 +0100 Subject: [PATCH 30/36] i baka --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0d31ba881..1b40f9086 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,7 +34,7 @@ services: "127.0.0.1:4000:4000", ] volumes: - - ./config:/etc/akkoma/config:z + - ./config:/opt/akkoma/config:z - ./uploads:/opt/akkoma/uploads:z - ./instance:/opt/akkoma/instance:z -- 2.43.0 From 6e063083543e8f9ef05cae51f61560e158dd2deb Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 4 Jun 2024 10:16:58 +0100 Subject: [PATCH 31/36] fix setup script --- Dockerfile | 5 +---- docker-compose.yml | 11 +++++++---- docker-resources/generate-instance.sh | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 94346edcf..0ce08eda7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,10 +56,7 @@ RUN ln -s $HOME/bin/pleroma_ctl /bin/akkoma_ctl ADD docker-entrypoint.sh $HOME/docker-entrypoint.sh -RUN adduser --system --home $HOME akkoma -USER akkoma - -ENV AKKOMA_CONFIG_PATH=/opt/akkoma/config/config.exs +ENV AKKOMA_CONFIG_PATH=/opt/akkoma/config/prod.secret.exs VOLUME uploads /opt/akkoma/uploads VOLUME instance /opt/akkoma/instance VOLUME config /opt/akkoma/config diff --git a/docker-compose.yml b/docker-compose.yml index 1b40f9086..57fe1457e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,8 @@ services: image: postgres:16-alpine shm_size: 4gb restart: unless-stopped + env_file: + - .env environment: { # This might seem insecure but is usually not a problem. # You should leave this at the "akkoma" default. @@ -14,13 +16,14 @@ services: POSTGRES_USER: akkoma, POSTGRES_PASSWORD: akkoma, } + user: ${DOCKER_USER} volumes: - ./pgdata:/var/lib/postgresql/data:z - akkoma: image: akkoma/akkoma:next restart: unless-stopped + user: ${DOCKER_USER} links: - db ports: [ @@ -34,9 +37,9 @@ services: "127.0.0.1:4000:4000", ] volumes: - - ./config:/opt/akkoma/config:z - - ./uploads:/opt/akkoma/uploads:z - - ./instance:/opt/akkoma/instance:z + - ./config:/opt/akkoma/config + - ./uploads:/opt/akkoma/uploads + - ./instance:/opt/akkoma/instance # Copy this into docker-compose.override.yml and uncomment there if you want to use a reverse proxy #proxy: diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh index 387975100..949ed1b6f 100755 --- a/docker-resources/generate-instance.sh +++ b/docker-resources/generate-instance.sh @@ -3,7 +3,6 @@ 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! @@ -22,6 +21,6 @@ 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" \ + -v "$(pwd)/config:/docker-entrypoint-initdb.d" \ db -- 2.43.0 From bb37aa3be55405a1b1efb623c5266d7f890a2d47 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 4 Jun 2024 10:21:13 +0100 Subject: [PATCH 32/36] put setup file in init.d --- docker-compose.yml | 1 + docker-resources/generate-instance.sh | 15 +-------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 57fe1457e..54faa7d56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: user: ${DOCKER_USER} volumes: - ./pgdata:/var/lib/postgresql/data:z + - ./config/setup_db.psql:/docker-entrypoint-initdb.d/setup_db.sql akkoma: image: akkoma/akkoma:next diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh index 949ed1b6f..3c8a310c5 100755 --- a/docker-resources/generate-instance.sh +++ b/docker-resources/generate-instance.sh @@ -5,22 +5,9 @@ set -euo pipefail mkdir -p pgdata # 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" \ 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 --output /opt/akkoma/config/generated_config.exs --output-psql /opt/akkoma/config/setup_db.psql -echo "" -echo "==========================" -echo "" -echo "Setting up your database!" - -docker compose start db - -docker compose run \ - --rm \ - -e "PGPASSWORD=akkoma" \ - -v "$(pwd)/config:/docker-entrypoint-initdb.d" \ - db - +echo "Instance generated!" \ No newline at end of file -- 2.43.0 From 3e8388e2de523beb313b7f8b083b4d1c892e5a0b Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 4 Jun 2024 10:23:06 +0100 Subject: [PATCH 33/36] use long syntax for bind --- docker-compose.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 54faa7d56..a396f421c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,8 +18,12 @@ services: } user: ${DOCKER_USER} volumes: - - ./pgdata:/var/lib/postgresql/data:z - - ./config/setup_db.psql:/docker-entrypoint-initdb.d/setup_db.sql + - type: bind + source: ./pgdata + target: /var/lib/postgresql/data + - type: bind + source: ./config/setup_db.psql + target: /docker-entrypoint-initdb.d/setup_db.sql akkoma: image: akkoma/akkoma:next -- 2.43.0 From 6ab2e960d7169966d8773f28b392f88637a2de0e Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 4 Jun 2024 10:24:31 +0100 Subject: [PATCH 34/36] mount directory --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a396f421c..8319e31c6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,8 +22,8 @@ services: source: ./pgdata target: /var/lib/postgresql/data - type: bind - source: ./config/setup_db.psql - target: /docker-entrypoint-initdb.d/setup_db.sql + source: ./config + target: /docker-entrypoint-initdb.d akkoma: image: akkoma/akkoma:next -- 2.43.0 From 569851f14c78e8b1449566428377d6d2537f0a5c Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 4 Jun 2024 10:27:50 +0100 Subject: [PATCH 35/36] fix setup --- docker-compose.yml | 4 ---- docker-resources/generate-instance.sh | 10 +++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8319e31c6..3ac94808f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,10 +21,6 @@ services: - type: bind source: ./pgdata target: /var/lib/postgresql/data - - type: bind - source: ./config - target: /docker-entrypoint-initdb.d - akkoma: image: akkoma/akkoma:next restart: unless-stopped diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh index 3c8a310c5..0598f5bdc 100755 --- a/docker-resources/generate-instance.sh +++ b/docker-resources/generate-instance.sh @@ -10,4 +10,12 @@ docker compose run \ -e "PLEROMA_CTL_RPC_DISABLED=true" \ 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 --output /opt/akkoma/config/generated_config.exs --output-psql /opt/akkoma/config/setup_db.psql -echo "Instance generated!" \ No newline at end of file +echo "Instance generated!" + +# setup database from generated config +# we run from the akkoma container to ensure we have the right environment! can't connect to a DB that doesn't exist yet... +docker compose run \ + --rm \ + -e "PLEROMA_CTL_RPC_DISABLED=true" \ + -e "PGPASSWORD=akkoma" \ + akkoma psql -h db -U akkoma -d akkoma -f /opt/akkoma/config/setup_db.psql \ No newline at end of file -- 2.43.0 From dbbfeeb7480885fa8a93a80d7358898b46218318 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 4 Jun 2024 11:40:49 +0100 Subject: [PATCH 36/36] Fix documentation --- .../docker-compose.pgsql-tuning.yml | 39 +++++++++ docker-resources/env.example | 5 ++ docker-resources/generate-instance.sh | 13 ++- docs/docs/installation/docker_en.md | 85 +++++++++---------- 4 files changed, 95 insertions(+), 47 deletions(-) create mode 100644 docker-resources/docker-compose.pgsql-tuning.yml create mode 100644 docker-resources/env.example diff --git a/docker-resources/docker-compose.pgsql-tuning.yml b/docker-resources/docker-compose.pgsql-tuning.yml new file mode 100644 index 000000000..7ac8c5ecd --- /dev/null +++ b/docker-resources/docker-compose.pgsql-tuning.yml @@ -0,0 +1,39 @@ +services: + db: + # If you use a config generator, use the value below for your + # "ram" size + shm_size: 4gb + command: + - "postgres" + - "-c" + - "max_connections=40" + - "-c" + - "shared_buffers=1GB" + - "-c" + - "effective_cache_size=3GB" + - "-c" + - "maintenance_work_mem=512MB" + - "-c" + - "checkpoint_completion_target=0.9" + - "-c" + - "wal_buffers=16MB" + - "-c" + - "default_statistics_target=500" + - "-c" + - "random_page_cost=1.1" + - "-c" + - "effective_io_concurrency=200" + - "-c" + - "work_mem=6553kB" + - "-c" + - "min_wal_size=4GB" + - "-c" + - "max_wal_size=16GB" + - "-c" + - "max_worker_processes=4" + - "-c" + - "max_parallel_workers_per_gather=2" + - "-c" + - "max_parallel_workers=4" + - "-c" + - "max_parallel_maintenance_workers=2" diff --git a/docker-resources/env.example b/docker-resources/env.example new file mode 100644 index 000000000..23ca15221 --- /dev/null +++ b/docker-resources/env.example @@ -0,0 +1,5 @@ +MIX_ENV=prod +ERL_EPMD_ADDRESS=127.0.0.1 +DB_NAME=akkoma +DB_USER=akkoma +DB_PASS=akkoma diff --git a/docker-resources/generate-instance.sh b/docker-resources/generate-instance.sh index 0598f5bdc..1f92d3d8d 100755 --- a/docker-resources/generate-instance.sh +++ b/docker-resources/generate-instance.sh @@ -8,9 +8,7 @@ mkdir -p pgdata docker compose run \ --rm \ -e "PLEROMA_CTL_RPC_DISABLED=true" \ - 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 --output /opt/akkoma/config/generated_config.exs --output-psql /opt/akkoma/config/setup_db.psql - -echo "Instance generated!" + 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 y --output /opt/akkoma/config/generated_config.exs --output-psql /opt/akkoma/config/setup_db.psql # setup database from generated config # we run from the akkoma container to ensure we have the right environment! can't connect to a DB that doesn't exist yet... @@ -18,4 +16,11 @@ docker compose run \ --rm \ -e "PLEROMA_CTL_RPC_DISABLED=true" \ -e "PGPASSWORD=akkoma" \ - akkoma psql -h db -U akkoma -d akkoma -f /opt/akkoma/config/setup_db.psql \ No newline at end of file + akkoma psql -h db -U akkoma -d akkoma -f /opt/akkoma/config/setup_db.psql + +# stop tzdata trying to write to places it shouldn't +echo "config :tzdata, :data_dir, "/var/tmp/elixir_tzdata_storage" >> /opt/akkoma/config/generated_config.exs + +echo "Instance generated!" + +echo "Make sure you check your config and copy it to config/prod.secret.exs before starting the instance!" \ No newline at end of file diff --git a/docs/docs/installation/docker_en.md b/docs/docs/installation/docker_en.md index 9551b034a..d586876e4 100644 --- a/docs/docs/installation/docker_en.md +++ b/docs/docs/installation/docker_en.md @@ -28,31 +28,14 @@ echo "DOCKER_USER=$(id -u):$(id -g)" >> .env This probably won't need to be changed, it's only there to set basic environment variables for the docker compose file. -### Building the container - -The container provided is a thin wrapper around akkoma's dependencies, -it does not contain the code itself. This is to allow for easy updates -and debugging if required. - -```bash -./docker-resources/build.sh -``` - -This will generate a container called `akkoma` which we can use -in our compose environment. - ### Generating your instance ```bash mkdir pgdata -./docker-resources/manage.sh mix deps.get -./docker-resources/manage.sh mix compile -./docker-resources/manage.sh mix pleroma.instance gen +./docker-resources/generate-instance.sh ``` -This will ask you a few questions - the defaults are fine for most things, -the database hostname is `db`, the database password is `akkoma` -(not auto generated), and you will want to set the ip to `0.0.0.0`. +This will ask you a few questions - the defaults are fine for most things! Now we'll want to copy over the config it just created @@ -60,24 +43,6 @@ Now we'll want to copy over the config it just created cp config/generated_config.exs config/prod.secret.exs ``` -### Setting up the database - -We need to run a few commands on the database container, this isn't too bad - -```bash -docker compose run --rm --user akkoma -d db -# Note down the name it gives here, it will be something like akkoma_db_run -docker compose run --rm akkoma psql -h db -U akkoma -f config/setup_db.psql -docker stop akkoma_db_run # Replace with the name you noted down -``` - -Now we can actually run our migrations - -```bash -./docker-resources/manage.sh mix ecto.migrate -# this will recompile your files at the same time, since we changed the config -``` - ### Start the server We're going to run it in the foreground on the first run, just to make sure @@ -102,7 +67,7 @@ docker compose up -d If your instance is up and running, you can create your first user with administrative rights with the following task: ```shell -./docker-resources/manage.sh mix pleroma.user new MY_USERNAME MY_EMAIL@SOMEWHERE --admin +./docker-resources/manage.sh user new MY_USERNAME MY_EMAIL@SOMEWHERE --admin ``` And follow the prompts @@ -154,23 +119,43 @@ If you want, you can also run the reverse proxy on the host. This is a bit more Follow the guides for source install for your distribution of choice, or adapt as needed. Your standard setup can be found in the [Debian Guide](../debian_based_en/#nginx) +### Applying Postgresql optimisations + +Your postgresql server will behave better if you tune its settings to your machine. + +There is a file at `docker-resources/docker-compose.pgsql-tuning.yml` which shows you how to apply settings, for example +those generated by [PgTune](https://pgtune.leopard.in.ua/) + +You can merge this config into a `docker-compose.override.yml` file to apply them. Make sure that you generate your options +based on the shm_size you allocate! + ### You're done! All that's left is to set up your frontends. -The standard from-source commands will apply to you, just make sure you +The standard OTP commands will apply to you, just make sure you prefix them with `./docker-resources/manage.sh`! +So, for example, if an OTP command would be + +``` +./bin/pleroma_ctl user new myuser +``` + +The equivalent docker command would be + +``` +./docker-resources/manage.sh user new myuser +``` + {! installation/frontends.include !} ### Updating Docker Installs ```bash git pull -./docker-resources/build.sh -./docker-resources/manage.sh mix deps.get -./docker-resources/manage.sh mix compile -./docker-resources/manage.sh mix ecto.migrate +docker compose pull +./docker-resources/manage.sh migrate docker compose restart akkoma db ``` @@ -180,6 +165,20 @@ create a new file called `docker-compose.override.yml`. There you can add any overrides or additional services without worrying about git conflicts when a new release comes out. +### Migrating from the old docker install system + +If you were running akkoma in docker before 2024.06, you will need to do a few little migration steps. + +First off, we need to migrate our postgres installation to a newer version! + +```bash +./docker-resources/migrate-postgresql-version.sh pgdata 14 16 +``` + +This should be nice and quick. + +After that you can just `docker compose pull` and all should be fine. + #### Further reading {! installation/further_reading.include !} -- 2.43.0