-
Notifications
You must be signed in to change notification settings - Fork 0
/
crly
executable file
·277 lines (257 loc) · 9.85 KB
/
crly
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/bash
set -euo pipefail
CONFIG_DIR="${CONFIG_DIR:-$HOME/relayer-docker-config}"
RELAYER_IMAGE_NAME="iconcommunity/centralized-relay"
RELAYER_REPO_NAME="icon-project/centralized-relay"
DASHBOARD_IMAGE_NAME="iconcommunity/relayer-admin-dashboard"
DASHBOARD_REPO_NAME="icon-project/relayer-admin-dashboard"
COSIGN_VERSION="v2.4.1"
find_docker_compose() {
if command -v docker-compose &>/dev/null; then
echo "docker-compose"
elif docker compose version &>/dev/null; then
echo "docker compose"
else
echo "Error: docker-compose or docker compose command not found."
exit 1
fi
}
DOCKER_COMPOSE_COMMAND=$(find_docker_compose)
# Function to verify a container image using cosign
verify_container() {
local IMAGE_NAME="$1"
local VERSION="$2"
local REPO_NAME="$3"
if [ -z "$VERSION" ]; then
VERSION="stable"
fi
local PUBLIC_KEY_URL="https://github.com/${REPO_NAME}/releases/download/${VERSION}/cosign.pub"
echo "Verifying container image: ${IMAGE_NAME}:${VERSION}"
docker run --rm \
ghcr.io/sigstore/cosign/cosign:${COSIGN_VERSION} verify \
--key "${PUBLIC_KEY_URL}" \
"${IMAGE_NAME}:${VERSION}"
if [ $? -eq 0 ]; then
echo "Verification successful for ${IMAGE_NAME}:${VERSION}"
else
echo "Verification failed for ${IMAGE_NAME}:${VERSION}"
exit 1
fi
}
show_help() {
echo "Usage: crly [COMMAND] [OPTIONS]
Commands:
start [service] [version] Start all services or a specific service with optional version
stop [service] Stop all services or a specific service
restart [service] Restart all services or a specific service
upgrade [version] Verify and pull latest images for all services
update [component] Update specified component (compose-config, script, or [service])
logs [service] Show logs for all services or a specific service
verify [service] [version] Verify container images for all services or a specific service
--help, -h Show this help message
Arguments:
[service] Optional service name (relayer or dashboard)
[component] Component to update (compose-config, script, relayer, dashboard)
[version] Optional version tag (defaults to 'stable' if not provided)
Examples:
crly start Start all services
crly start relayer v1.2.3 Start relayer service with version v1.2.3
crly verify dashboard Verify dashboard image using 'stable' version
crly verify relayer v1.2.3 Verify relayer image with version v1.2.3
crly upgrade Upgrade all services to 'stable' version
crly upgrade v1.2.3 Upgrade all services to version v1.2.3
"
}
cd "${CONFIG_DIR}" || exit 1
COMMAND="$1"
shift
if [[ "$COMMAND" == "--help" ]] || [[ "$COMMAND" == "-h" ]]; then
show_help
exit 0
fi
case "$COMMAND" in
verify)
SERVICE="$1"
VERSION="$2"
if [ -n "$SERVICE" ]; then
echo "Verifying image for service '$SERVICE'..."
case "$SERVICE" in
relayer)
IMAGE_NAME="${RELAYER_IMAGE_NAME}"
REPO_NAME="${RELAYER_REPO_NAME}"
;;
dashboard)
IMAGE_NAME="${DASHBOARD_IMAGE_NAME}"
REPO_NAME="${DASHBOARD_REPO_NAME}"
;;
*)
echo "Unknown service: $SERVICE"
exit 1
;;
esac
verify_container "${IMAGE_NAME}" "${VERSION}" "${REPO_NAME}"
else
echo "Verifying images for all services..."
VERSION="$1"
verify_container "${RELAYER_IMAGE_NAME}" "${VERSION}" "${RELAYER_REPO_NAME}"
verify_container "${DASHBOARD_IMAGE_NAME}" "${VERSION}" "${DASHBOARD_REPO_NAME}"
fi
;;
upgrade)
SERVICE="$1"
VERSION="$2"
if [ -z "$VERSION" ]; then
VERSION="stable"
fi
if [ -n "$SERVICE" ]; then
echo "Verifying and pulling latest image for service '$SERVICE'..."
case "$SERVICE" in
relayer)
IMAGE_NAME="${RELAYER_IMAGE_NAME}"
REPO_NAME="${RELAYER_REPO_NAME}"
;;
dashboard)
IMAGE_NAME="${DASHBOARD_IMAGE_NAME}"
REPO_NAME="${DASHBOARD_REPO_NAME}"
;;
*)
echo "Unknown service: $SERVICE"
exit 1
;;
esac
verify_container "${IMAGE_NAME}" "${VERSION}" "${REPO_NAME}"
${DOCKER_COMPOSE_COMMAND} pull "$SERVICE"
${DOCKER_COMPOSE_COMMAND} up -d "$SERVICE"
else
echo "Verifying and pulling latest images for all services..."
verify_container "${RELAYER_IMAGE_NAME}" "${VERSION}" "${RELAYER_REPO_NAME}"
verify_container "${DASHBOARD_IMAGE_NAME}" "${VERSION}" "${DASHBOARD_REPO_NAME}"
${DOCKER_COMPOSE_COMMAND} pull
${DOCKER_COMPOSE_COMMAND} up -d
fi
;;
start)
SERVICE="$1"
VERSION="$2"
if [ -n "$SERVICE" ]; then
echo "Verifying and starting service '$SERVICE'..."
case "$SERVICE" in
relayer)
IMAGE_NAME="${RELAYER_IMAGE_NAME}"
REPO_NAME="${RELAYER_REPO_NAME}"
;;
dashboard)
IMAGE_NAME="${DASHBOARD_IMAGE_NAME}"
REPO_NAME="${DASHBOARD_REPO_NAME}"
;;
*)
echo "Unknown service: $SERVICE"
exit 1
;;
esac
verify_container "${IMAGE_NAME}" "${VERSION}" "${REPO_NAME}"
${DOCKER_COMPOSE_COMMAND} up -d "$SERVICE"
else
echo "Verifying and starting all services..."
VERSION="$1"
verify_container "${RELAYER_IMAGE_NAME}" "${VERSION}" "${RELAYER_REPO_NAME}"
verify_container "${DASHBOARD_IMAGE_NAME}" "${VERSION}" "${DASHBOARD_REPO_NAME}"
${DOCKER_COMPOSE_COMMAND} up -d
fi
;;
stop)
SERVICE="$1"
if [ -n "$SERVICE" ]; then
echo "Stopping service '$SERVICE'..."
${DOCKER_COMPOSE_COMMAND} stop "$SERVICE"
else
echo "Stopping all services..."
${DOCKER_COMPOSE_COMMAND} stop
fi
;;
restart)
SERVICE="$1"
if [ -n "$SERVICE" ]; then
echo "Restarting service '$SERVICE'..."
${DOCKER_COMPOSE_COMMAND} restart "$SERVICE"
else
echo "Restarting all services..."
${DOCKER_COMPOSE_COMMAND} restart
fi
;;
update)
SUBCOMMAND="$1"
case "$SUBCOMMAND" in
compose-config)
echo "Updating docker-compose.yaml from the repository..."
REPO_URL="https://raw.githubusercontent.com/icon-project/relayer-docker/main/docker-compose.yaml"
curl -sL "${REPO_URL}" -o "${CONFIG_DIR}/docker-compose.yaml"
echo "docker-compose.yaml has been updated."
;;
script)
echo "Updating crly script from the repository..."
SCRIPT_URL="https://raw.githubusercontent.com/icon-project/relayer-docker/main/crly"
curl -sL "${SCRIPT_URL}" -o "${CONFIG_DIR}/crly.tmp"
if [ -s "${CONFIG_DIR}/crly.tmp" ]; then
mv "${CONFIG_DIR}/crly.tmp" "${CONFIG_DIR}/crly"
chmod +x "${CONFIG_DIR}/crly"
echo "crly script has been updated."
else
echo "Error: Failed to download the crly script."
rm -f "${CONFIG_DIR}/crly.tmp"
fi
;;
*)
SERVICE="$SUBCOMMAND"
VERSION="$2"
echo "Updating service '$SERVICE'..."
case "$SERVICE" in
relayer)
IMAGE_NAME="${RELAYER_IMAGE_NAME}"
REPO_NAME="${RELAYER_REPO_NAME}"
;;
dashboard)
IMAGE_NAME="${DASHBOARD_IMAGE_NAME}"
REPO_NAME="${DASHBOARD_REPO_NAME}"
;;
*)
echo "Unknown service: $SERVICE"
exit 1
;;
esac
verify_container "${IMAGE_NAME}" "${VERSION}" "${REPO_NAME}"
${DOCKER_COMPOSE_COMMAND} pull "$SERVICE"
;;
esac
;;
logs)
SERVICE="$1"
if [ -n "$SERVICE" ]; then
echo "Showing logs for service '$SERVICE'..."
${DOCKER_COMPOSE_COMMAND} logs -f "$SERVICE"
else
echo "Showing logs for all services..."
${DOCKER_COMPOSE_COMMAND} logs -f
fi
;;
cleanup)
echo "Cleaning up unused Docker resources..."
docker system prune -f --volumes --all
;;
*)
CONTAINER_ID=$(${DOCKER_COMPOSE_COMMAND} ps -q relayer)
if [ -z "$CONTAINER_ID" ]; then
echo "Relayer service is not running. Starting it..."
VERSION="$1"
verify_container "${RELAYER_IMAGE_NAME}" "${VERSION}" "${RELAYER_REPO_NAME}"
${DOCKER_COMPOSE_COMMAND} up -d relayer
sleep 5
CONTAINER_ID=$(${DOCKER_COMPOSE_COMMAND} ps -q relayer)
fi
if [ -z "$CONTAINER_ID" ]; then
echo "Error: Unable to start relayer service."
exit 1
fi
docker exec -it "$CONTAINER_ID" crly "$COMMAND" "$@"
;;
esac