Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: update docker-compose
  • Loading branch information
phenix3443 committed Aug 27, 2025
commit dd077d5785e24600cc022fcf407cdbe550d19a47
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hl-visor.asc
30 changes: 7 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,20 @@ ARG USERNAME=hluser
ARG USER_UID=10000
ARG USER_GID=$USER_UID

# Define URLs as environment variables
ARG PUB_KEY_URL=https://raw.githubusercontent.com/hyperliquid-dex/node/refs/heads/main/pub_key.asc
ARG HL_VISOR_URL=https://binaries.hyperliquid-testnet.xyz/Testnet/hl-visor
ARG HL_VISOR_ASC_URL=https://binaries.hyperliquid-testnet.xyz/Testnet/hl-visor.asc

# Create user and install dependencies
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get update -y && apt-get install -y curl gnupg \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& mkdir -p /home/$USERNAME/hl/data && chown -R $USERNAME:$USERNAME /home/$USERNAME/hl

# Copy initialization script
COPY init.sh /home/$USERNAME/
RUN chmod +x /home/$USERNAME/init.sh \
&& chown $USERNAME:$USERNAME /home/$USERNAME/init.sh

USER $USERNAME
WORKDIR /home/$USERNAME

# Configure chain to testnet
RUN echo '{"chain": "Testnet"}' > /home/$USERNAME/visor.json

# Import GPG public key
RUN curl -o /home/$USERNAME/pub_key.asc $PUB_KEY_URL \
&& gpg --import /home/$USERNAME/pub_key.asc

# Download and verify hl-visor binary
RUN curl -o /home/$USERNAME/hl-visor $HL_VISOR_URL \
&& curl -o /home/$USERNAME/hl-visor.asc $HL_VISOR_ASC_URL \
&& gpg --verify /home/$USERNAME/hl-visor.asc /home/$USERNAME/hl-visor \
&& chmod +x /home/$USERNAME/hl-visor

# Expose gossip ports
EXPOSE 4000-4010

# Run a non-validating node
ENTRYPOINT ["/home/hluser/hl-visor", "run-non-validator", "--replica-cmds-style", "recent-actions"]
# Expose ports
EXPOSE 4000-4010 3001
28 changes: 28 additions & 0 deletions config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Hyperliquid Node Environment Configuration
# Network type: mainnet or testnet
HL_NETWORK=testnet

# GPG Public Key URL
PUB_KEY_URL=https://raw.githubusercontent.com/hyperliquid-dex/node/refs/heads/main/pub_key.asc

# Root Node IP Addresses (comma-separated)
ROOT_NODE_IPS=64.31.48.111,64.31.51.137

# Whether to try new peers
TRY_NEW_PEERS=true

# Reserved Peer IPs (comma-separated, optional)
RESERVED_PEER_IPS=

# Data writing options
WRITE_TRADES=true
WRITE_FILLS=true
WRITE_ORDER_STATUSES=true
WRITE_MISC_EVENTS=true

# Service options
SERVE_ETH_RPC=true
SERVE_INFO=true

# Replica command style
REPLICA_CMDS_STYLE=actions
9 changes: 7 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ services:
restart: unless-stopped
build: .
ports:
- "4000-4010:4000-4010"
- 4000-4010:4000-4010
- 3001:3001
volumes:
- hl-data:/home/hluser/hl/data
env_file:
- config.env
command: ["/bin/bash", "-c", "/home/hluser/init.sh && /home/hluser/hl-visor run-non-validator"]

pruner:
restart: unless-stopped
build: ./pruner
volumes:
- hl-data:/home/hluser/hl/data

env_file:
- config.env

volumes:
hl-data:
Expand Down
64 changes: 64 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Hyperliquid Node initialization script
# Perform one-time setup when container is created

set -e

# Check if already initialized
if [ -f /home/hluser/.initialized ]; then
echo "Already initialized, skipping..."
exit 0
fi

echo "Initializing Hyperliquid Node environment..."

# Download and import GPG public key
echo "Downloading and importing GPG public key..."
curl -o /home/hluser/pub_key.asc "${PUB_KEY_URL:-https://raw.githubusercontent.com/hyperliquid-dex/node/refs/heads/main/pub_key.asc}"
gpg --import /home/hluser/pub_key.asc

# Download and verify binaries based on network type
if [ "${HL_NETWORK:-testnet}" = "mainnet" ]; then
echo "Downloading Mainnet binary..."
curl -o /home/hluser/hl-visor https://binaries.hyperliquid.xyz/Mainnet/hl-visor
curl -o /home/hluser/hl-visor.asc https://binaries.hyperliquid.xyz/Mainnet/hl-visor.asc
else
echo "Downloading Testnet binary..."
curl -o /home/hluser/hl-visor https://binaries.hyperliquid-testnet.xyz/Testnet/hl-visor
curl -o /home/hluser/hl-visor.asc https://binaries.hyperliquid-testnet.xyz/Testnet/hl-visor.asc
fi

# Verify binary and set permissions
echo "Verifying binary and setting permissions..."
gpg --verify /home/hluser/hl-visor.asc /home/hluser/hl-visor
chmod +x /home/hluser/hl-visor

# Create initial configuration
echo "Creating initial configuration..."
if [ "${HL_NETWORK:-testnet}" = "mainnet" ]; then
echo '{"chain": "Mainnet"}' > /home/hluser/visor.json
else
echo '{"chain": "Testnet"}' > /home/hluser/visor.json
fi

# Create gossip configuration
echo "Creating gossip configuration..."
# Convert comma-separated IPs to JSON array
ROOT_IPS=$(echo "${ROOT_NODE_IPS:-64.31.48.111,64.31.51.137}" | sed 's/,/",{"Ip":"/g')
RESERVED_IPS=$(echo "${RESERVED_PEER_IPS:-}" | sed 's/,/",{"Ip":"/g')

cat > /home/hluser/override_gossip_config.json << EOF
{
"root_node_ips": [{"Ip":"$ROOT_IPS"}],
"try_new_peers": ${TRY_NEW_PEERS:-true},
"chain": "${HL_NETWORK:-testnet}",
"reserved_peer_ips": [{"Ip":"$RESERVED_IPS"}]
}
EOF

echo "Initialization complete."

# Mark as initialized
touch /home/hluser/.initialized

3 changes: 3 additions & 0 deletions plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. run.sh 通过 docker-compose.yml 来管理容器环境,比如 run.sh start 启动容器环境, run.sh stop 暂停容器环境。
2. docker 在构建创建容器的时候执行 init.sh 来初始化容器的执行环境。
2.
Loading