diff --git a/.dockerignore b/.dockerignore index 89cf5ee31..1d4f80bdf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,6 +10,8 @@ test benchmarks docs/site docker-db +uploads +instance # Required to get version !.git diff --git a/.gitignore b/.gitignore index eba0fcadf..e7ddb7dc1 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,8 @@ vm.args .hex/ .mix/ .psql_history +docker-resources/Dockerfile +pgdata # Prevent committing custom emojis /priv/static/emoji/custom/* diff --git a/Dockerfile b/Dockerfile index 80c098500..730730ce3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -FROM hexpm/elixir:1.13.4-erlang-24.3.4.5-alpine-3.15.6 as build - +FROM hexpm/elixir:1.13.4-erlang-24.3.4.5-alpine-3.15.6 ENV MIX_ENV=prod diff --git a/docker-compose.yml b/docker-compose.yml index 2de1d62fc..a43f21be4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,8 @@ version: "3.7" services: db: - image: postgres:14 + image: akkoma-db:latest + build: ./docker-resources/database restart: unless-stopped user: ${DOCKER_USER} environment: { @@ -19,7 +20,9 @@ services: env_file: - .env volumes: - - ./docker-db:/var/lib/postgresql/data + - type: bind + source: ./pgdata + target: /var/lib/postgresql/data akkoma: image: akkoma:latest @@ -41,3 +44,16 @@ services: ] volumes: - .:/opt/akkoma + + # Uncomment the following if you want to use a reverse proxy + proxy: + image: caddy:2-alpine + restart: unless-stopped + links: + - akkoma + ports: [ + "443:443", + "80:80" + ] + volumes: + - ./docker-resources/Caddyfile:/etc/caddy/Caddyfile \ No newline at end of file diff --git a/docker-resources/Caddyfile b/docker-resources/Caddyfile new file mode 100644 index 000000000..4db738c3a --- /dev/null +++ b/docker-resources/Caddyfile @@ -0,0 +1,14 @@ +# default docker Caddyfile config for Akkoma +# +# Simple installation instructions: +# 1. Replace 'example.tld' with your instance's domain wherever it appears. + +akkoma.local.live { + log { + output file /var/log/caddy/akkoma.log + } + + encode gzip + + reverse_proxy akkoma:4000 +} diff --git a/docker-resources/Caddyfile.example b/docker-resources/Caddyfile.example new file mode 100644 index 000000000..47b8c7c74 --- /dev/null +++ b/docker-resources/Caddyfile.example @@ -0,0 +1,14 @@ +# default docker Caddyfile config for Akkoma +# +# Simple installation instructions: +# 1. Replace 'example.tld' with your instance's domain wherever it appears. + +example.tld { + log { + output file /var/log/caddy/akkoma.log + } + + encode gzip + + reverse_proxy akkoma:4000 +} diff --git a/docker-resources/database/Dockerfile b/docker-resources/database/Dockerfile new file mode 100644 index 000000000..2a38dd16b --- /dev/null +++ b/docker-resources/database/Dockerfile @@ -0,0 +1,10 @@ +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/manage.sh b/docker-resources/manage.sh new file mode 100755 index 000000000..944f5e2e2 --- /dev/null +++ b/docker-resources/manage.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run --rm akkoma $@ diff --git a/docs/docs/installation/docker_en.md b/docs/docs/installation/docker_en.md index a657c7488..a176787a6 100644 --- a/docs/docs/installation/docker_en.md +++ b/docs/docs/installation/docker_en.md @@ -49,7 +49,9 @@ in our compose environment. ``` This will ask you a few questions - the defaults are fine for most things, -the database hostname is `db`. +the database hostname is `db`, and you will want to set the ip to `0.0.0.0` +if you want to access the instance from outside the container (i.e you're using +a reverse proxy on the host) Now we'll want to copy over the config it just created @@ -62,7 +64,7 @@ cp config/generated_config.exs config/prod.secret.exs We need to run a few commands on the database container, this isn't too bad ```bash -docker-compose run --rm -d db +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 @@ -83,14 +85,47 @@ everything start up. ```bash docker-compose up ``` -#### Create your first user + +If everything went well, you should be able to access your instance at http://localhost:4000 + +You can `ctrl-c` out of the docker-compose now to shutdown the server. + +### Running in the background + +```bash +docker-compose up -d +``` + +### Create your first user If your instance is up and running, you can create your first user with administrative rights with the following task: ```shell -doas -u akkoma env MIX_ENV=prod mix pleroma.user new --admin +./docker-resources/manage.sh mix pleroma.user new MY_USERNAME MY_EMAIL@SOMEWHERE --admin ``` +And follow the prompts + +### Reverse proxies + +This is a tad more complex in docker than on the host itself. It + +You've got two options. + +#### Running caddy in a container + +This is by far the easiest option. It'll handle HTTPS and all that for you. + +```bash +cp docker-resources/Caddyfile.example docker-resources/Caddyfile +``` + +Then edit the TLD in your caddyfile to the domain you're serving on. + +Uncomment the `caddy` section in the docker-compose file, +then run `docker-compose up -d` again. + +```bash {! installation/frontends.include !} #### Further reading