From 6c114c45dc27746b88b720fb275648da3b96c7ef Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Sat, 14 Oct 2023 18:44:32 +0200 Subject: [PATCH] Initial commit --- .gitignore | 4 +++ Dockerfile | 58 +++++++++++++++++++++++++++++++++++++++++ README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 57 +++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 246 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100755 entrypoint.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..365938e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +config/ +pgdata/ +static/ +uploads/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..db0eb90 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +FROM hexpm/elixir:1.15.4-erlang-26.0.2-alpine-3.18.2 as otp +ARG MIX_ENV="prod" +ARG TMPDIR="/tmp/akkoma" +ARG BUILD_TAG="v3.10.2" +ARG PLEROMA_BUILD_BRANCH=${BUILD_TAG} +# install dependencies +RUN apk add git gcc g++ musl-dev make cmake file-dev rclone wget zip imagemagick +# get source +RUN wget \ + -O /tmp/akkoma.tar.gz \ + https://akkoma.dev/AkkomaGang/akkoma/archive/${BUILD_TAG}.tar.gz +RUN mkdir -p ${TMPDIR} +RUN tar -C ${TMPDIR} --strip-components=1 -xvf /tmp/akkoma.tar.gz +WORKDIR ${TMPDIR} +# clean +RUN (rm -rf release || true) && (rm -rf _build || true) && (rm -rf /root/.mix) +# setup-hex +RUN mix local.hex --force && mix local.rebar --force +# mix-clean +RUN mix deps.clean --all && mix clean +RUN mix deps.get --only prod +RUN mix release --path $TMPDIR/release + +FROM alpine:3.18 as akkoma-basic-alpine +ARG AKKOMADIR="/akkoma" +ARG TMPDIR="/tmp/akkoma" +COPY --from=otp ${TMPDIR}/release ${AKKOMADIR} +# dependencies +RUN apk add postgresql-client +# optional dependencies +RUN apk add imagemagick ffmpeg exiftool + +WORKDIR ${AKKOMADIR} +EXPOSE 4000 +ENV AKKOMADIR=${AKKOMADIR} +ENV DB_USER=postgres +ENV DB_HOST=db +ENV DB_NAME=${DB_USER} +ENV DB_PASS=postgres +ENV INSTANCE_DOMAIN=akkoma.example.com +ENV INSTANCE_NAME=Akkoma +ENV INSTANCE_ADMIN_EMAIL=admin@example.com +ENV INSTANCE_NOTIFY_EMAIL=info@example.com +# allow search engines to index site +# one of [y,n] +ENV INSTANCE_INDEX=y +# enables configuration via AdminFE +# one of [y,n] +ENV INSTANCE_ADMINFE=y +# one of [y,n] +ENV STRIP_UPLOADS=y +# one of [y,n] +ENV ANONYMIZE_UPLOADS=n +# one of [y,n] +ENV DEDUPLICATE_UPLOADS=n + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT /entrypoint.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..829f32b --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +# akkoma-basic-alpine +Unofficial [Akkoma](https://akkoma.social) docker image based on [Alpine Linux](https://alpinelinux.org), +focused on putting as many files into the docker file as possible, +to reduce the hassle of git fetching the latest stable version +and breaking your instance in the process. + +Sound like a /me/ problem - I known, +but that is why I created this image. + +## Usage +You can *auto-deploy* this image using docker-compose: +```bash +docker compose build +docker compose up +``` +or use the pre-built images available on codeberg. + +## Configuration +Initial configuration can be done using environment variables. + +## Post-installl +After starting your server, +you might want to install the UI or setup users. + +To do so, you have to connect to the running `akkoma` container, +by running the following command: +```bash +docker container exec -it /bin/ash +``` + +Afterwards you can access the pleroma commands from the containers shell. + +If you don't know the container name, +have a look at the list of all running containers +and try to find the akkoma container, +which is using the `akkoma-basic-alpine` image: +```bash +docker container ls +``` + + +### Creating a user +Users can be created using the `pleroma_ctl` command: +```bash +/akkoma/bin/pleroma_ctl user new [option ...] +``` +For more information, refer to the [official documentation](https://docs.akkoma.dev/stable/administration/CLI_tasks/user/) + +### Installing frontends +Frontends can be installed using the `pleroma_ctl` command: +```bash +/akkoma/bin/pleroma_ctl frontend install +``` + +For example to install `pleroma-fe` and the `admin-fe` frontends: +```bash +# pleroma-fe +/akkoma/bin/pleroma_ctl frontend install pleroma-fe --ref stable +# admin-fe + /akkoma/bin/pleroma_ctl frontend install admin-fe --ref stable +``` + +Additional information is available in the [official documentation](https://docs.akkoma.dev/stable/administration/CLI_tasks/frontend/) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6363441 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,57 @@ +--- +version: "3.7" + +services: + db: + image: postgres:16-alpine + restart: unless-stopped + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + volumes: + - ./pgdata:/var/lib/postgresql/data + + akkoma: + image: akkoma-basic-alpine:latest + build: . + restart: unless-stopped + links: + - db + ports: + - "4000:4000" + environment: + ####################################### + # DATABASE CONFIGURATION + # you don't have to change this, + # because the database isn't accessible from the outside + ####################################### + - DB_HOST=db + - DB_USER=postgres + - DB_NAME=postgres + - DB_PASS=postgres + ####################################### + # AKKOMA CONFIGURATION + ####################################### + # domain of the instance + - INSTANCE_DOMAIN=akkoma.example.com + # display name of the instance + - INSTANCE_NAME=Akkoma + # email of the admin user + # (the admin user ISN'T automatically created, use this as a contact email instead) + - INSTANCE_ADMIN_EMAIL=admin@example.com + # email used to send notifications + - INSTANCE_NOTIFY_EMAIL=info@example.com + # allow search engines to index your instance + - INSTANCE_INDEX=y + # remove GPS data from uploads + - STRIP_UPLOADS=y + # anonymize uploads + - ANONYMIZE_UPLOADS=n + # use image hash to remove duplicates + # might save storage space + # ingreases upload duration + - DEDUPLICATE_UPLOADS=n + volumes: + - ./config:/akkoma/config + - ./static:/akkoma/static + - ./uploads:/akkoma/uploads diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..e4f8662 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +set -e + +export DB_PORT=5432 +export AKKOMA_CONFIG_PATH=$AKKOMADIR/config/config.exs +export AKKOMA_DB_PATH=$AKKOMADIR/config/setup_db.psql + +function dbwait() { + echo "-- Waiting for database..." + while ! pg_isready -U ${DB_USER} -h ${DB_HOST} -p ${DB_PORT} -t 1; do + sleep 1s + done +} + +if [ ! -f $AKKOMA_CONFIG_PATH ]; then + echo "-- Generating instance configuration --" + mkdir -p $(dirname $AKKOMA_CONFIG_PATH) + $AKKOMADIR/bin/pleroma_ctl instance gen \ + --output $AKKOMA_CONFIG_PATH \ + --output-psql $AKKOMA_DB_PATH \ + --domain "$INSTANCE_DOMAIN" \ + --instance-name "$INSTANCE_NAME" \ + --admin-email "$INSTANCE_ADMIN_EMAIL" \ + --notify-email "$INSTANCE_NOTIFY_EMAIL" \ + --dbhost "$DB_HOST" \ + --dbname "$DB_NAME" \ + --dbuser "$DB_USER" \ + --dbpass "$DB_PASS" \ + --rum N \ + --indexable "$INSTANCE_INDEX" \ + --db-configurable "$INSTANCE_ADMINFE" \ + --uploads-dir "$AKKOMADIR/uploads" \ + --static-dir "$AKKOMADIR/static" \ + --listen-ip "0.0.0.0" \ + --listen-port "4000" \ + --strip-uploads "$STRIP_UPLOADS" \ + --anonymize-uploads "$ANONYMIZE_UPLOADS" \ + --dedupe-uploads "$DEDUPLICATE_UPLOADS" + echo "-- Generated instance config --" +fi + +if [ -f $AKKOMA_DB_PATH ]; then + echo "-- Initializing database --" + dbwait + echo "$DB_PASS" | \ + psql \ + -h "$DB_HOST" \ + -p "$DB_PORT" \ + -U "$DB_USER" \ + -f $AKKOMA_DB_PATH \ + "$DB_NAME" + rm $AKKOMA_DB_PATH + + echo "-- Initialized database --" +fi + +dbwait() + +echo "-- Running migrations..." +$AKKOMADIR/bin/pleroma_ctl migrate + +echo "-- Starting!" +$AKKOMADIR/bin/pleroma start -- 2.38.5