|
| 1 | +# Gradle Docker |
| 2 | +This document provides guidance on using Gradle to automate the build and test processes for java-tron docker image. You can customize the corresponding scripts to perform specific actions or integrate them with your existing Continuous Integration (CI) setup. |
| 3 | + |
| 4 | +If you encounter any problems during the build or testing process, please refer to the troubleshooting section. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | + |
| 8 | +Follow the [getting-started](https://github.com/tronprotocol/tron-docker/blob/main/README.md#getting-started) guide to download Docker and the tron-docker repository. Then, navigate to the gradlew directory. |
| 9 | +``` |
| 10 | +cd /java-tron/tools/gradlew |
| 11 | +``` |
| 12 | +Container testing uses the [Goss](https://github.com/goss-org/goss/blob/v0.4.9/README.md) tool, a YAML-based testing framework for validating service states. While no additional installation is required, it is beneficial to learn the basic usage of [Goss with container](https://goss.readthedocs.io/en/stable/container_image/) to help you better understand the following testing scripts. |
| 13 | + |
| 14 | +## Build image |
| 15 | + |
| 16 | +The command below will trigger the build process for java-tron image. Now we only support platform:`linux/amd64`. |
| 17 | +``` |
| 18 | +./gradlew --no-daemon sourceDocker |
| 19 | +``` |
| 20 | + |
| 21 | +The compilation process may take above 30 minutes, depending on your network conditions. Once it successfully completes, you will be able to see the generated image. |
| 22 | +``` |
| 23 | +$ docker images |
| 24 | +REPOSITORY TAG IMAGE ID CREATED SIZE |
| 25 | +tronprotocol/java-tron 1.0.0 76702facd55e 23 seconds ago 549MB |
| 26 | +``` |
| 27 | + |
| 28 | +### What ./gradlew sourceDocker do? |
| 29 | + |
| 30 | +It will trigger the execution of `task sourceDocker` in [build.gradle](build.gradle). Reviewing the logic, `task sourceDocker` essentially copies the Dockerfile and shell script to a build directory, then runs the docker build. From the logic, you can run `./gradlew sourceDocker` with customised `dockerOrgName`, `dockerArtifactName`, and `release.releaseVersion`. |
| 31 | + |
| 32 | +For example: |
| 33 | +``` |
| 34 | +./gradlew --no-daemon sourceDocker -PdockerOrgName=yourOrgName -PdockerArtifactName=test -Prelease.releaseVersion=V1.1.0 |
| 35 | +``` |
| 36 | +## Test image |
| 37 | + |
| 38 | +Test the java-tron image use the command below. |
| 39 | +``` |
| 40 | +./gradlew --no-daemon testDocker |
| 41 | +``` |
| 42 | +This will trigger the execution of `task testDocker` in [build.gradle](build.gradle). According to this logic, it will run the [test.sh](test.sh) script with the parameter of the Docker image name. |
| 43 | + |
| 44 | +The test.sh script sets up the Goss environment and then invokes the [dgoss shell](tests/dgoss), which will copy the test cases from [tests/01](tests/01) folder to the Docker container and execute the test validations. |
| 45 | + |
| 46 | +Currently, there are three test files: |
| 47 | + |
| 48 | +- The `goss.yaml` and `goss_wait.yaml` files are used to perform port checks. |
| 49 | + |
| 50 | +- The `testSync.sh` script is used to verify whether block synchronization is functioning normally. It will call `http://127.0.0.1:8090/wallet/getnodeinfo` 100 times. As long as `beginSyncNum` changes from the genesis block 0 to a larger number, the test will pass. |
| 51 | + |
| 52 | +Successful execution will output the following content: |
| 53 | +``` |
| 54 | +$ ./gradlew --no-daemon testDocker |
| 55 | +
|
| 56 | +To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.6.4/userguide/gradle_daemon.html#sec:disabling_the_daemon. |
| 57 | +Daemon will be stopped at the end of the build |
| 58 | +
|
| 59 | +> Task :docker:sourceDocker |
| 60 | +Building for default linux/amd64 platform |
| 61 | +#0 building with "desktop-linux" instance using docker driver |
| 62 | +
|
| 63 | +#1 [internal] load build definition from Dockerfile |
| 64 | +#1 transferring dockerfile: 2.32kB done |
| 65 | +#1 DONE 0.0s |
| 66 | +
|
| 67 | +#2 [internal] load metadata for docker.io/library/ubuntu:24.04 |
| 68 | +#2 DONE 3.9s |
| 69 | +
|
| 70 | +#3 [internal] load .dockerignore |
| 71 | +#3 transferring context: 2B done |
| 72 | +#3 DONE 0.0s |
| 73 | +
|
| 74 | +#4 [1/5] FROM docker.io/library/ubuntu:24.04@sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab |
| 75 | +#4 DONE 0.0s |
| 76 | +
|
| 77 | +#5 [internal] load build context |
| 78 | +#5 transferring context: 160B done |
| 79 | +#5 DONE 0.0s |
| 80 | +
|
| 81 | +#6 [2/5] RUN apt-get update -o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0 && apt-get --quiet --yes install git wget 7zip curl jq && wget -P /usr/local https://github.com/frekele/oracle-java/releases/download/8u202-b08/jdk-8u202-linux-x64.tar.gz && echo "0029351f7a946f6c05b582100c7d45b7 /usr/local/jdk-8u202-linux-x64.tar.gz" | md5sum -c && tar -zxf /usr/local/jdk-8u202-linux-x64.tar.gz -C /usr/local && rm /usr/local/jdk-8u202-linux-x64.tar.gz && export JAVA_HOME=/usr/local/jdk1.8.0_202 && export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar && export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$JAVA_HOME/bin && echo "git clone" && mkdir -p /tron-build && cd /tron-build && git clone https://github.com/tronprotocol/java-tron.git && cd java-tron && git checkout master && ./gradlew build -x test && cd build/distributions && 7z x -y java-tron-1.0.0.zip && mv java-tron-1.0.0 /java-tron && rm -rf /tron-build && rm -rf ~/.gradle && mv /usr/local/jdk1.8.0_202/jre /usr/local && rm -rf /usr/local/jdk1.8.0_202 apt-get clean && rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* && rm -rf /var/lib/apt/lists/* |
| 82 | +#6 CACHED |
| 83 | +
|
| 84 | +#7 [3/5] RUN wget -P /java-tron/config https://raw.githubusercontent.com/tronprotocol/tron-deployment/master/main_net_config.conf |
| 85 | +#7 CACHED |
| 86 | +
|
| 87 | +#8 [4/5] COPY docker-entrypoint.sh /java-tron/bin |
| 88 | +#8 CACHED |
| 89 | +
|
| 90 | +#9 [5/5] WORKDIR /java-tron |
| 91 | +#9 CACHED |
| 92 | +
|
| 93 | +#10 exporting to image |
| 94 | +#10 exporting layers done |
| 95 | +#10 writing image sha256:da229c38032f4c49c8199dcb9f1632f3312ee89b1d8d75f08700f43d35d6fd13 done |
| 96 | +#10 naming to docker.io/tronprotocol/java-tron:1.0.0 done |
| 97 | +#10 DONE 0.0s |
| 98 | +
|
| 99 | +View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/gyq5fuhe324kx4qd9judic3jl |
| 100 | +
|
| 101 | +> Task :docker:testDocker |
| 102 | +INFO: Run Docker tests |
| 103 | +INFO: Setting up test dir |
| 104 | +INFO: Setup complete |
| 105 | +INFO: Creating docker container |
| 106 | +WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested |
| 107 | +INFO: Copy goss files into container |
| 108 | +INFO: Starting docker container |
| 109 | +INFO: Container ID: e7e419dc |
| 110 | +INFO: Found goss_wait.yaml, waiting for it to pass before running tests |
| 111 | +INFO: Sleeping for 1.0 |
| 112 | +INFO: Running Tests |
| 113 | +<?xml version="1.0" encoding="UTF-8"?> |
| 114 | +<testsuite name="goss" errors="0" tests="1" failures="0" skipped="0" time="0.000" timestamp="2025-01-23T06:25:42Z"> |
| 115 | +<testcase name="Process java running" time="0.000"> |
| 116 | +<system-out>Process: java: running: matches expectation: true</system-out> |
| 117 | +</testcase> |
| 118 | +</testsuite> |
| 119 | +
|
| 120 | +BUILD SUCCESSFUL in 47s |
| 121 | +2 actionable tasks: 2 executed |
| 122 | +``` |
| 123 | + |
| 124 | +## Troubleshooting |
| 125 | + |
| 126 | +If you encounter the following errors while building the image: |
| 127 | + |
| 128 | +``` |
| 129 | +800.3 Cloning into 'java-tron'... |
| 130 | +1187.3 error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8) |
| 131 | +1187.3 error: xxxx bytes of body are still expected |
| 132 | +1187.3 fetch-pack: unexpected disconnect while reading sideband packet |
| 133 | +1187.3 fatal: early EOF |
| 134 | +1187.3 fatal: fetch-pack: invalid index-pack output |
| 135 | +``` |
| 136 | + |
| 137 | +Adjust your Git HTTP post buffer to a larger size by using the command below: |
| 138 | +``` |
| 139 | +git config --global http.postBuffer 5242880000 # Sets it to 5GB |
| 140 | +``` |
| 141 | + |
| 142 | +For other issues, they may be caused by poor network conditions. You could try switching to a different network or VPN. If the issue still cannot be resolved, please refer to [Issue Work Flow](https://tronprotocol.github.io/documentation-en/developers/issue-workflow/#issue-work-flow), then raise issue in [Github](https://github.com/tronprotocol/tron-docker/issues). |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
0 commit comments