Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Updates to dockerfile #21 (#23)
Browse files Browse the repository at this point in the history
* Format out explorer
* Upgrade base image to Ubuntu LTS

Co-authored-by: Stefan Bussemaker <[email protected]>
  • Loading branch information
kad-floriw and kad-busses authored Jul 19, 2021
1 parent 343e6f0 commit 611f3f5
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 145 deletions.
28 changes: 9 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
FROM ubuntu:16.04
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y \
curl \
dnsutils \
python \
python-dev \
python-pip \
sqlite3 \
libsqlite3-dev \
wget \
dnsutils \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Multichain
Expand All @@ -20,25 +15,20 @@ RUN wget https://www.multichain.com/download/multichain-2.1.1.tar.gz \
&& cd /tmp \
&& rm -Rf multichain*

# Multichain Explorer
# Configure container
WORKDIR /root

COPY explorer.tar.gz .
RUN tar -xvzf explorer.tar.gz \
&& rm -Rf explorer.tar.gz
COPY multichain.sh ./multichain.sh
RUN chmod +x multichain.sh

WORKDIR /root/multichain-explorer-master
COPY requirements.txt ./requirements.txt
RUN pip install -r requirements.txt \
&& python setup.py install --user
COPY streams.sh ./streams.sh
RUN chmod +x streams.sh

# Configure container
WORKDIR /root
COPY entrypoint.sh ./entrypoint.sh
RUN chmod +x entrypoint.sh

EXPOSE 8570
EXPOSE 8571
EXPOSE 2750

ENTRYPOINT ["/root/entrypoint.sh"]
ENTRYPOINT [ "/root/entrypoint.sh" ]
CMD [ "start" ]
20 changes: 0 additions & 20 deletions base/Dockerfile

This file was deleted.

118 changes: 12 additions & 106 deletions entrypoint.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,123 +1,29 @@
#!/bin/bash

init_chain() {
echo "Init a chain: $CHAINNAME."

multichain-util create $CHAINNAME \
-datadir=/data

# Set some required parameters in the params.dat
sed -i "s/^default-network-port.*/default-network-port = $NETWORK_PORT/" /data/$CHAINNAME/params.dat
sed -i "s/^default-rpc-port.*/default-rpc-port = $RPC_PORT/" /data/$CHAINNAME/params.dat
sed -i "s/^chain-name.*/chain-name = $CHAINNAME/" /data/$CHAINNAME/params.dat
sed -i "s/^chain-description.*/chain-description = MultiChain $CHAINNAME/" /data/$CHAINNAME/params.dat

# Loop over all variables that start with PARAM_: e.g. PARAM_BLOCKTIME='target-block-time|40';
( set -o posix ; set ) | sed -n '/^PARAM_/p' | while read PARAM; do
IFS='=' read -ra KV <<< "$PARAM"
IFS='|' read -ra KV <<< "${!KV[0]}"
sed -i "s/^${KV[0]}.*/${KV[0]} = ${KV[1]}/" /data/$CHAINNAME/params.dat
done
}
set -m

wait() {
echo "Waiting for $1 seconds"
sleep $1
}

start_main_node () {
echo "Start main node with chain: $CHAINNAME."

if [ ! -d /data/$CHAINNAME ]; then
init_chain
start () {
if [[ $DELAY_INIT == 1 ]]; then
wait 10
fi

cat /data/$CHAINNAME/params.dat

cat << EOF > /data/$CHAINNAME/multichain.conf
rpcuser=$RPC_USER
rpcpassword=$RPC_PASSWORD
rpcallowip=$RPC_ALLOW_IP
rpcport=$RPC_PORT
EOF
cp /data/$CHAINNAME/multichain.conf /data/multichain.conf
if [ -z "$MAIN_NODE_HOST" ]; then
./multichain.sh &
./streams.sh

multichaind $CHAINNAME \
-daemon \
-txindex \
-shrinkdebugfilesize \
-datadir=/data \
-initprivkey=$PRIVATE_KEY

wait 10

for stream in 'legalentity' 'sensordevice' 'observationgoal' ;
do
echo "Creating stream: $stream"
multichain-cli $CHAINNAME -datadir=/data create stream $stream true
done
}

start_node () {
if [[ $MAIN_NODE_HOST =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
IP=$MAIN_NODE_HOST
fg %1
else
IP=$(dig +short $MAIN_NODE_HOST)
./multichain.sh
fi

echo "Start node with existing chain: $CHAINNAME from $IP:$NETWORK_PORT"

multichaind $CHAINNAME@$IP:$NETWORK_PORT \
-daemon \
-txindex \
-shrinkdebugfilesize \
-rpcuser=$RPC_USER \
-rpcpassword=$RPC_PASSWORD \
-rpcallowip=$RPC_ALLOW_IP \
-rpcport=$RPC_PORT \
-datadir=/data \
-initprivkey=$PRIVATE_KEY

wait 10
}

start_explorer() {
echo "Run the explorer"

cat << EOF > /data/$CHAINNAME/multichain.conf
rpcuser=$RPC_USER
rpcpassword=$RPC_PASSWORD
rpcallowip=$RPC_ALLOW_IP
rpcport=$RPC_PORT
EOF

cat << EOF > /root/explorer.conf
port 2750
host 0.0.0.0
datadir += [{
"dirname": "/data/$CHAINNAME",
"loader": "default",
"chain": "MultiChain $CHAINNAME",
"policy": "MultiChain"
}]
dbtype = sqlite3
connect-args = dockerchain.explorer.sqlite
EOF

python -m Mce.abe --config /root/explorer.conf --commit-bytes 100000 --no-serve
wait 5
python -m Mce.abe --config /root/explorer.conf
}


if [[ $DELAY_INIT == 1 ]]; then
wait 10
fi

if [ -z "$MAIN_NODE_HOST" ]; then
start_main_node
if [ "$1" = "start" ]; then
start
else
start_node
exec "$@"
fi

start_explorer
Binary file removed explorer.tar.gz
Binary file not shown.
73 changes: 73 additions & 0 deletions multichain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

set -m

init_chain() {
echo "Init a chain: $CHAINNAME."

multichain-util create $CHAINNAME \
-datadir=/data

# Set some required parameters in the params.dat
sed -i "s/^default-network-port.*/default-network-port = $NETWORK_PORT/" /data/$CHAINNAME/params.dat
sed -i "s/^default-rpc-port.*/default-rpc-port = $RPC_PORT/" /data/$CHAINNAME/params.dat
sed -i "s/^chain-name.*/chain-name = $CHAINNAME/" /data/$CHAINNAME/params.dat
sed -i "s/^chain-description.*/chain-description = MultiChain $CHAINNAME/" /data/$CHAINNAME/params.dat

# Loop over all variables that start with PARAM_: e.g. PARAM_BLOCKTIME='target-block-time|40';
( set -o posix ; set ) | sed -n '/^PARAM_/p' | while read PARAM; do
IFS='=' read -ra KV <<< "$PARAM"
IFS='|' read -ra KV <<< "${!KV[0]}"
sed -i "s/^${KV[0]}.*/${KV[0]} = ${KV[1]}/" /data/$CHAINNAME/params.dat
done
}

start_main_node () {
echo "Start main node with chain: $CHAINNAME."

if [ ! -d /data/$CHAINNAME ]; then
init_chain
fi

cat /data/$CHAINNAME/params.dat

cat << EOF > /data/$CHAINNAME/multichain.conf
rpcuser=$RPC_USER
rpcpassword=$RPC_PASSWORD
rpcallowip=$RPC_ALLOW_IP
rpcport=$RPC_PORT
EOF
cp /data/$CHAINNAME/multichain.conf /data/multichain.conf

exec multichaind $CHAINNAME \
-txindex \
-shrinkdebugfilesize \
-datadir=/data \
-initprivkey=$PRIVATE_KEY
}

start_node () {
if [[ $MAIN_NODE_HOST =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
IP=$MAIN_NODE_HOST
else
IP=$(dig +short $MAIN_NODE_HOST)
fi

echo "Start node with existing chain: $CHAINNAME from $IP:$NETWORK_PORT"

exec multichaind $CHAINNAME@$IP:$NETWORK_PORT \
-txindex \
-shrinkdebugfilesize \
-rpcuser=$RPC_USER \
-rpcpassword=$RPC_PASSWORD \
-rpcallowip=$RPC_ALLOW_IP \
-rpcport=$RPC_PORT \
-datadir=/data \
-initprivkey=$PRIVATE_KEY
}

if [ -z "$MAIN_NODE_HOST" ]; then
start_main_node
else
start_node
fi
23 changes: 23 additions & 0 deletions streams.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -m

wait() {
echo "Waiting for $1 seconds"
sleep $1
}

create_streams () {
for stream in 'legalentity' 'sensordevice' 'observationgoal' ;
do
echo "Creating stream: $stream"
multichain-cli $CHAINNAME -datadir=/data create stream $stream true
done
}

# Wait a bit as the Multichain daemon is started in background. This prevents
# racing conditions where multichain-cli tries to create streams while the chain
# isn't created yet
wait 10

create_streams

0 comments on commit 611f3f5

Please sign in to comment.