Skip to content

Commit d7f1d97

Browse files
gustavovalverdeGustavo Valverde
andauthored
refactor: modernize Z3 stack with upstream repos and Zebra health checks (#4)
* refactor: modernize Z3 stack with upstream repos and Zebra health checks Update the Z3 stack to use official upstream repositories and their corresponding Dockerfiles instead of building from personal forks with specific branches. This refactor also implements proper Zebra configuration using its new environment variable system and health check endpoints. Major changes: 1. Use official upstream repositories with default branches - Zebra: ZcashFoundation/zebra (main branch) - Zaino: zingolabs/zaino (dev branch) - Zallet: zcash/wallet (main branch) - Updated Dockerfile paths to match each project's structure 2. Implement Zebra's environment variable configuration system - Use config-rs format: ZEBRA_SECTION__KEY for Zebra configuration - Implement Z3_* prefix for Docker Compose infrastructure variables - Three-tier variable hierarchy to prevent config collisions: * Z3_* for infrastructure (volumes, ports, Docker Compose only) * Shared variables (NETWORK_NAME, etc.) remapped per service * Service-specific (ZEBRA_*, ZAINO_*, ZALLET_*) for app config 3. Leverage Zebra's new health check endpoints - Use /ready endpoint for production (synced near network tip) - Use /healthy endpoint for development (has peer connections) - Implement two-phase deployment pattern for blockchain sync - Configure healthcheck with 90s start_period for cached state 4. Improve security and documentation - Add fix-permissions.sh for proper UID/GID ownership setup - Document specific UIDs/GIDs for each service - Add warnings about unstable development branches - Update deployment documentation for fresh sync scenarios 5. Remove hardcoded paths and configurations - Eliminate user-specific paths from docker-compose.yml - Use environment variables for all customizable settings - Add docker-compose.override.yml.example for development mode * fix(compose): workaround through zallet limitations * fix(zallet): Use Zebra as the indexer, and update docs * chore: reduce logging * docs: update README.md --------- Co-authored-by: Gustavo Valverde <gustavovalverde@unknowncad5ab0a9f79.lan>
1 parent db63c82 commit d7f1d97

12 files changed

Lines changed: 829 additions & 182 deletions

‎.env‎

Lines changed: 97 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,104 @@
22

33
# z3/docker-compose.yml Environment Variables
44

5-
# --- Common Configuration ---
6-
# Network name for all services (e.g., Mainnet, Testnet, Regtest). Referenced by Zebra, Zaino, and Zallet.
7-
NETWORK_NAME=Testnet
8-
# Globally enables RPC cookie authentication. If true, Zebra generates a .cookie file.
9-
# Zaino's use of this cookie (via ZAINO_VALIDATOR_COOKIE_AUTH_ENABLE in compose) is conditional on its ZAINO_VALIDATOR_LISTEN_ADDRESS.
5+
# =============================================================================
6+
# VARIABLE HIERARCHY QUICK REFERENCE
7+
# =============================================================================
8+
# For detailed explanation, see README.md "Understanding the Variable Hierarchy"
9+
#
10+
# Three-tier system to avoid collisions:
11+
# Z3_* - Infrastructure (volumes, ports) - Docker Compose only
12+
# (no prefix) - Shared config (remapped per service)
13+
# ZEBRA_* - Zebra app config (ZEBRA_SECTION__KEY format)
14+
# ZAINO_* - Zaino app config
15+
# ZALLET_* - Zallet app config
16+
#
17+
# =============================================================================
18+
# Z3 Stack Infrastructure Configuration
19+
# =============================================================================
20+
# These Z3_* variables control Docker Compose volume mounts and are NEVER
21+
# passed to containers. They avoid collision with service configs (ZEBRA_*,
22+
# ZAINO_*, ZALLET_*).
23+
#
24+
# Default: Docker named volumes (recommended - managed by Docker, no permission issues)
25+
# Advanced: Local directories (see README.md "Advanced: Local Directories" section)
26+
#
27+
# To use local directories:
28+
# 1. Choose appropriate paths for your OS (see README for suggestions)
29+
# 2. Create directories: mkdir -p /your/chosen/path
30+
# 3. Fix permissions: ./fix-permissions.sh <service> /your/chosen/path
31+
# 4. Update variables below with your paths
32+
#
33+
# Security Requirements:
34+
# - Zebra: UID=10001, GID=10001, permissions=700
35+
# - Zaino: UID=1000, GID=1000, permissions=700
36+
# - Zallet: UID=65532, GID=65532, permissions=700
37+
# - Cookie: Keep as Docker volume (recommended) to avoid cross-user issues
38+
#
39+
# WARNING: Never use 755 or 777 permissions - they expose your data!
40+
41+
# Zebra blockchain state directory
42+
# Default: zebra_data (Docker named volume)
43+
Z3_ZEBRA_DATA_PATH=zebra_data
44+
45+
# Shared cookie authentication directory (used by Zebra and Zaino)
46+
# Default: shared_cookie_volume (Docker named volume)
47+
# NOTE: For local directories, Zebra (10001) writes and Zaino (1000) reads.
48+
# Consider using Docker volume (default) to avoid cross-user permission issues.
49+
# If using local dir, you'll need to set up ACLs or a shared group.
50+
Z3_COOKIE_PATH=shared_cookie_volume
51+
52+
# Zaino indexer data directory
53+
# Default: zaino_data (Docker named volume)
54+
Z3_ZAINO_DATA_PATH=zaino_data
55+
56+
# Zallet wallet data directory
57+
# Default: zallet_data (Docker named volume)
58+
Z3_ZALLET_DATA_PATH=zallet_data
59+
60+
# =============================================================================
61+
# Common Configuration
62+
# =============================================================================
63+
# Shared variables used by multiple services, mapped in docker-compose.yml:
64+
# NETWORK_NAME → ZEBRA_NETWORK__NETWORK, ZAINO_NETWORK, ZALLET_NETWORK
65+
# ENABLE_COOKIE_AUTH → ZEBRA_RPC__ENABLE_COOKIE_AUTH, ZAINO_VALIDATOR_COOKIE_AUTH
66+
# COOKIE_AUTH_FILE_DIR → ZEBRA_RPC__COOKIE_DIR, ZAINO_VALIDATOR_COOKIE_PATH
67+
68+
# Network name for all services (e.g., Mainnet, Testnet, Regtest)
69+
NETWORK_NAME=Mainnet
70+
# Globally enables RPC cookie authentication
1071
ENABLE_COOKIE_AUTH=true
11-
# In-container directory for the .cookie authentication file (e.g., /var/run/auth).
12-
# Zebra writes its cookie here; Zaino reads from this location via its ZAINO_VALIDATOR_COOKIE_PATH in compose.
72+
# In-container directory for the .cookie authentication file
1373
COOKIE_AUTH_FILE_DIR=/var/run/auth
1474

15-
# --- Zebra Configuration ---
16-
# Zebra Rust log level
17-
ZEBRA_RUST_LOG=info
18-
# Zebra's internal RPC port. Zaino connects to this port on the 'zebra' service hostname.
19-
ZEBRA_RPC_PORT=18232
20-
# Zebra host RPC port (for external access to Zebra)
21-
ZEBRA_HOST_RPC_PORT=18232
75+
# =============================================================================
76+
# Zebra Configuration
77+
# =============================================================================
78+
# Zebra logging (will be mapped to RUST_LOG in container)
79+
Z3_ZEBRA_RUST_LOG=info
80+
# Zebra tracing filter (config-rs format: ZEBRA_TRACING__FILTER)
81+
ZEBRA_TRACING__FILTER=info
82+
# Zebra RPC listen address (config-rs format: ZEBRA_RPC__LISTEN_ADDR)
83+
ZEBRA_RPC__LISTEN_ADDR=0.0.0.0:18232
84+
# Zebra state cache directory (config-rs format: ZEBRA_STATE__CACHE_DIR)
85+
ZEBRA_STATE__CACHE_DIR=/home/zebra/.cache/zebra
86+
# Zebra health endpoint configuration
87+
ZEBRA_HEALTH__LISTEN_ADDR=0.0.0.0:8080
88+
ZEBRA_HEALTH__MIN_CONNECTED_PEERS=1
89+
ZEBRA_HEALTH__READY_MAX_BLOCKS_BEHIND=2
90+
ZEBRA_HEALTH__ENFORCE_ON_TEST_NETWORKS=false
91+
# Infrastructure: Zebra RPC port (used in Docker Compose port mappings and service discovery)
92+
Z3_ZEBRA_RPC_PORT=18232
93+
# Infrastructure: Zebra host RPC port (for external access to Zebra)
94+
Z3_ZEBRA_HOST_RPC_PORT=18232
95+
# Infrastructure: Zebra host health port (for external access to health endpoints)
96+
Z3_ZEBRA_HOST_HEALTH_PORT=8080
2297

23-
# --- Zaino Configuration ---
98+
# =============================================================================
99+
# Zaino Configuration
100+
# =============================================================================
24101
# Zaino Rust log level
25-
ZAINO_RUST_LOG=trace,hyper=info
102+
ZAINO_RUST_LOG=info,reqwest=warn,hyper_util=warn
26103
# Zaino's internal gRPC port. Zallet connects to this port on the 'zaino' service hostname.
27104
ZAINO_GRPC_PORT=8137
28105
# Enable/disable Zaino's JSON-RPC service
@@ -53,9 +130,11 @@ ZAINO_CONF_PATH=/home/zaino/.config/zaino/zindexer.toml
53130
# Zaino application internal data directory
54131
ZAINO_DATA_DIR=/home/zaino/.cache/zaino
55132

56-
# --- Zallet Configuration ---
133+
# =============================================================================
134+
# Zallet Configuration
135+
# =============================================================================
57136
# Zallet Rust log level
58-
ZALLET_RUST_LOG=debug
137+
ZALLET_RUST_LOG=info,hyper_util=warn,reqwest=warn
59138
# Zallet internal RPC port
60139
ZALLET_RPC_PORT=28232
61140
# Zallet host RPC port (for external access to Zallet RPC)

‎.github/workflows/build-z3-images.yaml‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ on:
2323
- '.github/workflows/build-z3-images.yaml'
2424

2525
jobs:
26+
build-zebra:
27+
name: Build zebra Docker
28+
permissions:
29+
contents: 'read'
30+
id-token: 'write'
31+
packages: 'write'
32+
uses: ./.github/workflows/sub-build-docker-image.yaml
33+
with:
34+
repository: ZcashFoundation/zebra
35+
ref: 'main'
36+
dockerfile_path: ./docker/Dockerfile
37+
dockerfile_target: runtime
38+
image_name: zebra
39+
no_cache: ${{ inputs.no_cache || false }}
40+
rust_backtrace: full
41+
rust_lib_backtrace: full
42+
rust_log: info
43+
2644
build-zaino:
2745
name: Build zaino Docker
2846
permissions:
@@ -31,9 +49,9 @@ jobs:
3149
packages: 'write'
3250
uses: ./.github/workflows/sub-build-docker-image.yaml
3351
with:
34-
repository: gustavovalverde/zaino
35-
ref: 'imp-dockerfile'
36-
dockerfile_path: ./docker/Dockerfile
52+
repository: zingolabs/zaino
53+
ref: 'dev'
54+
dockerfile_path: ./Dockerfile
3755
dockerfile_target: runtime
3856
image_name: zaino
3957
no_cache: ${{ inputs.no_cache || false }}
@@ -49,9 +67,9 @@ jobs:
4967
packages: 'write'
5068
uses: ./.github/workflows/sub-build-docker-image.yaml
5169
with:
52-
repository: gustavovalverde/wallet
53-
ref: 'feat-add-docker'
54-
dockerfile_path: ./docker/Dockerfile
70+
repository: zcash/wallet
71+
ref: 'main'
72+
dockerfile_path: ./Dockerfile
5573
dockerfile_target: runtime
5674
image_name: zallet
5775
no_cache: ${{ inputs.no_cache || false }}

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ target/
1818

1919
# Ignore all contents of the 'config' directory recursively
2020
config/**
21+
!config/zallet.toml
2122

2223
# Un-ignore the 'tls' subdirectory itself, so we can look inside it
2324
!config/tls/

‎Dockerfile.zebra‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)