Browse Source

Update structure

keep-around/1d41123a1244c0fde37bb8c5c7d02b7245f2751a
sn0w 1 year ago
parent
commit
99f9c49151
13 changed files with 319 additions and 178 deletions
  1. 1
    1
      .dockerignore
  2. 26
    2
      .env.dist
  3. 71
    0
      .gitignore
  4. 0
    6
      .gitmodules
  5. 64
    0
      README.md
  6. 0
    0
      custom.d/.gitkeep
  7. 7
    9
      docker-compose.m4
  8. 25
    47
      entrypoint.ash
  9. 1
    0
      initdb.sql
  10. 0
    1
      pleroma
  11. 108
    0
      pleroma
  12. 16
    3
      pleroma.dockerfile
  13. 0
    109
      pleroma.sh

+ 1
- 1
.dockerignore View File

@@ -1 +1 @@
data
data/

+ 26
- 2
.env.dist View File

@@ -1,26 +1,50 @@
### Docker settings ###

# The docker network to bind to.
# (Useful for reverse-proxies outside of this compose).
# (Defaults to "pleroma_docker_1")
DOCKER_NETWORK=

# The directory where all containers store their data.
# Can be a relative path, "~/...", or absolute.
DOCKER_DATADIR=

# Database settings
### Database settings ###
POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=

# Pleroma Settings
### Pleroma Settings ###

# The env to use
MIX_ENV=

# The git tag or branch to check out on build
PLEROMA_VERSION=

# The domain/scheme/port where pleroma will be hosted
PLEROMA_URL=
PLEROMA_SCHEME=
PLEROMA_PORT=

# The seed for your secret keys
# (Enter something as random as possible)
PLEROMA_SECRET_KEY_BASE=

# The name of your instance
PLEROMA_NAME=

# Your contact info
PLEROMA_ADMIN_EMAIL=

# User settings
PLEROMA_USER_LIMIT=
PLEROMA_REGISTRATIONS_OPEN=

# Media proxy
PLEROMA_MEDIA_PROXY_ENABLED=
PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE=
PLEROMA_MEDIA_PROXY_URL=

# DB
PLEROMA_DB_POOL_SIZE=

+ 71
- 0
.gitignore View File

@@ -1,2 +1,73 @@
data
.env
custom.d/
!custom.d/.gitkeep
docker-compose.yml

# Created by https://www.gitignore.io/api/osx,linux,windows

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


# End of https://www.gitignore.io/api/osx,linux,windows

+ 0
- 6
.gitmodules View File

@@ -1,6 +0,0 @@
[submodule "pleroma"]
path = pleroma
url = git@git.pleroma.social:pleroma/pleroma.git
[submodule "camo"]
path = camo
url = https://github.com/atmos/camo.git

+ 64
- 0
README.md View File

@@ -0,0 +1,64 @@
# Pleroma-Docker

[Pleroma](https://pleroma.social/) is a selfhosted social network that uses OStatus/ActivityPub.

This repository is my attempt to dockerize it for easier deployment.

## Features

- 100% generic
- Everything is customizable
- Everything is configurable through `.env` files
- Zero special host dependencies
- "It just works"

## Assumptions

This repo assumes that you're using Træfik as your auto-configuring reverse proxy.

## Tutorial

- Make sure that `m4` and `docker-compose` are installed
- Check out this repo
- Create your env file (`cp .env.dist .env`)
- Edit the env values
- Run `./pleroma build`
- Run `./pleroma run`
- ...
- Profit!

## Building an image

Since this setup injects code into pleroma that moves it's configuration into the environment (ref ["The Twelve-Factor App"](https://12factor.net/)), the image is 100% reusable and can be shared/replicated across multiple hosts. To do that just run `./pleroma build` as usual and then tag your image to whatever you want. Just make sure to start the container with `env_file:` or all required `-e` pairs.

## Customizing Pleroma

Just add your customizations (and their folder structure) to `custom.d`.<br>
They will be copied into the right place when the container starts.<br>
You can even replace/patch pleroma's code with this, because the project is recompiled at startup.

In general: Prepending `custom.d` to pleroma's customization guides should work all the time.<br>
Check them out in the [official pleroma wiki](https://git.pleroma.social/pleroma/pleroma/wikis/home).

Here are a few customization examples:

- I want to have a custom thumbnail
- Save it in `custom.d/priv/static/instance/thumbnail.jpeg`

- I want to change the `config.json`.
- Just use [the template](https://git.pleroma.social/pleroma/pleroma/blob/develop/priv/static/static/config.json) and save it in `custom.d/priv/static/static/config.json`

- I want to change the background
- Throw an image into `custom.d/priv/static/static` and then edit the config from above

- I want a custom logo
- See above

- I need blobs. Give me emojis.
- Save them in `custom.d/priv/static/emoji`. Then create and/or edit `custom.d/config/custom_emoji.txt`.

- I want custom ToS
- Throw a HTML document to `priv/static/static/terms-of-service.html`

You get the gist.<br>
Pretty basic stuff.

+ 0
- 0
custom.d/.gitkeep View File


+ 7
- 9
docker-compose.m4 View File

@@ -3,6 +3,7 @@ define(`upcase', `translit($1, `a-z', `A-Z')')
define(`env', `upcase($1): ${upcase($1):?upcase($1)}')
define(`env_fb', `upcase($1): ${upcase($1):-$2}')
define(`env_inline', `${upcase($1):?upcase($1)}')
define(`env_inline_fb', `${upcase($1):-$2}')
divert(1)dnl

version: "3"
@@ -10,7 +11,7 @@ version: "3"
networks:
default:
external:
name: env_inline(`docker_network')
name: env_inline_fb(`docker_network', `pleroma_docker_1')

services:
db:
@@ -22,11 +23,15 @@ services:
env(`postgres_password')
volumes:
- env_inline(`docker_datadir')/db:/var/lib/postgresql/data
- ./initdb.sql:/docker-entrypoint-initdb.d/pleroma.sql

server:
build:
context: .
dockerfile: ./pleroma.dockerfile
args:
env(`pleroma_version')
env_fb(`mix_env', `prod')
restart: unless-stopped
links:
- db
@@ -49,16 +54,9 @@ services:
env(`pleroma_media_proxy_url')
env(`pleroma_db_pool_size')

env_fb(`pleroma_workspace', `/pleroma')
env_fb(`mix_archives', `/mix/archives')
env_fb(`mix_home', `/mix/home')
env_fb(`mix_env', `prod')
volumes:
- ./pleroma:/pleroma
- env_inline(`docker_datadir')/pleroma:/data
- env_inline(`docker_datadir')/mix:/mix
- env_inline(`docker_datadir')/misc/cache:/root/.cache
- env_inline(`docker_datadir')/misc/meta:/meta
- ./custom.d:/custom.d
labels:
traefik.enable: "true"
traefik.fe.port: "4000"

+ 25
- 47
entrypoint.ash View File

@@ -2,54 +2,32 @@

set -e

function action__build {
mix local.hex --force
mix local.rebar --force
mix deps.get
mix compile
}

function action__configure {
mix generate_config
}

function action__run {
if [[ ! -f /meta/ECTO_REPO_CREATED ]]; then
mix ecto.create
touch /meta/ECTO_REPO_CREATED
fi

mix ecto.migrate
exec mix phx.server
}

if [[ -z "$1" ]]; then
echo "No action provided."
exit 1
# Ensure that the environment is clean
if [[ -d /pleroma-runtime ]]; then
rm -rf /pleroma-runtime
fi
mkdir /pleroma-runtime

if [[ -z "$PLEROMA_WORKSPACE" ]]; then
echo "Please set the PLEROMA_WORKSPACE variable to your pleroma root."
exit 1
fi
# Copy sources
rsync -azI /pleroma/ /pleroma-runtime/

cd $PLEROMA_WORKSPACE
if [[ ! -L config/prod.secret.exs ]]; then
rm -f config/prod.secret.exs
ln -s /docker-config.exs config/prod.secret.exs
fi
if [[ ! -L config/dev.secret.exs ]]; then
rm -f config/dev.secret.exs
ln -s /docker-config.exs config/dev.secret.exs
fi
# Copy overrides
rsync -azI /custom.d/ /pleroma-runtime/

# Go to runtime workspace
cd /pleroma-runtime

# Make sure that the tooling is present
mix local.hex --force
mix local.rebar --force

# Recompile
mix deps.get
mix clean && mix compile

# Prepare DB
mix ecto.create
mix ecto.migrate

case "$1" in
build) action__build;;
configure) action__configure;;
run) action__run;;
*)
echo "The action '$1' is invalid."
exit 1
;;
esac
shift
# Liftoff o/
exec mix phx.server

+ 1
- 0
initdb.sql View File

@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS citext;

+ 0
- 1
pleroma

@@ -1 +0,0 @@
Subproject commit 8f9bcc4ab0b16efa9168f49f6e2cc14bc424d398

+ 108
- 0
pleroma View File

@@ -0,0 +1,108 @@
#!/bin/bash

set -e

function log_generic { # $1: color, $2: prefix, $3: message #
echo -e "[$(tput setaf $1)$(tput bold)$2$(tput sgr0)] $3"
}

function log_error { # $1: message #
log_generic 1 ERR "$1"
}

function log_ok { # $1: message #
log_generic 2 "OK " "$1"
}

function log_info { # $1: message #
log_generic 4 INF "$1"
}

function print_help {
echo "
Pleroma Maintenance Script

Usage:
$0 [action] [flags]

Actions:
start Start pleroma and sibling services
stop Stop pleroma and sibling services
restart Executes #stop and #start respectively.
logs Show the current container logs
enter Enter the pleroma container for debugging/maintenance
"
}

function run_dockerized {
log_info "Stopping existing containers (if any)"
docker-compose down

log_info "Rebuilding images"
docker-compose build

log_info "Running action '$1'"
docker-compose run server $1

log_info "Cleaning up.."
docker-compose down
}

function action__start {
log_info "Booting pleroma"
docker-compose up --remove-orphans -d
log_ok "Done"
}

function action__stop {
log_info "Stopping pleroma"
docker-compose down
log_ok "Done"
}

function action__logs {
docker-compose logs -f
}

function action__build {
docker-compose build
}

function action__enter {
docker-compose exec server ash
}

function prepare {
log_info "Preparing script"
m4 docker-compose.m4 > docker-compose.yml
}

function cleanup {
log_info "Cleaning up"
rm docker-compose.yml
}

trap "cleanup" INT TERM EXIT

if [[ -z "$1" ]]; then
log_error "No action provided."
print_help
exit 1
fi

prepare

case "$1" in
build) action__build;;
start) action__start;;
stop) action__stop;;
restart) action__start; action__stop; ;;
logs) action__logs;;
enter) action__enter;;
*)
log_error "The action '$1' is invalid."
print_help
exit 1
;;
esac
shift

+ 16
- 3
pleroma.dockerfile View File

@@ -1,12 +1,25 @@
FROM elixir:1.6-alpine

RUN apk add --no-cache --virtual .build alpine-sdk git
WORKDIR /pleroma

# Prepare system
RUN apk add --no-cache --virtual .build alpine-sdk git rsync

# Perform a clone that can be cached
RUN git clone https://git.pleroma.social/pleroma/pleroma.git .

# Prepare pleroma
ADD ./docker-config.exs /docker-config.exs
ARG PLEROMA_VERSION
RUN \
git checkout $PLEROMA_VERSION && \
git pull --rebase --autostash && \
ln -s /docker-config.exs config/prod.secret.exs && \
ln -s /docker-config.exs config/dev.secret.exs

# Register entrypoint
ADD ./entrypoint.ash /
RUN chmod +x /entrypoint.ash
ENTRYPOINT ["/entrypoint.ash"]
CMD ["run"]
CMD ["/entrypoint.ash"]

EXPOSE 4000

+ 0
- 109
pleroma.sh View File

@@ -1,109 +0,0 @@
#!/bin/bash

set -e

function log_generic { # $1: color, $2: prefix, $3: message #
echo -e "[$(tput setaf $1)$(tput bold)$2$(tput sgr0)] $3"
}

function log_error { # $1: message #
log_generic 1 ERR "$1"
}

function log_ok { # $1: message #
log_generic 2 "OK " "$1"
}

function log_info { # $1: message #
log_generic 4 INF "$1"
}

function print_help {
echo "
Pleroma Maintenance Script

Usage:
$0 [action] [flags]

Actions:
build Build the pleroma container and all dependencies
configure Runs the interactive configuration script
run Start pleroma and sibling services
stop Stop pleroma and sibling services
logs Show the current container logs
"
}

function run_dockerized {
log_info "Stopping existing containers (if any)"
docker-compose down

log_info "Rebuilding images"
docker-compose build

log_info "Running action '$1'"
docker-compose run server $1

log_info "Cleaning up.."
docker-compose down
}

function action__build {
run_dockerized "build"
log_ok "Done"
}

function action__configure {
run_dockerized "configure"
log_ok "Done"
}

function action__run {
log_info "Booting pleroma"
docker-compose up --remove-orphans -d
log_ok "Done"
}

function action__stop {
log_info "Stopping pleroma"
docker-compose down
log_ok "Done"
}

function action__logs {
docker-compose logs -f
}

function prepare {
log_info "Preparing script"
m4 docker-compose.m4 > docker-compose.yml
}

function cleanup {
log_info "Cleaning up"
rm docker-compose.yml
}

trap "cleanup" INT TERM EXIT

if [[ -z "$1" ]]; then
log_error "No action provided."
print_help
exit 1
fi

prepare

case "$1" in
build) action__build;;
configure) action__configure;;
run) action__run;;
stop) action__stop;;
logs) action__logs;;
*)
log_error "The action '$1' is invalid."
print_help
exit 1
;;
esac
shift

Loading…
Cancel
Save