-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from 0KnowledgeNetwork/86-feature-docker-node-…
…utils feat(docker/node): sovereign node utils
- Loading branch information
Showing
11 changed files
with
212 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
apps/walletshield/walletshield | ||
docker/node/.env | ||
genconfig/cmd/genconfig/genconfig | ||
pki/pki | ||
server_plugins/cbor_plugins/http_proxy/cmd/http_proxy/http_proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
x-common-service: &common-service | ||
restart: "no" | ||
image: ${IMAGE_NODE} | ||
user: ${DOCKER_USER} | ||
volumes: | ||
- ${VOLUME_MIXNET}:${DIR_BASE} | ||
network_mode: host | ||
|
||
services: | ||
mix-agent: | ||
<<: *common-service | ||
image: ${IMAGE_AGENT} | ||
environment: | ||
- URL_APPCHAIN_INDEXER=${URL_APPCHAIN_INDEXER} | ||
- URL_APPCHAIN_PROCESSOR=${URL_APPCHAIN_PROCESSOR} | ||
- URL_APPCHAIN_SEQUENCER=${URL_APPCHAIN_SEQUENCER} | ||
command: > | ||
pnpm run agent | ||
--ipfs | ||
--ipfs-data ${DIR_BASE}/ipfs | ||
--listen | ||
--key ${DIR_BASE}/${NODE_ID}-auth/appchain.key | ||
--socket ${DIR_BASE}/${NODE_ID}-auth/appchain.sock | ||
--socket-format cbor | ||
--debug | ||
mix-auth: | ||
<<: *common-service | ||
command: ${DIR_BIN}/pki -f ${DIR_BASE}/${NODE_ID}-auth/authority.toml | ||
depends_on: | ||
- mix-agent | ||
|
||
mix: | ||
<<: *common-service | ||
command: ${DIR_BIN}/server -f ${DIR_BASE}/${NODE_ID}/katzenpost.toml | ||
depends_on: | ||
- mix-auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
NODE_ADDRESS=127.0.0.1 | ||
NODE_ID=mix-1000 | ||
NODE_LOG_LEVEL=INFO | ||
NODE_METRICS=0.0.0.0:9100 | ||
NODE_PORT=8888 | ||
NODE_TYPE=mix | ||
VOLUME_MIXNET=/tmp/mix | ||
|
||
DIR_BASE=/mixnet | ||
DIR_BIN=/opt/zkn | ||
IMAGE_AGENT=ghcr.io/0knowledgenetwork/appchain-agent:latest | ||
IMAGE_NODE=ghcr.io/0knowledgenetwork/node:latest | ||
URL_APPCHAIN_INDEXER=http://localhost:8081/graphql | ||
URL_APPCHAIN_SEQUENCER=http://localhost:8080/graphql | ||
URL_APPCHAIN_PROCESSOR=http://localhost:8082/graphql | ||
USE_LOCAL_IMAGES=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
dir_script=$(dirname "$(readlink -f "$0")") | ||
network_id=${1:-_} # default to active network | ||
file_env="${2:-${dir_script}/.env}" # default to .env in this script's directory | ||
|
||
# Load configuration from the .env file in the same directory as the script | ||
[ ! -f "${file_env}" ] && echo "Error: .env file not found: ${file_env}" && exit 1 | ||
echo "Loading environment variables from ${file_env}" | ||
export $(grep -v '^#' "${file_env}" | xargs) | ||
|
||
# Verify that required environment variables are set | ||
for var in \ | ||
DIR_BASE \ | ||
DIR_BIN \ | ||
IMAGE_AGENT \ | ||
IMAGE_NODE \ | ||
NODE_ADDRESS \ | ||
NODE_ID \ | ||
NODE_LOG_LEVEL \ | ||
NODE_METRICS \ | ||
NODE_PORT \ | ||
NODE_TYPE \ | ||
URL_APPCHAIN_INDEXER \ | ||
URL_APPCHAIN_PROCESSOR \ | ||
URL_APPCHAIN_SEQUENCER \ | ||
USE_LOCAL_IMAGES \ | ||
VOLUME_MIXNET \ | ||
; do | ||
: "${!var:?Environment variable ${var} is required}" | ||
done | ||
|
||
# Configuration | ||
file_network="${VOLUME_MIXNET}/network.yml" | ||
|
||
# Determine container tool and related settings | ||
if command -v podman >/dev/null; then | ||
docker="podman" | ||
docker_user=$(if podman info --format '{{.Host.Security.Rootless}}' | grep -iq "true"; then echo "$(id -u):$(id -g)"; else echo "0:0"; fi) | ||
docker_compose_env="DOCKER_USER=${docker_user} DOCKER_HOST=unix://${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/podman/podman.sock" | ||
else | ||
docker="docker" | ||
docker_user="${SUDO_UID:-$(id -u)}:${SUDO_GID:-$(id -g)}" | ||
docker_compose_env="DOCKER_USER=${docker_user}" | ||
fi | ||
docker_compose="${docker_compose_env} docker compose --env-file ${file_env}" | ||
docker_run="${docker} run \ | ||
--env URL_APPCHAIN_INDEXER=${URL_APPCHAIN_INDEXER} \ | ||
--env URL_APPCHAIN_PROCESSOR=${URL_APPCHAIN_PROCESSOR} \ | ||
--env URL_APPCHAIN_SEQUENCER=${URL_APPCHAIN_SEQUENCER} \ | ||
--network=host \ | ||
--rm \ | ||
--user ${docker_user} \ | ||
--volume ${VOLUME_MIXNET}:${DIR_BASE}" | ||
|
||
# Pull required Docker images | ||
[ ${USE_LOCAL_IMAGES} -eq "0" ] && echo -e "\nPulling required Docker images..." && eval ${docker_compose} pull | ||
|
||
# Fetch network info | ||
echo -e "\nFetching active network configuration..." | ||
eval ${docker_run} \ | ||
${IMAGE_AGENT} \ | ||
pnpm run agent \ | ||
--ipfs \ | ||
--ipfs-data ${DIR_BASE}/ipfs \ | ||
networks getNetwork ${network_id} ${DIR_BASE}/network.yml | ||
[ ! -f "${file_network}" ] && echo "Error: Network configuration file not generated." && exit 1 | ||
echo "Network configuration saved to ${file_network}" | ||
|
||
# Generate node configuration | ||
echo -e "\nGenerating node configuration..." | ||
eval ${docker_run} \ | ||
${IMAGE_NODE} \ | ||
${DIR_BIN}/genconfig \ | ||
-input ${DIR_BASE}/network.yml \ | ||
-binary-prefix ${DIR_BIN}/ \ | ||
-dir-base ${DIR_BASE} \ | ||
-dir-out ${DIR_BASE} \ | ||
-address ${NODE_ADDRESS} \ | ||
-identifier ${NODE_ID} \ | ||
-log-level ${NODE_LOG_LEVEL} \ | ||
-metrics ${NODE_METRICS} \ | ||
-port ${NODE_PORT} \ | ||
-type ${NODE_TYPE} | ||
echo "Node configuration generated successfully." | ||
|
||
# Start services | ||
echo -e "\nStarting services..." | ||
eval ${docker_compose} -p ${NODE_ID} up -d | ||
|
||
echo -e "\nNode setup and services started successfully." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters