Skip to content

Commit 3e98308

Browse files
authored
Merge pull request #35 from rwth-acis/v1.2.1
V1.2.1
2 parents 58b69f5 + d7fb236 commit 3e98308

4 files changed

Lines changed: 112 additions & 4 deletions

File tree

.github/workflows/gradle.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
name: Java CI with Gradle
55

66
# Triggers the workflow on push or pull request events (on every branch)
7-
on: [push, pull_request]
8-
7+
on:
8+
push:
9+
branches: [ master, develop]
910
jobs:
1011
build:
1112

@@ -23,4 +24,4 @@ jobs:
2324
run: ./gradlew build
2425
- uses: codecov/codecov-action@v1
2526
with:
26-
files: ./template_project/export/jacoco/test/jacocoTestReport.xml
27+
files: ./template_project/export/jacoco/test/jacocoTestReport.xml

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
28+
29+
EXPOSE $HTTP_PORT
30+
EXPOSE $HTTPS_PORT
31+
EXPOSE $LAS2PEER_PORT
32+
RUN chmod +x /src/docker-entrypoint.sh
33+
ENTRYPOINT ["/src/docker-entrypoint.sh"]

docker-entrypoint.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.servicePackage.TemplateService.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+
24+
# set defaults for optional service parameters
25+
[[ -z "${SERVICE_PASSPHRASE}" ]] && export SERVICE_PASSPHRASE='template'
26+
27+
# wait for any bootstrap host to be available
28+
if [[ ! -z "${BOOTSTRAP}" ]]; then
29+
echo "Waiting for any bootstrap host to become available..."
30+
for host_port in ${BOOTSTRAP//,/ }; do
31+
arr_host_port=(${host_port//:/ })
32+
host=${arr_host_port[0]}
33+
port=${arr_host_port[1]}
34+
if { </dev/tcp/${host}/${port}; } 2>/dev/null; then
35+
echo "${host_port} is available. Continuing..."
36+
break
37+
fi
38+
done
39+
fi
40+
# prevent glob expansion in lib/*
41+
set -f
42+
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}"
43+
if [[ ! -z "${BOOTSTRAP}" ]]; then
44+
LAUNCH_COMMAND="${LAUNCH_COMMAND} -b ${BOOTSTRAP}"
45+
fi
46+
47+
# it's realistic for different nodes to use different accounts (i.e., to have
48+
# different node operators). this function echos the N-th mnemonic if the
49+
# variable WALLET is set to N. If not, first mnemonic is used
50+
function selectMnemonic {
51+
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")
52+
if [[ ${WALLET} =~ ^[0-9]+$ && ${WALLET} -lt ${#mnemonics[@]} ]]; then
53+
# get N-th mnemonic
54+
echo "${mnemonics[${WALLET}]}"
55+
else
56+
# note: zsh and others use 1-based indexing. this requires bash
57+
echo "${mnemonics[0]}"
58+
fi
59+
}
60+
61+
#prepare pastry properties
62+
echo external_address = $(curl -s https://ipinfo.io/ip):${LAS2PEER_PORT} > etc/pastry.properties
63+
64+
# start the service within a las2peer node
65+
if [[ -z "${@}" ]]
66+
then
67+
if [ -n "$LAS2PEER_ETH_HOST" ]; then
68+
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()"
69+
else
70+
exec ${LAUNCH_COMMAND} --node-id-seed $NODE_ID_SEED --observer uploadStartupDirectory startService\("'""${SERVICE}""'", "'""${SERVICE_PASSPHRASE}""'"\) startWebConnector
71+
fi
72+
else
73+
exec ${LAUNCH_COMMAND} ${@}
74+
fi

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
core.version=1.2.0
1+
core.version=1.2.2
22
service.name=i5.las2peer.services.templateService
33
service.class=TemplateService
44
service.version=1.0.0

0 commit comments

Comments
 (0)