From 5f59cfd9ae6e3f6f15f1ec4bb6ecfb1b86be0da6 Mon Sep 17 00:00:00 2001 From: sn0w Date: Sun, 8 Apr 2018 16:35:41 +0200 Subject: [PATCH] Use m4 to make the docker-compose file less ugly --- docker-compose.m4 | 71 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 64 ----------------------------------------- pleroma.sh | 16 +++++++++++ 3 files changed, 87 insertions(+), 64 deletions(-) create mode 100644 docker-compose.m4 delete mode 100644 docker-compose.yml diff --git a/docker-compose.m4 b/docker-compose.m4 new file mode 100644 index 0000000..c0f875b --- /dev/null +++ b/docker-compose.m4 @@ -0,0 +1,71 @@ +divert(-1) +define(`upcase', `translit($1, `a-z', `A-Z')') +define(`env', `upcase($1):${upcase($1):?upcase($1)}') +define(`env_fb', `upcase($1):-$2') +define(`env_inline', `${upcase($1):?upcase($1)}') +divert(1)dnl + +version: "3" + +networks: + default: + external: + name: env_inline(`docker_network') + +services: + db: + image: postgres:10.3-alpine + restart: unless-stopped + environment: + env(`postgres_db') + env(`postgres_user') + env(`postgres_password') + volumes: + - env_inline(`docker_datadir')/db:/var/lib/postgresql/data + + server: + build: + context: . + dockerfile: ./pleroma.dockerfile + restart: unless-stopped + links: + - db + environment: + env(`postgres_ip', `db') + env(`postgres_db') + env(`postgres_user') + env(`postgres_password') + + env(`pleroma_url') + env(`pleroma_scheme') + env(`pleroma_port') + env(`pleroma_secret_key_base') + env(`pleroma_name') + env(`pleroma_admin_email') + env(`pleroma_user_limit') + env(`pleroma_registrations_open') + env(`pleroma_media_proxy_enabled') + env(`pleroma_media_proxy_redirect_on_failure') + env(`pleroma_media_proxy_url') + + 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 + labels: + traefik.enable: "true" + traefik.fe.port: "4000" + traefik.fe.protocol: "http" + traefik.fe.entryPoints: "http,https" + traefik.fe.frontend.rule: "Host:env_inline(`pleroma_url')" + traefik.cache.port: "80" + traefik.cache.protocol: "http" + traefik.cache.entryPoints: "http,https" + traefik.cache.frontend.rule: "Host:env_inline(`pleroma_media_proxy_url')" + diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 027bf01..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,64 +0,0 @@ -version: "3" - -networks: - default: - external: - name: ${DOCKER_NETWORK:?DOCKER_NETWORK} - -services: - db: - image: postgres:10.3-alpine - restart: unless-stopped - environment: - POSTGRES_DB: ${POSTGRES_DB:?POSTGRES_DB} - POSTGRES_USER: ${POSTGRES_USER:?POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD} - volumes: - - ${DOCKER_DATADIR:?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_DB} - POSTGRES_USER: ${POSTGRES_USER:?POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD} - - PLEROMA_URL: ${PLEROMA_URL:?PLEROMA_URL} - PLEROMA_SCHEME: ${PLEROMA_SCHEME:?PLEROMA_SCHEME} - PLEROMA_PORT: ${PLEROMA_PORT:?PLEROMA_PORT} - PLEROMA_SECRET_KEY_BASE: ${PLEROMA_SECRET_KEY_BASE:?PLEROMA_SECRET_KEY_BASE} - PLEROMA_NAME: ${PLEROMA_NAME:?PLEROMA_NAME} - PLEROMA_ADMIN_EMAIL: ${PLEROMA_ADMIN_EMAIL:?PLEROMA_ADMIN_EMAIL} - PLEROMA_USER_LIMIT: ${PLEROMA_USER_LIMIT:?PLEROMA_USER_LIMIT} - PLEROMA_REGISTRATIONS_OPEN: ${PLEROMA_REGISTRATIONS_OPEN:?PLEROMA_REGISTRATIONS_OPEN} - PLEROMA_MEDIA_PROXY_ENABLED: ${PLEROMA_MEDIA_PROXY_ENABLED:?PLEROMA_MEDIA_PROXY_ENABLED} - PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE: ${PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE:?PLEROMA_MEDIA_PROXY_REDIRECT_ON_FAILURE} - PLEROMA_MEDIA_PROXY_URL: ${PLEROMA_MEDIA_PROXY_URL:?PLEROMA_MEDIA_PROXY_URL} - - PLEROMA_WORKSPACE: /pleroma - MIX_ARCHIVES: /mix/archives - MIX_HOME: /mix/home - MIX_ENV: prod - volumes: - - ./pleroma:/pleroma - - ${DOCKER_DATADIR:?DOCKER_DATADIR}/pleroma:/data - - ${DOCKER_DATADIR:?DOCKER_DATADIR}/mix:/mix - - ${DOCKER_DATADIR:?DOCKER_DATADIR}/misc/cache:/root/.cache - - ${DOCKER_DATADIR:?DOCKER_DATADIR}/misc/meta:/meta - labels: - traefik.enable: "true" - traefik.fe.port: "4000" - traefik.fe.protocol: "http" - traefik.fe.entryPoints: "http,https" - traefik.fe.frontend.rule: "Host:${PLEROMA_URL:?PLEROMA_URL}" - traefik.cache.port: "80" - traefik.cache.protocol: "http" - traefik.cache.entryPoints: "http,https" - traefik.cache.frontend.rule: "Host:${PLEROMA_MEDIA_PROXY_URL:?PLEROMA_MEDIA_PROXY_URL}" - diff --git a/pleroma.sh b/pleroma.sh index 19bd263..d6926ad 100755 --- a/pleroma.sh +++ b/pleroma.sh @@ -47,26 +47,42 @@ function run_dockerized { docker-compose down } +function action__pre { + m4 docker-compose.m4 > docker-compose.yml +} + +function action__post { + rm docker-compose.yml +} + function action__build { + action__pre run_dockerized "build" log_ok "Done" + action__post } function action__configure { + action__pre run_dockerized "configure" log_ok "Done" + action__post } function action__run { + action__pre log_info "Booting pleroma..." docker-compose up --remove-orphans -d log_ok "Done" + action__post } function action__stop { + action__pre log_info "Stopping pleroma..." docker-compose down log_ok "Done" + action__post } if [[ -z "$1" ]]; then