generalize haqq initialization

This commit is contained in:
goldsquid
2025-11-23 13:24:57 +07:00
parent 0acfbf88fa
commit e433d44a93
3 changed files with 89 additions and 5 deletions

9
haqq/haqq.Dockerfile Normal file
View File

@@ -0,0 +1,9 @@
ARG HAQQ_HAQQ_IMAGE
ARG HAQQ_HAQQ_VERSION
FROM ${HAQQ_HAQQ_IMAGE}:${HAQQ_HAQQ_VERSION}
COPY ./scripts/init.sh /usr/local/bin/init.sh
RUN chmod +x /usr/local/bin/init.sh
ENTRYPOINT [ "init.sh" ]

View File

@@ -30,7 +30,12 @@ x-logging-defaults: &logging-defaults
services: services:
haqq-mainnet: haqq-mainnet:
image: ${HAQQ_HAQQ_IMAGE:-alhaqq/haqq}:${HAQQ_MAINNET_HAQQ_VERSION:-v1.9.1} build:
context: ./haqq
dockerfile: haqq.Dockerfile
args:
HAQQ_HAQQ_VERSION: ${HAQQ_MAINNET_HAQQ_VERSION:-v1.8.5}
HAQQ_HAQQ_IMAGE: ${HAQQ_MAINNET_HAQQ_IMAGE:-alhaqq/haqq}
sysctls: sysctls:
# TCP Performance # TCP Performance
net.ipv4.tcp_slow_start_after_idle: 0 # Disable slow start after idle net.ipv4.tcp_slow_start_after_idle: 0 # Disable slow start after idle
@@ -51,18 +56,24 @@ services:
expose: expose:
- 8545 - 8545
- 8546 - 8546
entrypoint: [haqqd, start] - 6065
command: --p2p.laddr=tcp://0.0.0.0:10465 environment:
- IP=${IP}
- MONIKER=d${DOMAIN:-local}
- P2P_PORT=10465
restart: unless-stopped restart: unless-stopped
stop_grace_period: 5m stop_grace_period: 5m
networks: networks:
- chains - chains
volumes: volumes:
- ${HAQQ_MAINNET_HAQQ_PRUNED_DATA:-haqq-mainnet-haqq-pruned}:/root/.haqqd - ${HAQQ_MAINNET_HAQQ_PRUNED_DATA:-haqq-mainnet-haqq-pruned}:/root/.haqqd/data
- /slowdisk:/slowdisk - /slowdisk:/slowdisk
- haqq-mainnet-haqq-pruned_config:/root/.haqqd/config
logging: *logging-defaults logging: *logging-defaults
labels: labels:
- prometheus-scrape.enabled=false - prometheus-scrape.enabled=true
- prometheus-scrape.port=6065
- prometheus-scrape.path=/metrics
- traefik.enable=true - traefik.enable=true
- traefik.http.middlewares.haqq-mainnet-haqq-pruned-stripprefix.stripprefix.prefixes=/haqq-mainnet - traefik.http.middlewares.haqq-mainnet-haqq-pruned-stripprefix.stripprefix.prefixes=/haqq-mainnet
- traefik.http.services.haqq-mainnet-haqq-pruned.loadbalancer.server.port=8545 - traefik.http.services.haqq-mainnet-haqq-pruned.loadbalancer.server.port=8545
@@ -84,6 +95,7 @@ services:
volumes: volumes:
haqq-mainnet-haqq-pruned: haqq-mainnet-haqq-pruned:
haqq-mainnet-haqq-pruned_config:
x-upstreams: x-upstreams:
- id: $${ID} - id: $${ID}

63
haqq/scripts/init.sh Normal file
View File

@@ -0,0 +1,63 @@
#!/bin/sh
set -e # Exit on failure
echo "MONIKER: $MONIKER"
CHAINID=${CHAINID:-haqq_11235-1}
CHAINNAME=${CHAINNAME:-mainnet}
CONFIG_DIR="/root/.haqqd/config"
# Create config directory
mkdir -p "$CONFIG_DIR"
JWTSECRET="$(cat /jwtsecret)" # needs to go to the config dir (default path)
P2P_STRING="tcp:\\/\\/0\\.0\\.0\\.0\\:${P2P_PORT:-10465}"
NAT_STRING="${IP}:${P2P_PORT:-10465}"
env
# this goes first because it won't overwrite shit
apk add curl
if [ $? -ne 0 ]; then exit 1; fi
if haqqd init ${MONIKER} --chain-id ${CHAINID} --home /root/.haqqd/; then
# Define variables
GENESIS_URL="https://raw.githubusercontent.com/haqq-network/${CHAINNAME}/master/genesis.json"
ADDRESSBOOK_URL="https://raw.githubusercontent.com/haqq-network/${CHAINNAME}/master/addrbook.json"
# Download config files
curl -sL "$GENESIS_URL" -o "$CONFIG_DIR/genesis.json"
curl -sL "$ADDRESSBOOK_URL" -o "$CONFIG_DIR/addressbook.json"
# somehow it's better to make home static to /root
sed -i 's|~/|/root/|g' "$CONFIG_DIR/config.toml"
sed -i 's|~/|/root/|g' "$CONFIG_DIR/app.toml"
else
echo "Already initialized, continuing!" >&2
fi
# apply a port change to the config
sed -i "/^\[p2p\]/,/^\[/{s|^laddr = .*|laddr = \"$P2P_STRING\"|}" "$CONFIG_DIR/config.toml"
#sed -i "s/^laddr = \".*\"/laddr = \"$P2P_STRING\"/" "$CONFIG_DIR/config.toml"
sed -i "/^\[p2p\]/,/^\[/{s|^external_address = .*|external_address = \"$NAT_STRING\"|}" "$CONFIG_DIR/config.toml"
#sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.01hqq"/g' $CONFIG_DIR/app.toml
sed -i -e "s/^pruning *=.*/pruning = \"custom\"/" $CONFIG_DIR/app.toml
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $CONFIG_DIR/app.toml
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"19\"/" $CONFIG_DIR/app.toml
sed -i -e "s/^indexer *=.*/indexer = \"null\"/" $CONFIG_DIR/config.toml
sed -i "/^\[json-rpc\]/,/^\[/{s|^address = .*|address = \"tcp://0.0.0.0:8545\"|}" "$CONFIG_DIR/app.toml"
sed -i "/^\[json-rpc\]/,/^\[/{s|^ws-address = .*|ws-address = \"tcp://0.0.0.0:8546\"|}" "$CONFIG_DIR/app.toml"
sed -i "/^\[json-rpc\]/,/^\[/{s|^metrics-address = .*|metrics-address = \"tcp://0.0.0.0:6065\"|}" "$CONFIG_DIR/app.toml"
# Update moniker if set
if [ -n "$MONIKER" ] && [ -f "$CONFIG_DIR/config.toml" ]; then
sed -i "s/^moniker = \".*\"/moniker = \"$MONIKER\"/" "$CONFIG_DIR/config.toml"
fi
exec haqqd start --chain-id ${CHAINID} $@