Skip to content

Commit 839aae7

Browse files
committed
Init docker
1 parent 5502853 commit 839aae7

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM openjdk:17-jdk-alpine
2+
3+
ENV HTTP_PORT=8080
4+
ENV HTTPS_PORT=8443
5+
ENV LAS2PEER_PORT=9011
6+
7+
RUN apk add --update bash tzdata curl && rm -f /var/cache/apk/*
8+
RUN addgroup -g 1000 -S las2peer && \
9+
adduser -u 1000 -S las2peer -G las2peer
10+
11+
COPY --chown=las2peer:las2peer . /src
12+
WORKDIR /src
13+
14+
# run the rest as unprivileged user
15+
USER las2peer
16+
# Include this in case you build on a windows machine
17+
#RUN dos2unix gradlew
18+
#RUN dos2unix gradle.properties
19+
#RUN dos2unix /src/docker-entrypoint.sh
20+
#RUN dos2unix /src/etc/i5.las2peer.connectors.webConnector.WebConnector.properties
21+
#RUN dos2unix /src/etc/i5.las2peer.services.servicePackage.TemplateService.properties
22+
RUN chmod -R a+rwx /src
23+
RUN chmod +x /src/docker-entrypoint.sh
24+
RUN chmod +x gradlew && ./gradlew build
25+
26+
27+
EXPOSE $HTTP_PORT
28+
EXPOSE $HTTPS_PORT
29+
EXPOSE $LAS2PEER_PORT
30+
RUN chmod +x /src/docker-entrypoint.sh
31+
ENTRYPOINT ["/src/docker-entrypoint.sh"]

docker-entrypoint.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# print all comands to console if DEBUG is set
6+
if [[ ! -z "${DEBUG}" ]]; then
7+
set -x
8+
fi
9+
NODE_ID_SEED=${NODE_ID_SEED:-$RANDOM}
10+
11+
# set some helpful variables
12+
export SERVICE_PROPERTY_FILE='etc/i5.las2peer.services.apiTestingBot.APITestingBot.properties'
13+
export WEB_CONNECTOR_PROPERTY_FILE='etc/i5.las2peer.connectors.webConnector.WebConnector.properties'
14+
export SERVICE_VERSION=$(awk -F "=" '/service.version/ {print $2}' gradle.properties)
15+
export SERVICE_NAME=$(awk -F "=" '/service.name/ {print $2}' gradle.properties)
16+
export SERVICE_CLASS=$(awk -F "=" '/service.class/ {print $2}' gradle.properties)
17+
export SERVICE=${SERVICE_NAME}.${SERVICE_CLASS}@${SERVICE_VERSION}
18+
19+
function set_in_service_config {
20+
sed -i "s?${1}[[:blank:]]*=.*?${1}=${2}?g" ${SERVICE_PROPERTY_FILE}
21+
}
22+
23+
function set_in_web_config {
24+
sed -i "s?${1}[[:blank:]]*=.*?${1}=${2}?g" ${WEB_CONNECTOR_PROPERTY_FILE}
25+
}
26+
set_in_web_config httpPort ${HTTP_PORT}
27+
set_in_web_config httpsPort ${HTTPS_PORT}
28+
29+
# check mandatory variables
30+
[[ -z "${BOT_MANAGER_URL}" ]] && \
31+
echo "Mandatory variable BOT_MANAGER_URL is not set. Add -e BOT_MANAGER_URL=... to your arguments." && exit 1
32+
33+
set_in_service_config botManagerURL ${BOT_MANAGER_URL}
34+
35+
36+
# set defaults for optional service parameters
37+
[[ -z "${SERVICE_PASSPHRASE}" ]] && export SERVICE_PASSPHRASE='template'
38+
39+
# wait for any bootstrap host to be available
40+
if [[ ! -z "${BOOTSTRAP}" ]]; then
41+
echo "Waiting for any bootstrap host to become available..."
42+
for host_port in ${BOOTSTRAP//,/ }; do
43+
arr_host_port=(${host_port//:/ })
44+
host=${arr_host_port[0]}
45+
port=${arr_host_port[1]}
46+
if { </dev/tcp/${host}/${port}; } 2>/dev/null; then
47+
echo "${host_port} is available. Continuing..."
48+
break
49+
fi
50+
done
51+
fi
52+
# prevent glob expansion in lib/*
53+
set -f
54+
LAUNCH_COMMAND='java -cp lib/* --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED i5.las2peer.tools.L2pNodeLauncher -s service -p '"${LAS2PEER_PORT} ${SERVICE_EXTRA_ARGS}"
55+
if [[ ! -z "${BOOTSTRAP}" ]]; then
56+
LAUNCH_COMMAND="${LAUNCH_COMMAND} -b ${BOOTSTRAP}"
57+
fi
58+
59+
# it's realistic for different nodes to use different accounts (i.e., to have
60+
# different node operators). this function echos the N-th mnemonic if the
61+
# variable WALLET is set to N. If not, first mnemonic is used
62+
function selectMnemonic {
63+
declare -a mnemonics=("differ employ cook sport clinic wedding melody column pave stuff oak price" "memory wrist half aunt shrug elbow upper anxiety maximum valve finish stay" "alert sword real code safe divorce firm detect donate cupboard forward other" "pair stem change april else stage resource accident will divert voyage lawn" "lamp elbow happy never cake very weird mix episode either chimney episode" "cool pioneer toe kiwi decline receive stamp write boy border check retire" "obvious lady prize shrimp taste position abstract promote market wink silver proof" "tired office manage bird scheme gorilla siren food abandon mansion field caution" "resemble cattle regret priority hen six century hungry rice grape patch family" "access crazy can job volume utility dial position shaft stadium soccer seven")
64+
if [[ ${WALLET} =~ ^[0-9]+$ && ${WALLET} -lt ${#mnemonics[@]} ]]; then
65+
# get N-th mnemonic
66+
echo "${mnemonics[${WALLET}]}"
67+
else
68+
# note: zsh and others use 1-based indexing. this requires bash
69+
echo "${mnemonics[0]}"
70+
fi
71+
}
72+
73+
#prepare pastry properties
74+
echo external_address = $(curl -s https://ipinfo.io/ip):${LAS2PEER_PORT} > etc/pastry.properties
75+
76+
# start the service within a las2peer node
77+
if [[ -z "${@}" ]]
78+
then
79+
if [ -n "$LAS2PEER_ETH_HOST" ]; then
80+
exec ${LAUNCH_COMMAND} --node-id-seed $NODE_ID_SEED --observer --ethereum-mnemonic "$(selectMnemonic)" uploadStartupDirectory startService\("'""${SERVICE}""'", "'""${SERVICE_PASSPHRASE}""'"\) startWebConnector "node=getNodeAsEthereumNode()" "registry=node.getRegistryClient()" "n=getNodeAsEthereumNode()" "r=n.getRegistryClient()"
81+
else
82+
exec ${LAUNCH_COMMAND} --node-id-seed $NODE_ID_SEED --observer uploadStartupDirectory startService\("'""${SERVICE}""'", "'""${SERVICE_PASSPHRASE}""'"\) startWebConnector
83+
fi
84+
else
85+
exec ${LAUNCH_COMMAND} ${@}
86+
fi

0 commit comments

Comments
 (0)