Skip to content

Commit

Permalink
Merge pull request #197 from desci-labs/m0ar/ceramic-config-interpola…
Browse files Browse the repository at this point in the history
…tion

Ceramic Dockerfile with config interpolation
  • Loading branch information
hubsmoke authored Jan 26, 2024
2 parents 031ef78 + a9e6f25 commit 9d3523f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .ceramicTemplate.config.json
Original file line number Diff line number Diff line change
@@ -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": []
}
}
9 changes: 9 additions & 0 deletions ceramic.Dockerfile
Original file line number Diff line number Diff line change
@@ -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" \
]
38 changes: 38 additions & 0 deletions interpolateConfigVars.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 9d3523f

Please sign in to comment.