From 05e87eb9451910371fdec5a0a4db98f43eb26a02 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 2 May 2022 16:49:34 +0000 Subject: [PATCH] overhaul the env.production files, add more nginx wrappers, split things into setup scripts --- .gitignore | 2 + env.production | 7 ++ hedgedoc/docker-compose.yaml | 25 +++---- hedgedoc/env.production | 2 + hedgedoc/setup | 40 ++++++++++ keycloak/docker-compose.yaml | 12 +-- keycloak/env.production | 1 + keycloak/setup | 73 +++++++++++++++++++ mastodon/README.md | 5 ++ mastodon/docker-compose.yaml | 16 ++-- mastodon/env.production | 1 - mastodon/setup | 14 ++++ nextcloud/README.md | 35 +++++++++ nextcloud/docker-compose.yaml | 8 +- nextcloud/env.production | 1 + nginx/data/nginx/templates/docs.conf.template | 59 +++++++++++++++ .../data/nginx/templates/login.conf.template | 4 +- nginx/setup | 11 +-- 18 files changed, 279 insertions(+), 37 deletions(-) create mode 100644 .gitignore create mode 100644 env.production create mode 100644 hedgedoc/env.production create mode 100755 hedgedoc/setup create mode 100644 keycloak/env.production create mode 100755 keycloak/setup create mode 100755 mastodon/setup create mode 100644 nextcloud/README.md create mode 100644 nextcloud/env.production create mode 100644 nginx/data/nginx/templates/docs.conf.template diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cc1547 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.*.swp +data diff --git a/env.production b/env.production new file mode 100644 index 0000000..8515192 --- /dev/null +++ b/env.production @@ -0,0 +1,7 @@ +DOMAIN_NAME=example.com +REALM=spacestation + +KEYCLOAK_HOSTNAME=login.${DOMAIN_NAME} +HEDGEDOC_HOSTNAME=docs.${DOMAIN_NAME} +MASTODON_HOSTNAME=social.${DOMAIN_NAME} +NEXTCLOUD_HOSTNAME=cloud.${DOMAIN_NAME} diff --git a/hedgedoc/docker-compose.yaml b/hedgedoc/docker-compose.yaml index c100d29..88c33d0 100644 --- a/hedgedoc/docker-compose.yaml +++ b/hedgedoc/docker-compose.yaml @@ -7,35 +7,30 @@ services: - POSTGRES_PASSWORD=password - POSTGRES_DB=hedgedoc volumes: - - database:/var/lib/postgresql/data + - ./data/database:/var/lib/postgresql/data restart: always app: # Make sure to use the latest release from https://hedgedoc.org/latest-release image: quay.io/hedgedoc/hedgedoc:1.9.3 + env_file: + - ../env.production + - env.production environment: - CMD_DB_URL=postgres://hedgedoc:password@database:5432/hedgedoc - - CMD_DOMAIN=spacestation - - CMD_URL_ADDPORT=true - - CMD_OAUTH2_USER_PROFILE_URL=http://spacestation:8080/realms/spacestation/protocol/openid-connect/userinfo + - CMD_DOMAIN=docs.example.com + #- CMD_URL_ADDPORT=true + - CMD_OAUTH2_USER_PROFILE_URL=https://login.example.com/realms/spacestation/protocol/openid-connect/userinfo - CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR=preferred_username - CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR=name - CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR=email - - CMD_OAUTH2_TOKEN_URL=http://spacestation:8080/realms/spacestation/protocol/openid-connect/token - - CMD_OAUTH2_AUTHORIZATION_URL=http://spacestation:8080/realms/spacestation/protocol/openid-connect/auth + - CMD_OAUTH2_TOKEN_URL=https://login.example.com/realms/spacestation/protocol/openid-connect/token + - CMD_OAUTH2_AUTHORIZATION_URL=https://login.example.com/realms/spacestation/protocol/openid-connect/auth - CMD_OAUTH2_CLIENT_ID=hedgedoc - - CMD_OAUTH2_CLIENT_SECRET=abcdef1234 - CMD_OAUTH2_PROVIDERNAME=Keycloak - - CMD_SESSION_SECRET=abcdef1234 - # - CMD_DOMAIN= - # - CMD_PROTOCOL_USESSL=true - # - CMD_URL_ADDPORT=false volumes: - - uploads:/hedgedoc/public/uploads + - ./data/uploads:/hedgedoc/public/uploads ports: - "3000:3000" restart: always depends_on: - database -volumes: - database: - uploads: diff --git a/hedgedoc/env.production b/hedgedoc/env.production new file mode 100644 index 0000000..118615d --- /dev/null +++ b/hedgedoc/env.production @@ -0,0 +1,2 @@ +CMD_OAUTH2_CLIENT_SECRET=abcdef1234 +CMD_SESSION_SECRET=abcdef1234 diff --git a/hedgedoc/setup b/hedgedoc/setup new file mode 100755 index 0000000..fd4f9fa --- /dev/null +++ b/hedgedoc/setup @@ -0,0 +1,40 @@ +#!/bin/bash +die() { echo >&2 "$@" ; exit 1 ; } + +DIRNAME="$(dirname $0)" +cd "$DIRNAME" +[ -r env.production ] && source env.production +[ -r ../env.production ] && source ../env.production + +cd ../keycloak + +sudo docker-compose exec -T keycloak \ + /opt/keycloak/bin/kcadm.sh \ + create clients \ + -r "$REALM" \ + -f - <&2 "ERROR: $@" ; exit 1 ; } +info() { echo >&2 "$@" ; } + +DIRNAME="$(dirname $0)" +cd "$DIRNAME" +source ../env.production +source ./env.production + +info "logging into server" +sudo docker-compose exec keycloak \ + /opt/keycloak/bin/kcadm.sh \ + config credentials \ + --server http://localhost:8080/ \ + --user admin \ + --password "$KEYCLOAK_ADMIN_PASSWORD" \ + --realm master \ +|| die "unable to login" + + +info "Create a new realm for '$REALM'" +sudo docker-compose exec keycloak \ + /opt/keycloak/bin/kcadm.sh \ + create realms \ + -s "realm=$REALM" \ + -s enabled=true \ +|| die "unable to create realm" + + +# https://github.com/hedgedoc/hedgedoc/issues/56 +info "Fix up a id bug" +sudo docker-compose exec -T keycloak \ + /opt/keycloak/bin/kcadm.sh \ + create client-scopes \ + -r "$REALM" \ + -f - <&2 "ERROR: $@" ; exit 1 ; } +info() { echo >&2 "$@" ; } + +DIRNAME="$(dirname $0)" +cd "$DIRNAME" +source ../env.production +source ./env.production + +info "configuring mastodon" +sudo docker-compose run web \ + rails db:setup \ +|| die "unable to login" + diff --git a/nextcloud/README.md b/nextcloud/README.md new file mode 100644 index 0000000..83f2a55 --- /dev/null +++ b/nextcloud/README.md @@ -0,0 +1,35 @@ +Enable SSO: + +``` +( cd ../keycloak ; sudo docker-compose exec -T keycloak \ + /opt/keycloak/bin/kcadm.sh \ + create clients \ + --realm master --user admin --password admin \ + -r spacestation \ + -f - ) <&2 "$@" ; exit 1 ; } + ENV=env.production if [ ! -r "$ENV" ]; then - echo >&2 "$ENV: not found?" - exit 1 + die "$ENV: not found?" fi source env.production if [ -z "${DOMAIN_NAME}" ]; then - echo >&2 "DOMAIN_NAME not set" - exit 1 + die "DOMAIN_NAME not set" fi certdir="data/certbot/conf/live/${DOMAIN_NAME}" -mkdir -p "$certdir" +mkdir -p "$certdir" || die "$certdir: unable to make" openssl req \ -x509 \ @@ -24,3 +24,4 @@ openssl req \ -nodes \ -days 365 \ -subj "/CN=${DOMAIN_NAME}'" \ +|| die "$certdir/privkey.pem: unable to create temp key"