Update structure

This commit is contained in:
sn0w 2018-04-08 22:49:07 +02:00
parent 3b84dfd5cf
commit 99f9c49151
12 changed files with 319 additions and 178 deletions

View File

@ -1 +1 @@
data data/

View File

@ -1,26 +1,50 @@
### Docker settings ###
# The docker network to bind to. # The docker network to bind to.
# (Useful for reverse-proxies outside of this compose). # (Useful for reverse-proxies outside of this compose).
# (Defaults to "pleroma_docker_1")
DOCKER_NETWORK= DOCKER_NETWORK=
# The directory where all containers store their data. # The directory where all containers store their data.
# Can be a relative path, "~/...", or absolute. # Can be a relative path, "~/...", or absolute.
DOCKER_DATADIR= DOCKER_DATADIR=
# Database settings ### Database settings ###
POSTGRES_DB= POSTGRES_DB=
POSTGRES_USER= POSTGRES_USER=
POSTGRES_PASSWORD= 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_URL=
PLEROMA_SCHEME= PLEROMA_SCHEME=
PLEROMA_PORT= PLEROMA_PORT=
# The seed for your secret keys
# (Enter something as random as possible)
PLEROMA_SECRET_KEY_BASE= PLEROMA_SECRET_KEY_BASE=
# The name of your instance
PLEROMA_NAME= PLEROMA_NAME=
# Your contact info
PLEROMA_ADMIN_EMAIL= PLEROMA_ADMIN_EMAIL=
# User settings
PLEROMA_USER_LIMIT= PLEROMA_USER_LIMIT=
PLEROMA_REGISTRATIONS_OPEN= PLEROMA_REGISTRATIONS_OPEN=
# Media proxy
PLEROMA_MEDIA_PROXY_ENABLED= PLEROMA_MEDIA_PROXY_ENABLED=
PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE= PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE=
PLEROMA_MEDIA_PROXY_URL= PLEROMA_MEDIA_PROXY_URL=
# DB
PLEROMA_DB_POOL_SIZE= PLEROMA_DB_POOL_SIZE=

71
.gitignore vendored
View File

@ -1,2 +1,73 @@
data data
.env .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

6
.gitmodules vendored
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
README.md Normal file
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
custom.d/.gitkeep Normal file
View File

View File

@ -3,6 +3,7 @@ define(`upcase', `translit($1, `a-z', `A-Z')')
define(`env', `upcase($1): ${upcase($1):?upcase($1)}') define(`env', `upcase($1): ${upcase($1):?upcase($1)}')
define(`env_fb', `upcase($1): ${upcase($1):-$2}') define(`env_fb', `upcase($1): ${upcase($1):-$2}')
define(`env_inline', `${upcase($1):?upcase($1)}') define(`env_inline', `${upcase($1):?upcase($1)}')
define(`env_inline_fb', `${upcase($1):-$2}')
divert(1)dnl divert(1)dnl
version: "3" version: "3"
@ -10,7 +11,7 @@ version: "3"
networks: networks:
default: default:
external: external:
name: env_inline(`docker_network') name: env_inline_fb(`docker_network', `pleroma_docker_1')
services: services:
db: db:
@ -22,11 +23,15 @@ services:
env(`postgres_password') env(`postgres_password')
volumes: volumes:
- env_inline(`docker_datadir')/db:/var/lib/postgresql/data - env_inline(`docker_datadir')/db:/var/lib/postgresql/data
- ./initdb.sql:/docker-entrypoint-initdb.d/pleroma.sql
server: server:
build: build:
context: . context: .
dockerfile: ./pleroma.dockerfile dockerfile: ./pleroma.dockerfile
args:
env(`pleroma_version')
env_fb(`mix_env', `prod')
restart: unless-stopped restart: unless-stopped
links: links:
- db - db
@ -49,16 +54,9 @@ services:
env(`pleroma_media_proxy_url') env(`pleroma_media_proxy_url')
env(`pleroma_db_pool_size') 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') env_fb(`mix_env', `prod')
volumes: volumes:
- ./pleroma:/pleroma - ./custom.d:/custom.d
- 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
labels: labels:
traefik.enable: "true" traefik.enable: "true"
traefik.fe.port: "4000" traefik.fe.port: "4000"

View File

@ -2,54 +2,32 @@
set -e set -e
function action__build { # Ensure that the environment is clean
mix local.hex --force if [[ -d /pleroma-runtime ]]; then
mix local.rebar --force rm -rf /pleroma-runtime
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
fi fi
mkdir /pleroma-runtime
if [[ -z "$PLEROMA_WORKSPACE" ]]; then # Copy sources
echo "Please set the PLEROMA_WORKSPACE variable to your pleroma root." rsync -azI /pleroma/ /pleroma-runtime/
exit 1
fi
cd $PLEROMA_WORKSPACE # Copy overrides
if [[ ! -L config/prod.secret.exs ]]; then rsync -azI /custom.d/ /pleroma-runtime/
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
case "$1" in # Go to runtime workspace
build) action__build;; cd /pleroma-runtime
configure) action__configure;;
run) action__run;; # Make sure that the tooling is present
*) mix local.hex --force
echo "The action '$1' is invalid." mix local.rebar --force
exit 1
;; # Recompile
esac mix deps.get
shift mix clean && mix compile
# Prepare DB
mix ecto.create
mix ecto.migrate
# Liftoff o/
exec mix phx.server

1
initdb.sql Normal file
View File

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

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

108
pleroma Executable file
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

View File

@ -1,12 +1,25 @@
FROM elixir:1.6-alpine 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 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 / ADD ./entrypoint.ash /
RUN chmod +x /entrypoint.ash RUN chmod +x /entrypoint.ash
ENTRYPOINT ["/entrypoint.ash"] CMD ["/entrypoint.ash"]
CMD ["run"]
EXPOSE 4000 EXPOSE 4000

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