-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathget-core.sh
More file actions
executable file
·186 lines (164 loc) · 6.61 KB
/
get-core.sh
File metadata and controls
executable file
·186 lines (164 loc) · 6.61 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
#!/bin/bash
# <h2 style="color:red">Get Firebolt Core with:</h2><code>bash <(curl -s https://get-core.firebolt.io/)</code><br/><br/><br/><pre>
set -e
# Parse command line arguments
AUTO_RUN=false
if [ "$1" = "--auto-run" ]; then
AUTO_RUN=true
elif [ -n "$1" ]; then
echo "Unknown option: $1"
echo "Usage: $0 [--auto-run]" 1>&2
exit 1
fi
banner() {
echo "
🔥🔥🔥 Firebolt Core setup script 🔥🔥🔥
---------: .--- ---------: ---------: ---------: :-====-: --- .---------..
++++++++++ :+++ ++++++++++++: +++++++++- ++++++++++++- ++++++++++++++ ...:=++ -+++++++++++++
++++ :+++ +++- ++++. +++- +++- ++++- :=++++. -++++= :+++ -+++
++++ :+++ +++: +++: +++- +++- .:++= ++++. =++: :++= :+-:
++++:.... :+++ +++- ++++ ++++:.... ++++:...-++++ .+=- =+++ :+++ .=++
+++++++++ :+++ ++++++++++++ +++++++++ ++++++++++++ -+++- - :++++ :+++
++++ :+++ +++=.:+++= +++= +++= .++++: +++= .=+++ :+++ :++=
++++ :+++ +++: =++= +++- +++- -++= =+++= ++++: :+++ :=+++
++++ :+++ +++: ++++ +++= +++= :++++: -+++++: -+++++: -+++. :+++
++++ :+++ +++: =+++ ++++++++++ =+++++++-- -++++++++++++. -++++++++- .-++
.:--:.
"
}
IS_MACOS=0
if [ "$(uname)" = "Darwin" ]; then
IS_MACOS=1
fi
# Docker image to pull - allow specifying overrides via env variables
CORE_REPO="${CORE_REPO:-ghcr.io/firebolt-db/firebolt-core}"
CORE_TAG="${CORE_TAG:-preview-rc}"
DOCKER_IMAGE="${CORE_REPO}:${CORE_TAG}"
EXTERNAL_PORT=3473
DOCKER_RUN_ARGS=(
-i
--name firebolt-core
--rm
--ulimit memlock=8589934592:8589934592
--security-opt seccomp=unconfined
-v "$(pwd)/firebolt-core-data:/firebolt-core/volume"
-p "$EXTERNAL_PORT:3473"
"$DOCKER_IMAGE"
)
ensure_docker_is_installed() {
if docker info >/dev/null 2>&1; then
echo "[🐳] Docker is present and works ✅"
return 0
fi
if [ $IS_MACOS -eq 1 ]; then
echo "[🐳] Docker needs to be installed: https://docs.docker.com/desktop/setup/install/mac-install/ ❌"
else
echo "[🐳] Docker needs to be installed: https://docs.docker.com/desktop/setup/install/linux/ ❌"
fi
return 1
}
check_docker_version() {
# Explicitly inform the user about the known io_uring issue in Docker Desktop for Mac
# See also:
# * https://github.com/firebolt-db/firebolt-core/issues/9
# * https://github.com/docker/for-mac/issues/7707
if [ $IS_MACOS -eq 1 ]; then
version=$(docker version | sed -n 's/.*Docker Desktop \([0-9.]*\).*/\1/p')
if [ "$version" = "4.42.1" ] || [ "$version" = "4.43.0" ] || [ "$version" = "4.43.1" ]; then
echo "[❌] Firebolt Core cannot run with Docker Desktop version ${version} on Mac, as it contains a known io_uring issue; please use version 4.43.2+"
return 1
fi
fi
}
pull_docker_image() {
echo "[🐳] Pulling Firebolt Core Docker image '$DOCKER_IMAGE'"
docker pull --quiet "$DOCKER_IMAGE"
if [ $? -eq 0 ]; then
echo "[🐳] Docker image '$DOCKER_IMAGE' pulled successfully ✅"
else
echo "[🐳] Failed to pull Docker image '$DOCKER_IMAGE' ❌"
return 1
fi
}
DEFAULT_CORE_USER=""
detect_firebolt_user() {
if [ $IS_MACOS -eq 1 ]; then
DEFAULT_CORE_USER=root
else
DEFAULT_CORE_USER="$(docker run --rm --entrypoint /bin/whoami $DOCKER_IMAGE)"
if [ -z "$DEFAULT_CORE_USER" ]; then
echo "[❌] Cannot identify non-root container user."
return 1
fi
fi
# set CORE_USER, unless already set by user
CORE_USER="${CORE_USER:-$DEFAULT_CORE_USER}"
}
wait_for_core_to_be_ready() {
# If curl is not installed, we can't check if Core is ready
if ! command -v curl >/dev/null 2>&1; then
return 0
fi
echo -n "[🔥] Wait for Firebolt Core to be ready"
# Try for ~10 seconds to get a valid response from Core
timeout=10
RESPONSE="Unknown error"
while [ $timeout -gt 0 ]; do
set +e
RESPONSE=$(curl -s 'http://localhost:3473/?output_format=TabSeparatedWithNamesAndTypes' --data-binary "SELECT 42;")
set -e
if [ "$RESPONSE" = $'?column?\nint\n42' ]; then
echo " ✅"
return 0
fi
sleep 1
timeout=$((timeout - 1))
echo -n "."
done
echo " ❌"
echo "[❌] Firebolt Core failed to start. This is unexpected, please submit a bug report on Github https://github.com/firebolt-db/firebolt-core/issues"
echo "[❌] Error: $RESPONSE"
return 1
}
run_docker_image() {
echo "[⚠️] Note: a local 'firebolt-core-data directory' with permissions 0777 will be created."
if [ "$AUTO_RUN" = true ]; then
answer="y"
else
read -p "[🔥] Everything is set up and you are ready to go! Do you want to run the Firebolt Core image? (use --auto-run to skip this prompt) [y/N]: " answer
fi
case "$answer" in
[yY])
if [ $IS_MACOS -eq 0 ]; then
if [ ! -d firebolt-core-data ]; then
mkdir -p -m 777 firebolt-core-data
fi
fi
echo -n "[🔥] Starting the Firebolt Core Docker container"
CID="$(docker run --detach --user $CORE_USER "${DOCKER_RUN_ARGS[@]}")"
trap "docker kill $CID" EXIT
echo " ✅"
wait_for_core_to_be_ready
echo "[🔥] Running Firebolt CLI"
docker exec -ti $CID fb --core
;;
*)
echo "[🔥] Firebolt Core is ready to be executed, you can do this by running the following commands:"
echo
echo "mkdir -m 777 firebolt-core-data"
echo "docker run --user $CORE_USER "${DOCKER_RUN_ARGS[@]}""
echo
echo "And then in another terminal:"
echo
echo "docker exec -ti firebolt-core fb --core"
echo
;;
esac
}
# Main script execution
banner
ensure_docker_is_installed
check_docker_version
pull_docker_image
detect_firebolt_user
run_docker_image