diff --git a/.ceramicTemplate.config.json b/.ceramicTemplate.config.json new file mode 100644 index 000000000..029129191 --- /dev/null +++ b/.ceramicTemplate.config.json @@ -0,0 +1,35 @@ +{ + "anchor": { }, + "http-api": { + "cors-allowed-origins": [ + ".*" + ], + "admin-dids": [ + "did:key:z6MktbKJrMnhVJ37QFTo12911ycm2juKDUzWHDVETu9s5a9T" + ] + }, + "ipfs": { + "mode": "remote", + "host": "@DOCKER_HOST@" + }, + "logger": { + "log-level": 2 + }, + "metrics": { + "metrics-exporter-enabled": false, + "metrics-port": 9090 + }, + "network": { + "name": "inmemory" + }, + "node": {}, + "state-store": { + "mode": "fs", + "local-directory": "/root/.ceramic/statestore" + }, + "indexing": { + "db": "@POSTGRES_URI@", + "allow-queries-before-historical-sync": true, + "models": [] + } +} diff --git a/ceramic.Dockerfile b/ceramic.Dockerfile new file mode 100644 index 000000000..0d3fc5f41 --- /dev/null +++ b/ceramic.Dockerfile @@ -0,0 +1,9 @@ +FROM ceramicnetwork/js-ceramic:3.2.0 + +COPY interpolateConfigVars.sh . +COPY .ceramicTemplate.config.json . + +ENTRYPOINT [ \ + "bash", "-c", \ + "./interpolateConfigVars.sh .ceramicTemplate.config.json | jq > daemon.config.json && ./packages/cli/bin/ceramic.js daemon --config daemon.config.json" \ +] diff --git a/interpolateConfigVars.sh b/interpolateConfigVars.sh new file mode 100755 index 000000000..de3b1a2f3 --- /dev/null +++ b/interpolateConfigVars.sh @@ -0,0 +1,38 @@ +#! /usr/bin/env bash + +set -euo pipefail + +# Send output to stderr +echoerr() { + echo "$@" 1>&2; +} + +TEMPLATE_FILE=$1 +if [[ -z "$TEMPLATE_FILE" ]]; then + echoerr "Template file not passed as first argument, exiting." + exit 1 +fi + +# Get all variables needing substitution +TEMPLATE_VARS=$(grep --only-matching "@.*@" "$TEMPLATE_FILE" | tr --delete "@") + +# Check that each template var exists in env +while read -r templateVar; do + if ! printenv "$templateVar" &>/dev/null; then + echoerr "$templateVar is not set in environment, exiting." + exit 1 + fi +done <<<"$TEMPLATE_VARS" + + +# For each line in the template file +while read -r line; do + # If we got a variable in the line... + if var=$(grep --only-matching "@.*@" <<<"$line" | tr --delete "@"); then + # ...replace it with the env variable + sed "s/@$var@/$(printenv "$var")/" <<<"$line" + else + # ...else just re-print the line + echo "$line" + fi +done < "$TEMPLATE_FILE"