forked from Stellar-Uzima/Uzima-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_all.sh
More file actions
executable file
·86 lines (65 loc) · 2.32 KB
/
Copy pathdeploy_all.sh
File metadata and controls
executable file
·86 lines (65 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# deploy_all.sh - Deploy all enabled contracts for a given environment
# Usage: ./scripts/deploy_all.sh <environment> <network> [identity]
set -euo pipefail
# --- Configuration ---
CONFIG_DIR="config"
DEFAULT_CONFIG="$CONFIG_DIR/default.json"
# --- Colors for output ---
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
# --- Helper functions ---
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
print_step() {
echo -e "${BLUE}[STEP]${NC} $1"
}
# --- Argument validation ---
if [ $# -lt 2 ]; then
print_error "Usage: $0 <environment> <network> [identity]"
print_error "Example: $0 development local"
print_error "Available environments: development, staging, production"
fi
ENVIRONMENT="$1"
NETWORK="$2"
IDENTITY="${3:-"default"}"
ENV_CONFIG="$CONFIG_DIR/$ENVIRONMENT.json"
# --- Pre-flight checks ---
if ! command -v jq &> /dev/null; then
print_error "'jq' is not installed. Please install it to continue."
fi
if [ ! -f "$ENV_CONFIG" ]; then
print_error "Configuration file for environment '$ENVIRONMENT' not found at '$ENV_CONFIG'"
fi
# --- Main script ---
print_status "Starting deployment for environment: $ENVIRONMENT on $NETWORK network"
# Merge configurations
# This uses jq to deeply merge the default and environment-specific configs
CONFIG=$(jq -s '.[0] * .[1]' "$DEFAULT_CONFIG" "$ENV_CONFIG")
# Get a list of all enabled contracts
ENABLED_CONTRACTS=$(echo "$CONFIG" | jq -r '.contracts | to_entries[] | select(.value.enabled == true) | .key')
if [ -z "$ENABLED_CONTRACTS" ]; then
print_status "No contracts are enabled for deployment in the '$ENVIRONMENT' configuration."
exit 0
fi
print_status "Enabled contracts for deployment:
$ENABLED_CONTRACTS"
# Loop and deploy each contract
for CONTRACT_NAME in $ENABLED_CONTRACTS; do
print_step "Deploying contract: $CONTRACT_NAME"
# Construct deployment command
DEPLOY_CMD="./scripts/deploy.sh $CONTRACT_NAME $NETWORK $IDENTITY"
# Execute the deployment script
if ! $DEPLOY_CMD; then
print_error "Deployment of '$CONTRACT_NAME' failed. Aborting."
fi
print_status "Successfully deployed contract: $CONTRACT_NAME"
done
print_status "All enabled contracts deployed successfully for '$ENVIRONMENT' environment. ✅"