Skip to content

Commit a4ff2cf

Browse files
committed
Iterate on Dockerfile and docker-entrypoint.sh
Signed-off-by: Jakub Dzikowski <jakub.t.dzikowski@gmail.com>
1 parent 39fbcb4 commit a4ff2cf

File tree

7 files changed

+643
-58
lines changed

7 files changed

+643
-58
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
FROM node:18-alpine3.16
22

33
RUN apk add --no-cache sudo shfmt
4-
RUN npm install --global --silent yo
54

65
# copy fablo files
7-
COPY generators /fablo/generators
6+
COPY dist /fablo/dist
87
COPY package.json /fablo/package.json
98
COPY package-lock.json /fablo/package-lock.json
109

@@ -29,6 +28,8 @@ RUN adduser -D -u 501 yeoman && \
2928
ENV HOME /network/workspace
3029

3130
COPY docker-entrypoint.sh /fablo/docker-entrypoint.sh
31+
COPY bin /fablo/bin
32+
COPY bin/run.js /fablo/bin/run.mjs
3233
COPY docs /fablo/docs
3334
COPY README.md /fablo/README.md
3435
COPY samples /fablo/samples/

docker-entrypoint.sh

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,39 @@
22

33
set -e
44

5-
executeYeomanCommand() {
5+
executeOclifCommand() {
66
command_with_params=$1
77

8-
# cleanup yeoman files after execution
9-
# shellcheck disable=SC2064
10-
trap "rm -rf \"$yeoman_target_dir/.cache\" \"$yeoman_target_dir/.config\" \"$yeoman_target_dir/.npm\"" EXIT
8+
ls -la /fablo/
9+
ls -la /fablo/bin/
1110

1211
if [ "$(id -u)" = 0 ]; then
13-
# root user detected, running as yeoman user
14-
sudo chown -R yeoman:yeoman "$yeoman_target_dir"
12+
# root user detected, running as yeoman user (keeping for compatibility)
13+
sudo chown -R yeoman:yeoman "$target_dir"
1514
# shellcheck disable=SC2086
16-
(cd "$yeoman_target_dir" && sudo -E -u yeoman yo --no-insight $command_with_params)
17-
sudo chown -R root:root "$yeoman_target_dir"
15+
(cd "$target_dir" && sudo -E -u yeoman node /fablo/bin/run.mjs $command_with_params)
16+
sudo chown -R root:root "$target_dir"
1817
else
1918
# shellcheck disable=SC2086
20-
(cd "$yeoman_target_dir" && yo --no-insight $command_with_params)
19+
(cd "$target_dir" && node /fablo/bin/run.mjs $command_with_params)
2120
fi
2221
}
2322

2423
formatGeneratedFiles() {
2524
# Additional script and yaml formatting
2625
#
27-
# Why? Yeoman output may contain some additional whitespaces or the formatting
26+
# Why? Generated output may contain some additional whitespaces or the formatting
2827
# might not be ideal. Keeping those whitespaces, however, might be useful
2928
# in templates to improve the brevity. That's why we need additional formatting.
3029
# Since the templates should obey good practices, we don't use linters here
3130
# (i.e. shellcheck and yamllint).
3231
echo "Formatting generated files"
33-
shfmt -i=2 -l -w "$yeoman_target_dir" >/dev/null
32+
shfmt -i=2 -l -w "$target_dir" >/dev/null
3433

35-
for yaml in "$yeoman_target_dir"/**/*.yaml; do
34+
for yaml in "$target_dir"/**/*.yaml; do
3635

3736
# the expansion failed, no yaml files found
38-
if [ "$yaml" = "$yeoman_target_dir/**/*.yaml" ]; then
37+
if [ "$yaml" = "$target_dir/**/*.yaml" ]; then
3938
break
4039
fi
4140

@@ -48,16 +47,19 @@ formatGeneratedFiles() {
4847
done
4948
}
5049

51-
yeoman_target_dir="/network/workspace"
52-
yeoman_command=${1:-Fablo:setup-network}
50+
target_dir="/network/workspace"
51+
oclif_command=${1:-setup-network}
5352

54-
# This part of output will be replaces with empty line. It breaks parsing of yeoman generator output.
55-
# See also: https://github.com/yeoman/generator/issues/1294
56-
annoying_yeoman_info="No change to package.json was detected. No package manager install will be executed."
53+
# Map old yeoman command format to oclif format
54+
case "$oclif_command" in
55+
"Fablo:setup-network"|"fablo:setup-network")
56+
oclif_command="setup-network"
57+
;;
58+
esac
5759

5860
# Execute the command
59-
executeYeomanCommand "$yeoman_command" 2>&1 | sed "s/$annoying_yeoman_info//g"
61+
executeOclifCommand "$oclif_command"
6062

61-
if echo "$yeoman_command" | grep "setup-network"; then
63+
if echo "$oclif_command" | grep -q "setup-network"; then
6264
formatGeneratedFiles
6365
fi

e2e-network/docker/test-01-v3-simple.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export FABLO_HOME
1010

1111
networkUp() {
1212
"$FABLO_HOME/fablo-build.sh"
13-
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" init node dev)
13+
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" init)
1414
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" up)
1515
}
1616

fablo-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if [ "$(command -v nvm)" = "nvm" ]; then
3030
fi
3131

3232
npm install
33-
npm run build:dist
33+
npm run build
3434

3535
# if --push is passed, then build for all platforms and push the image to the registry
3636
if [ "${1:-''}" = "--push" ]; then

fablo.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,31 @@ useVersion() {
231231
set +e
232232
curl -Lf https://github.com/hyperledger-labs/fablo/releases/download/"$version"/fablo.sh -o "$0" && chmod +x "$0"
233233
else
234-
executeOnFabloDocker "fablo:list-versions"
234+
executeOnFabloDocker "list-versions"
235235
fi
236236
}
237237

238238
initConfig() {
239239
printSplash
240-
executeOnFabloDocker "fablo:init $1 $2"
240+
executeOnFabloDocker "init $1 $2"
241241
cp -R -i "$FABLO_TEMP_DIR/." "$COMMAND_CALL_ROOT/"
242242
}
243243

244244
validateConfig() {
245245
local fablo_config=${1:-$(getDefaultFabloConfig)}
246-
executeOnFabloDocker "fablo:validate" "" "$fablo_config"
246+
executeOnFabloDocker "validate" "" "$fablo_config"
247247
}
248248

249249
extendConfig() {
250250
local fablo_config=${1:-$(getDefaultFabloConfig)}
251-
executeOnFabloDocker "fablo:extend-config" "" "$fablo_config"
251+
executeOnFabloDocker "extend-config" "" "$fablo_config"
252252
}
253253

254254
exportNetworkTopology() {
255255
local fablo_config=${1:-$(getDefaultFabloConfig)}
256256
local output_file=${2:-network-topology.mmd}
257257

258-
executeOnFabloDocker "fablo:export-network-topology /network/fablo-config.json $output_file" "$(dirname "$output_file")" "$fablo_config"
258+
executeOnFabloDocker "export-network-topology /network/fablo-config.json $output_file" "$(dirname "$output_file")" "$fablo_config"
259259
}
260260

261261
generateNetworkConfig() {
@@ -269,7 +269,7 @@ generateNetworkConfig() {
269269
echo " FABLO_NETWORK_ROOT: $fablo_target"
270270

271271
mkdir -p "$fablo_target"
272-
executeOnFabloDocker "fablo:setup-network" "$fablo_target" "$fablo_config"
272+
executeOnFabloDocker "setup-network" "$fablo_target" "$fablo_config"
273273
if [ -f "$fablo_target/hooks/post-generate.sh" ]; then
274274
chmod +x "$fablo_target/hooks/post-generate.sh" || true
275275
("$fablo_target/hooks/post-generate.sh")
@@ -366,7 +366,7 @@ elif [ "$COMMAND" = "help" ] || [ "$COMMAND" = "--help" ]; then
366366
printHelp
367367

368368
elif [ "$COMMAND" = "version" ]; then
369-
executeOnFabloDocker "fablo:version $2"
369+
executeOnFabloDocker "version $2"
370370

371371
elif [ "$COMMAND" = "use" ]; then
372372
useVersion "$2"

0 commit comments

Comments
 (0)