|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +# Make sure we're at the source of the repo. |
| 6 | +cd "$(dirname "${BASH_SOURCE[0]}")/.." |
| 7 | + |
| 8 | +# Function to check if a command exists |
| 9 | +command_exists() { |
| 10 | + command -v "$1" >/dev/null 2>&1 |
| 11 | +} |
| 12 | + |
| 13 | +docker_compose_plugin_installed() { |
| 14 | + docker compose version >/dev/null 2>&1 |
| 15 | +} |
| 16 | + |
| 17 | +if ! command_exists docker; then |
| 18 | + echo "Error: Docker is not installed. Please install Docker before running this script." |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +if ! docker_compose_plugin_installed; then |
| 23 | + echo "Error: Docker Compose is not installed. Please install Docker Compose before running this script." |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +HOST=$1 |
| 28 | + |
| 29 | +# Check if the host is provided as an argument |
| 30 | +if [ -z "$HOST" ]; then |
| 31 | + echo "Usage: $0 <host> [--remote-image]" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +if [ -n "$2" ]; then |
| 36 | + if [ "$2" != "--remote-image" ]; then |
| 37 | + echo "Usage: $0 <host> [--remote-image]" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + REMOTE_IMAGE="$2" |
| 41 | +fi |
| 42 | + |
| 43 | +# Get the current branch name and replace underscores with dashes |
| 44 | +BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) |
| 45 | +FORMATTED_BRANCH_NAME="${BRANCH_NAME//_/-}" |
| 46 | +GIT_COMMIT=$(git rev-parse --short HEAD) |
| 47 | + |
| 48 | +# Variables |
| 49 | +PORT="19100" |
| 50 | +METRICS_PORT="21100" |
| 51 | +GENESIS_URL="https://storage.googleapis.com/linera-io-dev-public/$FORMATTED_BRANCH_NAME/genesis.json" |
| 52 | +VALIDATOR_CONFIG="docker/validator-config.toml" |
| 53 | +GENESIS_CONFIG="docker/genesis.json" |
| 54 | + |
| 55 | +if [ -z "$REMOTE_IMAGE" ]; then |
| 56 | + echo "Building local image from commit $GIT_COMMIT..." |
| 57 | + docker build --build-arg git_commit="$GIT_COMMIT" -f docker/Dockerfile . -t linera |
| 58 | + export LINERA_IMAGE=linera |
| 59 | +else |
| 60 | + export LINERA_IMAGE="us-docker.pkg.dev/linera-io-dev/linera-public-registry/linera:${BRANCH_NAME}_release" |
| 61 | + echo "Using remote image $LINERA_IMAGE..." |
| 62 | +fi |
| 63 | + |
| 64 | +# Create validator configuration file |
| 65 | +echo "Creating validator configuration..." |
| 66 | +cat > $VALIDATOR_CONFIG <<EOL |
| 67 | +server_config_path = "server.json" |
| 68 | +host = "$HOST" |
| 69 | +port = $PORT |
| 70 | +metrics_port = $METRICS_PORT |
| 71 | +internal_host = "proxy" |
| 72 | +internal_port = 20100 |
| 73 | +[external_protocol] |
| 74 | +Grpc = "ClearText" |
| 75 | +[internal_protocol] |
| 76 | +Grpc = "ClearText" |
| 77 | +
|
| 78 | +[[shards]] |
| 79 | +host = "docker-shard-1" |
| 80 | +port = $PORT |
| 81 | +metrics_port = $METRICS_PORT |
| 82 | +
|
| 83 | +[[shards]] |
| 84 | +host = "docker-shard-2" |
| 85 | +port = $PORT |
| 86 | +metrics_port = $METRICS_PORT |
| 87 | +
|
| 88 | +[[shards]] |
| 89 | +host = "docker-shard-3" |
| 90 | +port = $PORT |
| 91 | +metrics_port = $METRICS_PORT |
| 92 | +
|
| 93 | +[[shards]] |
| 94 | +host = "docker-shard-4" |
| 95 | +port = $PORT |
| 96 | +metrics_port = $METRICS_PORT |
| 97 | +EOL |
| 98 | + |
| 99 | +# Download genesis configuration |
| 100 | +echo "Downloading genesis configuration..." |
| 101 | +wget -O $GENESIS_CONFIG $GENESIS_URL |
| 102 | + |
| 103 | +cd docker |
| 104 | + |
| 105 | +# Generate validator keys |
| 106 | +echo "Generating validator keys..." |
| 107 | +PUBLIC_KEY=$(docker run --rm -v "$(pwd):/config" -w /config $LINERA_IMAGE /linera-server generate --validators validator-config.toml) |
| 108 | + |
| 109 | +echo "Validator setup completed successfully." |
| 110 | +echo "Starting docker compose..." |
| 111 | + |
| 112 | +docker compose up --wait |
| 113 | + |
| 114 | +echo "Public Key: $PUBLIC_KEY" |
0 commit comments