-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautomated_deploy.sh
More file actions
198 lines (176 loc) · 5.56 KB
/
automated_deploy.sh
File metadata and controls
198 lines (176 loc) · 5.56 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
# Deployer information
DEPLOYER_NAME="Node-Automated-Deployer"
DEPLOYER_VERSION="v0.6.2"
DEPLOYER_RELEASE_URL="https://github.com/RSS3-Network/$DEPLOYER_NAME/releases"
# The version of RSS3 Node to deploy
NODE_VERSION="v2.0.0"
# Detect the operating system
OS=$(uname -s)
ARCH=$(uname -m)
# Function to check if Docker is installed and running
check_docker() {
if ! command -v docker &> /dev/null; then
echo "❌ Docker is not installed. Please install Docker: https://docs.docker.com/engine/install/ and rerun this script."
exit 1
fi
if ! docker ps &> /dev/null; then
echo "❌ Docker is not running. Please start Docker and rerun this script."
exit 1
fi
}
check_docker
# Function to check if Docker Compose is installed
check_docker_compose() {
if command -v docker-compose &> /dev/null; then
COMPOSE_CMD="docker-compose"
elif command -v docker &> /dev/null && docker compose version &> /dev/null; then
COMPOSE_CMD="docker compose"
else
echo "❌ Docker Compose is not installed. Please install Docker Compose: https://docs.docker.com/compose/install/ and rerun this script."
exit 1
fi
}
check_docker_compose
# Function to install curl if it's not already installed
install_curl() {
if ! command -v curl &> /dev/null; then
echo "❌ curl is not installed. Please install curl and rerun this script."
exit 1
fi
}
# Install curl if not installed
install_curl
# Determine the correct file name based on OS and architecture
case $OS in
Darwin)
case $ARCH in
arm64)
FILE="${DEPLOYER_NAME}_Darwin_arm64.tar.gz"
;;
x86_64)
FILE="${DEPLOYER_NAME}_Darwin_x86_64.tar.gz"
;;
*)
echo "❌ Unsupported architecture: $ARCH"
exit 1
;;
esac
;;
Linux)
case $ARCH in
arm64)
FILE="${DEPLOYER_NAME}_Linux_arm64.tar.gz"
;;
i386)
FILE="${DEPLOYER_NAME}_Linux_i386.tar.gz"
;;
x86_64)
FILE="${DEPLOYER_NAME}_Linux_x86_64.tar.gz"
;;
*)
echo "❌ Unsupported architecture: $ARCH"
exit 1
;;
esac
;;
MINGW*|MSYS*|CYGWIN*)
case $ARCH in
arm64)
FILE="${DEPLOYER_NAME}_Windows_arm64.zip"
;;
i386)
FILE="${DEPLOYER_NAME}_Windows_i386.zip"
;;
x86_64)
FILE="${DEPLOYER_NAME}_Windows_x86_64.zip"
;;
*)
echo "❌ Unsupported architecture: $ARCH"
exit 1
;;
esac
;;
*)
echo "❌ Unsupported operating system: $OS"
exit 1
;;
esac
# URL for the download
URL="$DEPLOYER_RELEASE_URL/download/$DEPLOYER_VERSION/$FILE"
echo "⬇️ Downloading $URL..."
# Download the file
curl -L $URL -o $FILE
# Check if the download was successful
if [ $? -eq 0 ]; then
echo "📦 Download successful, extracting the file..."
# Extract the file
case $FILE in
*.tar.gz)
tar -xzf $FILE
;;
*.zip)
unzip $FILE
;;
*)
echo "❌ Unsupported file format: $FILE"
exit 1
;;
esac
# Check if the extraction was successful
if [ $? -eq 0 ]; then
echo "✅ Extraction successful."
else
echo "❌ Extraction failed."
exit 1
fi
else
echo "❌ Download failed."
exit 1
fi
# Get the directory of the script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Check if config.yaml exists in the script's directory or in the config folder
if [ -f "$SCRIPT_DIR/config/config.yaml" ]; then
echo "⚙️ config.yaml found in the config folder. use existing config file."
elif [ -f "$SCRIPT_DIR/config.yaml" ]; then
echo "⚙️ config.yaml found in the script's directory, moving it to config folder..."
mkdir -p "$SCRIPT_DIR/config"
mv "$SCRIPT_DIR/config.yaml" "$SCRIPT_DIR/config/config.yaml"
echo "⚠️ DO NOT DELETE/MOVE THE config FOLDER OR ITS CONTENTS!"
else
echo "⚠️ config.yaml not found, please create a config.yaml file or generate one at https://explorer.rss3.io."
exit 1
fi
# Check for existing services
if $COMPOSE_CMD ps | grep -q "Up"; then
echo "🔄 Existing node services detected. This is an upgrade process."
echo "⏬ Stopping existing services..."
$COMPOSE_CMD down
if [ $? -ne 0 ]; then
echo "❌ Failed to stop existing services."
exit 1
fi
echo "✅ Existing services stopped successfully."
else
echo "🆕 No existing services detected. This is a new node deployment."
fi
export NODE_VERSION
echo "🚀 Running the deployer..."
"$SCRIPT_DIR/node-automated-deployer" > "$SCRIPT_DIR/docker-compose.yaml"
# Check if docker-compose.yaml was successfully created
if [ -f "$SCRIPT_DIR/docker-compose.yaml" ]; then
echo "ℹ️ docker-compose.yaml created, starting Docker Compose..."
(cd "$SCRIPT_DIR" && $COMPOSE_CMD up -d)
# Check if Docker Compose started successfully
if [ $? -eq 0 ]; then
echo "✅ Deployment process completed successfully."
echo "🎉 Welcome to the RSS3 Network!"
else
echo "❌ Failed to start Docker Compose."
exit 1
fi
else
echo "❌ Failed to create docker-compose.yaml."
exit 1
fi