From d5ad29eef4a6963cf3dda8972573c1322bdafcf4 Mon Sep 17 00:00:00 2001 From: sn0w Date: Sat, 7 Apr 2018 22:29:55 +0200 Subject: [PATCH] Init repo --- .dockerignore | 1 + .env.dist | 12 +++++++ .gitignore | 2 ++ .gitmodules | 6 ++++ docker-compose.yml | 39 ++++++++++++++++++++ entrypoint.ash | 46 ++++++++++++++++++++++++ pleroma | 1 + pleroma.dockerfile | 10 ++++++ pleroma.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 206 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.dist create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 docker-compose.yml create mode 100755 entrypoint.ash create mode 160000 pleroma create mode 100644 pleroma.dockerfile create mode 100755 pleroma.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1269488 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +data diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..be0c3cb --- /dev/null +++ b/.env.dist @@ -0,0 +1,12 @@ +# The docker network to bind to. +# (Useful for reverse-proxies outside of this compose). +DOCKER_NETWORK= + +# The directory where all containers store their data. +# Can be a relative path, "~/...", or absolute. +DOCKER_DATADIR= + +# Database settings +POSTGRES_DB= +POSTGRES_USER= +POSTGRES_PASSWORD= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c5156b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +data +.env diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..239bf03 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "pleroma"] + path = pleroma + url = git@git.pleroma.social:pleroma/pleroma.git +[submodule "camo"] + path = camo + url = https://github.com/atmos/camo.git diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0c7441b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +version: "3" + +networks: + default: + external: + name: ${DOCKER_NETWORK} + +services: + db: + image: postgres:10.3-alpine + restart: unless-stopped + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + volumes: + - ${DOCKER_DATADIR}/db:/var/lib/postgresql/data + + server: + build: + context: . + dockerfile: ./pleroma.dockerfile + restart: unless-stopped + links: + - db + environment: + POSTGRES_IP: db + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + PLEROMA_WORKSPACE: /pleroma + MIX_ARCHIVES: /mix/archives + MIX_HOME: /mix/home + volumes: + - ./pleroma:/pleroma + - ${DOCKER_DATADIR}/pleroma:/data + - ${DOCKER_DATADIR}/mix:/mix + - ${DOCKER_DATADIR}/misc/cache:/root/.cache + - ${DOCKER_DATADIR}/misc/meta:/meta diff --git a/entrypoint.ash b/entrypoint.ash new file mode 100755 index 0000000..569ab4d --- /dev/null +++ b/entrypoint.ash @@ -0,0 +1,46 @@ +#!/bin/ash + +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 +fi + +if [[ -z "$PLEROMA_WORKSPACE" ]]; then + echo "Please set the PLEROMA_WORKSPACE variable to your pleroma root." + exit 1 +fi +cd $PLEROMA_WORKSPACE + +case "$1" in +build) action__build;; +configure) action__configure;; +run) action__run;; +*) + echo "The action '$1' is invalid." + exit 1 +;; +esac +shift diff --git a/pleroma b/pleroma new file mode 160000 index 0000000..8f9bcc4 --- /dev/null +++ b/pleroma @@ -0,0 +1 @@ +Subproject commit 8f9bcc4ab0b16efa9168f49f6e2cc14bc424d398 diff --git a/pleroma.dockerfile b/pleroma.dockerfile new file mode 100644 index 0000000..dff1a19 --- /dev/null +++ b/pleroma.dockerfile @@ -0,0 +1,10 @@ +FROM elixir:1.6-alpine + +RUN apk add --no-cache --virtual .build alpine-sdk git + +ADD ./entrypoint.sh / +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +CMD ["run"] + +EXPOSE 4000 diff --git a/pleroma.sh b/pleroma.sh new file mode 100755 index 0000000..19bd263 --- /dev/null +++ b/pleroma.sh @@ -0,0 +1,89 @@ +#!/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 +" +} + +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" +} + +if [[ -z "$1" ]]; then + log_error "No action provided." + print_help + exit 1 +fi + +case "$1" in +build) action__build;; +configure) action__configure;; +run) action__run;; +stop) action__stop;; +*) + log_error "The action '$1' is invalid." + print_help + exit 1 +;; +esac +shift