From afc4919d3e443d6681173f93ddb9c5066544a105 Mon Sep 17 00:00:00 2001 From: Edward Date: Fri, 24 Jan 2025 17:10:15 +0800 Subject: [PATCH 1/2] fix shell cehck (#17) --- .pre-commit-config.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index adb3693..156e62f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,11 +14,14 @@ repos: - 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 + - repo: 'https://github.com/koalaman/shellcheck-precommit' + rev: v0.7.2 + hooks: + - id: shellcheck + exclude: tools/docker/docker.sh - repo: local # check java files format use a customized script hooks: - id: checkstyle From fcd5c99ca0c9fa2c943d760fe5cfc5ea846e6322 Mon Sep 17 00:00:00 2001 From: Edward Date: Fri, 24 Jan 2025 17:27:30 +0800 Subject: [PATCH 2/2] chore: delete unused file (#18) --- .github/workflows/codeql.yml | 2 +- .pre-commit-config.yaml | 2 - tools/docker/docker.sh | 291 ----------------------------------- 3 files changed, 1 insertion(+), 294 deletions(-) delete mode 100644 tools/docker/docker.sh diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 81151e9..314c24a 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -4,7 +4,7 @@ run-name: Lint sources on: push: pull_request: - branches: [main, develop] + branches: [main, develop, release_*] jobs: lint: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 156e62f..05fc6fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,6 @@ 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' @@ -21,7 +20,6 @@ repos: rev: v0.7.2 hooks: - id: shellcheck - exclude: tools/docker/docker.sh - repo: local # check java files format use a customized script hooks: - id: checkstyle diff --git a/tools/docker/docker.sh b/tools/docker/docker.sh deleted file mode 100644 index bf4961f..0000000 --- a/tools/docker/docker.sh +++ /dev/null @@ -1,291 +0,0 @@ -#!/bin/bash -############################################################################# -# -# GNU LESSER GENERAL PUBLIC LICENSE -# Version 3, 29 June 2007 -# -# Copyright (C) [2007] [TRON Foundation], Inc. -# Everyone is permitted to copy and distribute verbatim copies -# of this license document, but changing it is not allowed. -# -# -# This version of the GNU Lesser General Public License incorporates -# the terms and conditions of version 3 of the GNU General Public -# License, supplemented by the additional permissions listed below. -# -# You can find java-tron at https://github.com/tronprotocol/java-tron/ -# -############################################################################## - -BASE_DIR="/java-tron" -DOCKER_REPOSITORY="tronprotocol" -DOCKER_IMAGES="java-tron" -# latest or version -DOCKER_TARGET="latest" - -HOST_HTTP_PORT=8090 -HOST_RPC_PORT=50051 -HOST_LISTEN_PORT=18888 - -DOCKER_HTTP_PORT=8090 -DOCKER_RPC_PORT=50051 -DOCKER_LISTEN_PORT=18888 - -VOLUME=`pwd` -CONFIG="$VOLUME/config" -OUTPUT_DIRECTORY="$VOLUME/output-directory" - -CONFIG_PATH="/java-tron/config/" -CONFIG_FILE="main_net_config.conf" -MAIN_NET_CONFIG_FILE="main_net_config.conf" -TEST_NET_CONFIG_FILE="test_net_config.conf" -PRIVATE_NET_CONFIG_FILE="private_net_config.conf" - -# update the configuration file, if true, the configuration file will be fetched from the network every time you start -UPDATE_CONFIG=true - -LOG_FILE="/logs/tron.log" - -JAVA_TRON_REPOSITORY="https://raw.githubusercontent.com/tronprotocol/java-tron/develop/" -DOCKER_FILE="Dockerfile" -ENDPOINT_SHELL="docker-entrypoint.sh" - -if test docker; then - docker -v -else - echo "warning: docker must be installed, please install docker first." - exit -fi - -docker_ps() { - containerID=`docker ps -a | grep "$DOCKER_REPOSITORY-$DOCKER_IMAGES" | awk '{print $1}'` - cid=$containerID -} - -docker_image() { - image_name=`docker images |grep "$DOCKER_REPOSITORY/$DOCKER_IMAGES" |awk {'print $1'}| awk 'NR==1'` - image=$image_name -} - -download_config() { - mkdir -p config - if test curl; then - curl -o config/$CONFIG_FILE -LO https://raw.githubusercontent.com/tronprotocol/tron-deployment/master/$CONFIG_FILE -s - elif test wget; then - wget -P -q config/ https://raw.githubusercontent.com/tronprotocol/tron-deployment/master/$CONFIG_FILE - fi -} - - -check_download_config() { - if [[ ! -d 'config' || ! -f "config/$CONFIG_FILE" ]]; then - mkdir -p config - if test curl; then - curl -o config/$CONFIG_FILE -LO https://raw.githubusercontent.com/tronprotocol/tron-deployment/master/$CONFIG_FILE -s - elif test wget; then - wget -P -q config/ https://raw.githubusercontent.com/tronprotocol/tron-deployment/master/$CONFIG_FILE - fi - fi -} - -run() { - docker_image - - if [ ! $image ] ; then - echo 'warning: no java-tron mirror image, do you need to get the mirror image?[y/n]' - read need - - if [[ $need == 'y' || $need == 'yes' ]]; then - pull - else - echo "warning: no mirror image found, go ahead and download a mirror." - exit - fi - fi - - volume="" - parameter="" - tron_parameter="" - if [ $# -gt 0 ]; then - while [ -n "$1" ]; do - case "$1" in - -v) - volume="$volume -v $2" - shift 2 - ;; - -p) - parameter="$parameter -p $2" - shift 2 - ;; - -c) - tron_parameter="$tron_parameter -c $2" - UPDATE_CONFIG=false - shift 2 - ;; - --net) - if [[ "$2" = "main" ]]; then - CONFIG_FILE=$MAIN_NET_CONFIG_FILE - elif [[ "$2" = "test" ]]; then - CONFIG_FILE=$TEST_NET_CONFIG_FILE - elif [[ "$2" = "private" ]]; then - CONFIG_FILE=$PRIVATE_NET_CONFIG_FILE - fi - shift 2 - ;; - --update-config) - UPDATE_CONFIG=$2 - shift 2 - ;; - *) - echo "run: arg $1 is not a valid parameter" - exit - ;; - esac - done - if [ $UPDATE_CONFIG = true ]; then - download_config - fi - - if [ -z "$volume" ]; then - volume=" -v $CONFIG:/java-tron/config -v $OUTPUT_DIRECTORY:/java-tron/output-directory" - fi - - if [ -z "$parameter" ]; then - parameter=" -p $HOST_HTTP_PORT:$DOCKER_HTTP_PORT -p $HOST_RPC_PORT:$DOCKER_RPC_PORT -p $HOST_LISTEN_PORT:$DOCKER_LISTEN_PORT" - fi - - if [ -z "$tron_parameter" ]; then - tron_parameter=" -c $CONFIG_PATH$CONFIG_FILE" - fi - - # Using custom parameters - docker run -d -it --name "$DOCKER_REPOSITORY-$DOCKER_IMAGES" \ - $volume \ - $parameter \ - --restart always \ - "$DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET" \ - $tron_parameter - else - if [ $UPDATE_CONFIG = true ]; then - download_config - fi - # Default parameters - docker run -d -it --name "$DOCKER_REPOSITORY-$DOCKER_IMAGES" \ - -v $CONFIG:/java-tron/config \ - -v $OUTPUT_DIRECTORY:/java-tron/output-directory \ - -p $HOST_HTTP_PORT:$DOCKER_HTTP_PORT \ - -p $HOST_RPC_PORT:$DOCKER_RPC_PORT \ - -p $HOST_LISTEN_PORT:$DOCKER_LISTEN_PORT \ - --restart always \ - "$DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET" \ - -c "$CONFIG_PATH$CONFIG_FILE" - fi -} - -build() { - echo 'docker build' - if [ ! -f "Dockerfile" ]; then - echo 'warning: Dockerfile not exists.' - if test curl; then - DOWNLOAD_CMD="curl -LJO " - elif test wget; then - DOWNLOAD_CMD="wget " - else - echo "Dockerfile cannot be downloaded, you need to install 'curl' or 'wget'!" - exit - fi - # download Dockerfile - `$DOWNLOAD_CMD "$JAVA_TRON_REPOSITORY$DOCKER_FILE"` - `$DOWNLOAD_CMD "$JAVA_TRON_REPOSITORY$ENDPOINT_SHELL"` - chmod u+rwx $ENDPOINT_SHELL - fi - docker build -t "$DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET" . -} - -pull() { - echo "docker pull $DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET" - docker pull "$DOCKER_REPOSITORY/$DOCKER_IMAGES:$DOCKER_TARGET" -} - -start() { - docker_ps - if [ $cid ]; then - echo "containerID: $cid" - echo "docker stop $cid" - docker start $cid - docker ps - else - echo "container not running!" - fi -} - -stop() { - docker_ps - if [ $cid ]; then - echo "containerID: $cid" - echo "docker stop $cid" - docker stop $cid - docker ps - else - echo "container not running!" - fi -} - -rm_container() { - stop - if [ $cid ]; then - echo "containerID: $cid" - echo "docker rm $cid" - docker rm $cid - docker_ps - else - echo "image not exists!" - fi -} - -log() { - docker_ps - - if [ $cid ]; then - echo "containerID: $cid" - docker exec -it $cid tail -100f $BASE_DIR/$LOG_FILE - else - echo "container not exists!" - fi - -} - -case "$1" in - --pull) - pull ${@: 2} - exit - ;; - --start) - start ${@: 2} - exit - ;; - --stop) - stop ${@: 2} - exit - ;; - --build) - build ${@: 2} - exit - ;; - --run) - run ${@: 2} - exit - ;; - --rm) - rm_container ${@: 2} - exit - ;; - --log) - log ${@: 2} - exit - ;; - *) - echo "arg: $1 is not a valid parameter" - exit - ;; -esac