diff --git a/README.md b/README.md index da4388a..7cbf427 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,20 @@ To automatically rebuild all instances, use: sudo bash /distillery/rebuild-all.sh ``` +## Reserving an instance -- 'reserve.sh' + +Sometimes it is useful to reserve a particular instance name. +This is done by hosting a placeholder website at the domain. +To do so, use: + + +```bash +sudo bash /distillery/reserve.sh SLUG +``` + +To un-reserve a website, manually stop the docker stack and remove the folder. + + ## Purge an existing WissKI instance -- 'purge.sh' diff --git a/distillery/reserve.sh b/distillery/reserve.sh new file mode 100755 index 0000000..9afe634 --- /dev/null +++ b/distillery/reserve.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -e + +# read the lib/shared.sh and read the slug argument. +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "$DIR" +source "$DIR/lib/lib.sh" +require_slug_argument + +# wait for sql to be awake +wait_for_sql + +# check if the site exists +if sql_bookkeep_exists "$SLUG"; then + log_error "=> Site '$SLUG' already exists in bookeeping table. " + echo "Refusing to work" + exit 1; +fi + +log_info " => Creating local directory structure at '$INSTANCE_BASE_DIR'" +mkdir -p "$INSTANCE_BASE_DIR" +install_resource_dir "compose/reserve" "$INSTANCE_BASE_DIR" + +log_info " => Writing configuration file" +load_template "docker-env/reserve" \ + "VIRTUAL_HOST" "${INSTANCE_DOMAIN}" \ + "SLUG" "${SLUG}" \ + "LETSENCRYPT_HOST" "${LETSENCRYPT_HOST}" \ + "LETSENCRYPT_EMAIL" "${LETSENCRYPT_EMAIL}" \ + > "$INSTANCE_BASE_DIR/.env" + + +log_info " => Running and building image" +cd "$INSTANCE_BASE_DIR" +docker-compose build --pull +docker-compose pull + +log_info " => Starting container" +docker-compose up -d + +log_info " => $INSTANCE_DOMAIN has been reserved" \ No newline at end of file diff --git a/distillery/resources/compose/reserve/.env.sample b/distillery/resources/compose/reserve/.env.sample new file mode 100644 index 0000000..ed68b15 --- /dev/null +++ b/distillery/resources/compose/reserve/.env.sample @@ -0,0 +1,14 @@ +####################### +# Meta Settings +####################### + +####################### +### Web Server settings +####################### +# the hostname for the website +VIRTUAL_HOST=example.com + +# optional letsencrypt support +# when blank, ignore +LETSENCRYPT_HOST= +LETSENCRYPT_EMAIL= diff --git a/distillery/resources/compose/reserve/docker-compose.yml b/distillery/resources/compose/reserve/docker-compose.yml new file mode 100644 index 0000000..94ad72d --- /dev/null +++ b/distillery/resources/compose/reserve/docker-compose.yml @@ -0,0 +1,26 @@ +version: "3.7" + +services: + static: + image: tkw01536/gostatic + restart: always + environment: + # port and hostname for this image to use + VIRTUAL_HOST: ${VIRTUAL_HOST} + VIRTUAL_PORT: 8043 + + # optional letsencrypt email + LETSENCRYPT_HOST: ${LETSENCRYPT_HOST} + LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL} + + ports: + - 8043 + + # volumes that are mounted + volumes: + - ./index.html:/srv/http/index.html:ro + +networks: + default: + external: + name: distillery diff --git a/distillery/resources/compose/reserve/index.html b/distillery/resources/compose/reserve/index.html new file mode 100644 index 0000000..67b1625 --- /dev/null +++ b/distillery/resources/compose/reserve/index.html @@ -0,0 +1,4 @@ + + +This domain name is reserved. +Content is a work in progress. \ No newline at end of file diff --git a/distillery/resources/templates/docker-env/reserve b/distillery/resources/templates/docker-env/reserve new file mode 100644 index 0000000..cd4d7da --- /dev/null +++ b/distillery/resources/templates/docker-env/reserve @@ -0,0 +1,4 @@ +VIRTUAL_HOST=${VIRTUAL_HOST} + +LETSENCRYPT_HOST=${LETSENCRYPT_HOST} +LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL} \ No newline at end of file