Skip to content

Commit 361c39d

Browse files
authored
feat(gradle): add gradle docker README (#13)
1 parent 7e9aa27 commit 361c39d

File tree

5 files changed

+162
-7
lines changed

5 files changed

+162
-7
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TRON Docker
22

3-
This repository provides a quick and easy way to set up a single node, private chain, and monitor the status of nodes for the TRON Network using Docker.
3+
This repository provides guidance and tools for the community to quickly get started with TRON network and development.
44

55
## Features
66

@@ -16,6 +16,12 @@ You can also use this repository to set up a private TRON blockchain network. Th
1616

1717
Monitoring the health and performance of your TRON nodes is made easy with integrated Prometheus and Grafana services. The repository includes configurations to set up these monitoring tools, allowing you to visualize and track various metrics in real time.
1818

19+
### Tools
20+
21+
We also provide tools to facilitate the CI and testing process:
22+
- Gradle Docker: Using Gradle to automate the build and test processes for java-tron image.
23+
- DB Fork: This tool helps launch a private Java-Tron network based on the state of the Mainnet database to support shadow fork testing.
24+
1925
## Getting Started
2026

2127
### Prerequisites
@@ -36,6 +42,8 @@ Monitoring the health and performance of your TRON nodes is made easy with integ
3642
- To start a single FullNode, use the folder [single_node](./single_node).
3743
- To set up a private TRON network, use the folder [private_net](./private_net).
3844
- To monitor the TRON node, use the folder [metric_monitor](./metric_monitor).
45+
- To use Gradle with Docker, check [gradle docker](./tools/docker/README.md).
46+
- To do shadow fork testing, check [db fork guidance](./tools/dbfork/README.md).
3947

4048
## Troubleshooting
4149
If you encounter any difficulties, please refer to the [Issue Work Flow](https://tronprotocol.github.io/documentation-en/developers/issue-workflow/#issue-work-flow), then raise an issue on [GitHub](https://github.com/tronprotocol/tron-docker/issues). For general questions, please use [Discord](https://discord.gg/cGKSsRVCGm) or [Telegram](https://t.me/TronOfficialDevelopersGroupEn).

single_node/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ There are two ways to obtain the TRON image:
3030
- Pull it from the TRON Docker Hub.
3131
- Build it from the java-tron source code.
3232

33-
### Using the official Docker images
33+
### Pull from TRON docker hub
3434

3535
The quick start way is to use the official images. Download the official Docker image from [Docker Hub](https://hub.docker.com/r/tronprotocol/java-tron/tags) using the following command:
3636

tools/docker/README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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+

tools/docker/test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export TEST_PATH=./tests
1818
#export GOSS_PATH=$TEST_PATH/goss-linux-${architecture} # TODO. fixed by https://github.com/goss-org/goss/tree/master/extras/dgoss#mac-osx
1919
export GOSS_PATH=$TEST_PATH/goss-linux-amd64
2020
export GOSS_OPTS="$GOSS_OPTS --format junit"
21-
export GOSS_FILES_STRATEGY=cp
22-
DOCKER_IMAGE=$1
23-
DOCKER_FILE="${2:-$PWD/Dockerfile}"
21+
export GOSS_FILES_STRATEGY=cp # The cp strategy means that test files will be copied to the container.
22+
DOCKER_IMAGE=$1 # The first param passed
23+
DOCKER_FILE="${2:-$PWD/Dockerfile}" # If no second argument is provided, it defaults to the Dockerfile located in the current working directory ($PWD).
2424

25-
i=0
25+
i=0 # This initializes a counter variable i that will be used to track the number of failed tests.
2626

2727
# Test for normal startup with ports opened
2828
# we test that things listen on the right interface/port, not what interface the advertise

tools/docker/tests/01/goss_wait.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ http:
3131
method: GET
3232
status: 200
3333
body:
34-
- "\"blockID\":\"00000000000000001ebf88508a03865c71d452e25f4d51194196a1d22b6653dc\""
34+
- "\"blockID\":\"00000000000000001ebf88508a03865c71d452e25f4d51194196a1d22b6653dc\"" # genesis block id
3535

3636
command:
3737
/goss/testSync.sh: # use absolute directory to run shell

0 commit comments

Comments
 (0)