Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Dockerfile with config.json templating
Browse files Browse the repository at this point in the history
  • Loading branch information
francoilol committed May 24, 2018
1 parent fbaf598 commit 4176dae
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM node:6 AS builder

RUN groupadd --gid 1100 lisk && \
useradd --create-home --home-dir /home/lisk --shell /bin/bash --uid 1100 --gid 1100 lisk
COPY . /home/lisk/lisk/
RUN chown lisk:lisk --recursive /home/lisk/lisk

USER lisk
WORKDIR /home/lisk/lisk

RUN npm install
RUN ./node_modules/.bin/grunt release


FROM node:6

ENV CONFD_VERSION 0.16.0
ENV CONFD_SHA256 255d2559f3824dd64df059bdc533fd6b697c070db603c76aaf8d1d5e6b0cc334

RUN groupadd --gid 1100 lisk && \
useradd --create-home --home-dir /home/lisk --shell /bin/bash --uid 1100 --gid 1100 lisk
COPY --from=builder /home/lisk/lisk/ /home/lisk/lisk/
COPY docker_files/ /
# git repository needed for build; cannot added to .dockerignore
RUN rm -rf /home/lisk/lisk/.git && \
mkdir /home/lisk/lisk/logs && \
chown lisk:lisk --recursive /home/lisk/lisk

RUN curl --location --output /tmp/confd \
https://github.com/kelseyhightower/confd/releases/download/v${CONFD_VERSION}/confd-${CONFD_VERSION}-linux-amd64 && \
if [ x"$( sha256sum /tmp/confd |awk '{ print $1 }' )" = x"${CONFD_SHA256}" ]; then \
mv /tmp/confd /usr/local/bin/; \
chmod +x /usr/local/bin/confd; \
else \
rm -f /tmp/confd; \
exit 1; \
fi

ARG LISK_VERSION
ARG LISK_MIN_VERSION=${LISK_VERSION}
ENV LISK_VERSION ${LISK_VERSION}
ENV LISK_MIN_VERSION ${LISK_MIN_VERSION}

USER lisk
WORKDIR /home/lisk/lisk
CMD ["/home/lisk/run.sh"]
6 changes: 6 additions & 0 deletions docker_files/etc/confd/conf.d/lisk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[template]
src = "config.json.tmpl"
dest = "config.json"
keys = [
"/lisk",
]
109 changes: 109 additions & 0 deletions docker_files/etc/confd/templates/config.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"wsPort": {{getv "/lisk/wsport" "8001"}},
"httpPort": {{getv "/lisk/httpport" "8000"}},
"address": "{{getv "/lisk/address" "0.0.0.0"}}",
"version": "{{getenv "LISK_VERSION"}}",
"minVersion": "{{getenv "LISK_MIN_VERSION"}}",
"fileLogLevel": "{{getv "/lisk/fileloglevel" "info"}}",
"logFileName": "{{getv "/lisk/logfilename" "logs/lisk.log"}}",
"consoleLogLevel": "{{getv "/lisk/consoleloglevel" "error"}}",
"trustProxy": {{getv "/lisk/trustproxy" "false"}},
"topAccounts": {{getv "/lisk/topaccounts" "false"}},
"cacheEnabled": {{getv "/lisk/cacheenabled" "false"}},
"wsWorkers": {{getv "/lisk/wsworkers" "1"}},
"db": {
"host": "{{getv "/lisk/db/host" "localhost"}}",
"port": {{getv "/lisk/db/port" "5432"}},
"database": "{{getv "/lisk/db/database" "lisk_main"}}",
"user": "{{getv "/lisk/db/user" "lisk"}}",
"password": "{{getv "/lisk/db/password" "password"}}",
"min": {{getv "/lisk/db/min" "10"}},
"max": {{getv "/lisk/db/max" "95"}},
"poolIdleTimeout": {{getv "/lisk/db/poolidletimeout" "30000"}},
"reapIntervalMillis": {{getv "/lisk/db/reapintervalmillis" "1000"}},
"logEvents": ["error"],
"logFileName": "{{getv "/lisk/db/logfilename" "logs/lisk_db.log"}}"
},
"redis": {
"host": "{{getv "/lisk/redis/host" "127.0.0.1"}}",
"port": {{getv "/lisk/redis/port" "6380"}},
"db": {{getv "/lisk/redis/db" "0"}},
"password": {{getv "/lisk/redis/password" "null"}}
},
"api": {
"enabled": {{getv "/lisk/api/enabled" "true"}},
"access": {
"public": {{getv "/lisk/api/access/public" "false"}},
{{$whiteListEntries := getvs "/lisk/api/access/whitelist/*"}}"whiteList": [{{range $index, $element := $whiteListEntries}}{{if $index}},{{end}}"{{$element}}"{{end}}]
},
"options": {
"limits": {
"max": {{getv "/lisk/api/options/limits/max" "0"}},
"delayMs": {{getv "/lisk/api/options/limits/delayms" "0"}},
"delayAfter": {{getv "/lisk/api/options/limits/delayafter" "0"}},
"windowMs": {{getv "/lisk/api/options/limits/windowms" "60000"}}
},
"cors": {
"origin": "{{getv "/lil/api/options/cors/origin" "*"}}",
"methods": ["GET", "POST", "PUT"]
}
}
},
"peers": {
"enabled": {{getv "/lisk/peers/enabled" "true"}},
"list": [{{range $index, $element := (getvs "/lisk/peers/list/*")}}{{$data := split $element ":"}}{{if $index}},{{end}}
{
"ip": "{{index $data 0}}",
"wsPort": {{index $data 1}}
}{{end}}
],
"access": {
{{$blackListEntries := getvs "/lisk/peers/access/blacklist/*"}}"blackList": [{{range $index, $element := $blackListEntries}}{{if $index}},{{end}}"{{$element}}"{{end}}]
},
"options": {
"timeout": {{getv "/lisk/peers/options/timeout" "5000"}},
"broadhashConsensusCalculationInterval": {{getv "/lisk/peers/options/broadhashconsensuscalculationinterval" "5000"}}
}
},
"broadcasts": {
"active": {{getv "/lisk/broadcasts/active" "true"}},
"broadcastInterval": {{getv "/lisk/broadcasts/broadcastinterval" "5000"}},
"broadcastLimit": {{getv "/lisk/broadcasts/broadcastlimit" "20"}},
"parallelLimit": {{getv "/lisk/broadcasts/parallellimit" "20"}},
"releaseLimit": {{getv "/lisk/broadcasts/releaselimit" "25"}},
"relayLimit": {{getv "/lisk/broadcasts/relaylimit" "2"}}
},
"transactions": {
"maxTransactionsPerQueue": {{getv "/lisk/transactions/maxtransactionsperqueue" "1000"}}
},
"forging": {
"force": {{getv "/lisk/forging/force" "false"}},
{{$delegates := getvs "/lisk/forging/delegates/*"}}"delegates": [{{range $index, $element := $delegates}}{{if $index}},{{end}}"{{$element}}"{{end}}],
"defaultKey": "{{getv "/lisk/forging/defaultkey" ""}}",
"secret": [{{range $index, $element := (getvs "/lisk/forging/secret/*")}}{{$data := split $element ":"}}{{if $index}},{{end}}
{
"encryptedSecret": "{{index $data 0}}",
"publicKey": "{{index $data 1}}"
}{{end}}
],
"access": {
{{$whiteListEntries := getvs "/lisk/forging/access/whitelist/*"}}"whiteList": [{{range $index, $element := $whiteListEntries}}{{if $index}},{{end}}"{{$element}}"{{end}}]
}
},
"syncing": {
"active": {{getv "/lisk/syncing/active" "true"}}
},
"loading": {
"loadPerIteration": {{getv "/lisk/loading/loadperiteration" "5000"}}
},
"ssl": {
"enabled": {{getv "/lisk/ssl/enabled" "false"}},
"options": {
"port": {{getv "/lisk/ssl/options/port" "443"}},
"address": "{{getv "/lisk/ssl/options/address" "0.0.0.0"}}",
"key": "{{getv "/lisk/ssl/options/key" "./ssl/lisk.key"}}",
"cert": "{{getv "/lisk/ssl/options/cert" "./ssl/lisk.crt"}}"
}
},
"nethash": "{{getv "/lisk/nethash" "ed14889723f24ecc54871d058d98ce91ff2f973192075c0155ba2b7b70ad2511"}}"
}
4 changes: 4 additions & 0 deletions docker_files/home/lisk/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

confd -backend env -onetime
node app.js
177 changes: 177 additions & 0 deletions docker_files/home/lisk/wait-for-it.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available

cmdname=$(basename $0)

echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}

wait_for()
{
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
start_ts=$(date +%s)
while :
do
if [[ $ISBUSY -eq 1 ]]; then
nc -z $HOST $PORT
result=$?
else
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
fi
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}

wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $RESULT
}

# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-h)
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
HOST="${1#*=}"
shift 1
;;
-p)
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
PORT="${1#*=}"
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI=("$@")
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done

if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi

TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}

# check to see if timeout is from busybox?
# check to see if timeout is from busybox?
TIMEOUT_PATH=$(realpath $(which timeout))
if [[ $TIMEOUT_PATH =~ "busybox" ]]; then
ISBUSY=1
BUSYTIMEFLAG="-t"
else
ISBUSY=0
BUSYTIMEFLAG=""
fi

if [[ $CHILD -gt 0 ]]; then
wait_for
RESULT=$?
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
wait_for
RESULT=$?
fi
fi

if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec "${CLI[@]}"
else
exit $RESULT
fi

0 comments on commit 4176dae

Please sign in to comment.