Skip to content

Commit

Permalink
fix shell
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunny Jiao committed Jan 24, 2025
1 parent 74f4474 commit f0aaeb9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ repos:
- id: check-yaml
- id: double-quote-string-fixer
- id: check-shebang-scripts-are-executable
exclude: tools/docker/docker.sh
- id: check-executables-have-shebangs
- id: detect-private-key
- repo: 'https://github.com/jumanjihouse/pre-commit-hooks'
rev: 3.0.0
hooks:
- id: shellcheck
exclude: tools/docker/docker.sh
- id: script-must-have-extension
- id: git-dirty
- id: git-check
Expand Down
1 change: 1 addition & 0 deletions tools/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
set -eo pipefail
shopt -s nullglob

# shellcheck disable=SC2145
echo "./bin/FullNode $@" > command.txt
exec "./bin/FullNode" "$@"
10 changes: 7 additions & 3 deletions tools/docker/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export GOSS_PATH=$TEST_PATH/goss-linux-amd64
export GOSS_OPTS="$GOSS_OPTS --format junit"
export GOSS_FILES_STRATEGY=cp
DOCKER_IMAGE=$1
# shellcheck disable=SC2034
DOCKER_FILE="${2:-$PWD/Dockerfile}"

i=0
Expand All @@ -28,8 +29,11 @@ i=0
# we test that things listen on the right interface/port, not what interface the advertise
# hence we dont set p2p-host=0.0.0.0 because this sets what its advertising to devp2p; the important piece is that it defaults to listening on all interfaces
GOSS_FILES_PATH=$TEST_PATH/01 \
bash $TEST_PATH/dgoss run --sysctl net.ipv6.conf.all.disable_ipv6=1 $DOCKER_IMAGE \
#-p 8090:8090 -p 8091:8091 -p 18888:18888 -p 18888:18888/udp -p 50051:50051 \
bash $TEST_PATH/dgoss run --sysctl net.ipv6.conf.all.disable_ipv6=1 "$DOCKER_IMAGE" \
#-p 8090:8090 -p 8091:8091 -p 18888:18888 -p 18888:18888/udp -p 50051:50051
# shellcheck disable=SC2006
# shellcheck disable=SC2003
# shellcheck disable=SC2188
> ./reports/01.xml || i=`expr $i + 1`

exit $i
exit "$i"
9 changes: 6 additions & 3 deletions tools/docker/tests/01/testSync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ response=$(curl -X GET http://127.0.0.1:8090/wallet/getnodeinfo)
result=$(echo "$response" | jq -r '.beginSyncNum')
echo "result 1: $result, response 1: $response"

# shellcheck disable=SC2236
if [ ! -z "$result" ]; then
last_sync=$(printf "%d" "$result")
last_syncNum=$last_sync
echo "TRON node first sync: $last_sync"

else
alert="TRON node first sync error: : $response"
echo $alert
echo "$alert"
exit 1
fi

Expand All @@ -32,22 +33,24 @@ check_sync_process() {
result=$(echo "$response" | jq -r '.beginSyncNum')
echo "result 2: $result, response 2: $response"

# shellcheck disable=SC2236
if [ ! -z "$result" ]; then
last_sync=$(printf "%d" "$result")
second_syncNum=$last_sync
echo "TRON node second sync: $last_sync"
else
alert="TRON node second sync error: : $response"
echo $alert
echo "$alert"
exit 1
fi
}

# shellcheck disable=SC2004
for((i=1;i<=$count;i++)); do
echo "try i: $i"
sleep $monitor_interval
check_sync_process
if [ $second_syncNum -gt $last_syncNum ]; then
if [ "$second_syncNum" -gt "$last_syncNum" ]; then
echo "sync increased"
exit 0
fi
Expand Down
9 changes: 7 additions & 2 deletions tools/docker/tests/dgoss
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ setup_container(){
[[ -e "${GOSS_FILES_PATH}/goss.yaml" ]] && cp "${GOSS_FILES_PATH}/goss.yaml" "$tmp_dir"
[[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]] && cp "${GOSS_FILES_PATH}/goss_wait.yaml" "$tmp_dir"
[[ -e "${GOSS_FILES_PATH}/testSync.sh" ]] && cp "${GOSS_FILES_PATH}/testSync.sh" "$tmp_dir"
# shellcheck disable=SC2236
[[ ! -z "${GOSS_VARS}" ]] && [[ -e "${GOSS_FILES_PATH}/${GOSS_VARS}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_VARS}" "$tmp_dir"
# copy the Dockerfile if path has been provided
# shellcheck disable=SC2236
[[ ! -z "${3}" ]] && [[ "${3}" == *"Dockerfile"* ]] && cp "${3}" "$tmp_dir"
info "Setup complete"

Expand All @@ -47,11 +49,12 @@ setup_container(){
;;
cp)
info "Creating docker container"
# shellcheck disable=SC2068
id=$(docker create ${@:2})
info "Copy goss files into container"
docker cp $tmp_dir/. $id:/goss
docker cp "$tmp_dir"/. "$id":/goss
info "Starting docker container"
docker start $id > /dev/null
docker start "$id" > /dev/null
;;
*) error "Wrong goss files strategy used! Correct options are \"mount\" or \"cp\"."
esac
Expand All @@ -71,6 +74,7 @@ get_file_from_docker() {
# Main
tmp_dir=$(mktemp -d /tmp/tmp.XXXXXXXXXX)
chmod 777 "$tmp_dir"
# shellcheck disable=SC2154
trap 'ret=$?;cleanup;exit $ret' EXIT

GOSS_PATH="${GOSS_PATH:-$(which goss 2> /dev/null || true)}"
Expand Down Expand Up @@ -119,6 +123,7 @@ case "$1" in
docker exec -it "$id" sh -c 'cd /goss; PATH="/goss:$PATH" exec sh'
get_file_from_docker "/goss/goss.yaml"
get_file_from_docker "/goss/goss_wait.yaml"
# shellcheck disable=SC2236
[[ ! -z "${GOSS_VARS}" ]] && get_file_from_docker "/goss/${GOSS_VARS}"
;;
*)
Expand Down

0 comments on commit f0aaeb9

Please sign in to comment.