Skip to content

Commit 27858c7

Browse files
authored
no sql query for csv
1 parent 7d25bfe commit 27858c7

File tree

5 files changed

+363
-6
lines changed

5 files changed

+363
-6
lines changed

lib/redash/README.md

-6
This file was deleted.

redash/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
> Redash can read CSV files and Excel spreadsheets from any accessible URL.
2+
- No upload from local support
3+
4+
# Deploy
5+
6+
## Docker compose
7+
[sample](https://raw.githubusercontent.com/getredash/setup/refs/heads/master/data/compose.yaml) cannot be used directly
8+
9+
If OS is a linux distro, try [setup.sh](https://github.com/getredash/setup/blob/master/setup.sh)
10+
- It requires `sudo`

redash/query/README.md

Whitespace-only changes.

redash/query/file.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> Both the CSV and Excel query runners use **YAML syntax** to write queries.
2+
- No SQL support
3+
- > To query Excel or CSV files with SQL, you can use the [QRDS](https://redash.io/help/user-guide/querying/query-results-data-source/) in a separate query.

redash/setup.sh

+350
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,350 @@
1+
#!/usr/bin/env sh
2+
3+
# This script sets up dockerized Redash on Debian 12.x, Fedora 38 or later, Ubuntu LTS 20.04 & 22.04, and RHEL (and compatible) 8.x & 9.x
4+
set -eu
5+
6+
REDASH_BASE_PATH=/opt/redash
7+
DONT_START=no
8+
OVERWRITE=no
9+
PREVIEW=no
10+
11+
# Ensure the script is being run as root
12+
ID=$(id -u)
13+
if [ "0$ID" -ne 0 ]
14+
then echo "Please run this script as root"
15+
exit
16+
fi
17+
18+
# Ensure the 'docker' and 'docker-compose' commands are available
19+
# and if not, ensure the script can install them
20+
SKIP_DOCKER_INSTALL=no
21+
if [ -x "$(command -v docker)" ]; then
22+
# The first condition is 'docker-compose (v1)' and the second is 'docker compose (v2)'.
23+
if [ -x "$(command -v docker-compose)" ] || (docker compose 1> /dev/null 2>& 1 && [ $? -eq 0 ]); then
24+
SKIP_DOCKER_INSTALL=yes
25+
fi
26+
elif [ ! -f /etc/os-release ]; then
27+
echo "Unknown Linux distribution. This script presently works only on Debian, Fedora, Ubuntu, and RHEL (and compatible)"
28+
exit
29+
fi
30+
31+
# Parse any user provided parameters
32+
opts="$(getopt -o doph -l dont-start,overwrite,preview,help --name "$0" -- "$@")"
33+
eval set -- "$opts"
34+
35+
while true
36+
do
37+
case "$1" in
38+
-d|--dont-start)
39+
DONT_START=yes
40+
shift
41+
;;
42+
-o|--overwrite)
43+
OVERWRITE=yes
44+
shift
45+
;;
46+
-p|--preview)
47+
PREVIEW=yes
48+
shift
49+
;;
50+
-h|--help)
51+
echo "Redash setup script usage: $0 [-d|--dont-start] [-p|--preview] [-o|--overwrite]"
52+
echo " The --preview (also -p) option uses the Redash 'preview' Docker image instead of the last stable release"
53+
echo " The --overwrite (also -o) option replaces any existing configuration with a fresh new install"
54+
echo " The --dont-start (also -d) option installs Redash, but doesn't automatically start it afterwards"
55+
exit 1
56+
;;
57+
--)
58+
shift
59+
break
60+
;;
61+
*)
62+
echo "Unknown option: $1" >&2
63+
exit 1
64+
;;
65+
esac
66+
done
67+
68+
install_docker_debian() {
69+
echo "** Installing Docker (Debian) **"
70+
71+
export DEBIAN_FRONTEND=noninteractive
72+
apt-get -qqy update
73+
DEBIAN_FRONTEND=noninteractive apt-get -qqy -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
74+
apt-get -yy install apt-transport-https ca-certificates curl software-properties-common pwgen gnupg
75+
76+
# Add Docker GPG signing key
77+
if [ ! -f "/etc/apt/keyrings/docker.gpg" ]; then
78+
install -m 0755 -d /etc/apt/keyrings
79+
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
80+
chmod a+r /etc/apt/keyrings/docker.gpg
81+
fi
82+
83+
# Add Docker download repository to apt
84+
cat <<EOF >/etc/apt/sources.list.d/docker.list
85+
deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable
86+
EOF
87+
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
88+
}
89+
90+
install_docker_fedora() {
91+
echo "** Installing Docker (Fedora) **"
92+
93+
# Add Docker package repository
94+
dnf -qy install dnf-plugins-core
95+
dnf config-manager --quiet --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
96+
97+
# Install Docker
98+
dnf install -qy docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin pwgen
99+
100+
# Start Docker and enable it for automatic start at boot
101+
systemctl start docker && systemctl enable docker
102+
}
103+
104+
install_docker_rhel() {
105+
echo "** Installing Docker (RHEL and compatible) **"
106+
107+
# Add EPEL package repository
108+
if [ "x$DISTRO" = "xrhel" ]; then
109+
# Genuine RHEL doesn't have the epel-release package in its repos
110+
RHEL_VER=$(. /etc/os-release && echo "$VERSION_ID" | cut -d "." -f1)
111+
if [ "0$RHEL_VER" -eq "9" ]; then
112+
yum install -qy https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
113+
else
114+
yum install -qy https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
115+
fi
116+
yum install -qy yum-utils
117+
else
118+
# RHEL compatible distros do have epel-release available
119+
yum install -qy epel-release yum-utils
120+
fi
121+
yum update -qy
122+
123+
# Add Docker package repository
124+
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
125+
yum update -qy
126+
127+
# Install Docker
128+
yum install -qy docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin pwgen
129+
130+
# Start Docker and enable it for automatic start at boot
131+
systemctl start docker && systemctl enable docker
132+
}
133+
134+
install_docker_ubuntu() {
135+
echo "** Installing Docker (Ubuntu) **"
136+
137+
export DEBIAN_FRONTEND=noninteractive
138+
apt-get -qqy update
139+
DEBIAN_FRONTEND=noninteractive sudo -E apt-get -qqy -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
140+
apt-get -yy install apt-transport-https ca-certificates curl software-properties-common pwgen gnupg
141+
142+
# Add Docker GPG signing key
143+
if [ ! -f "/etc/apt/keyrings/docker.gpg" ]; then
144+
install -m 0755 -d /etc/apt/keyrings
145+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
146+
chmod a+r /etc/apt/keyrings/docker.gpg
147+
fi
148+
149+
# Add Docker download repository to apt
150+
cat <<EOF >/etc/apt/sources.list.d/docker.list
151+
deb [arch=""$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable
152+
EOF
153+
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
154+
}
155+
156+
create_directories() {
157+
echo "** Creating $REDASH_BASE_PATH directory structure for Redash **"
158+
159+
if [ ! -e "$REDASH_BASE_PATH" ]; then
160+
mkdir -p "$REDASH_BASE_PATH"
161+
chown "$USER:" "$REDASH_BASE_PATH"
162+
fi
163+
164+
if [ -e "$REDASH_BASE_PATH"/postgres-data ]; then
165+
# PostgreSQL database directory seems to exist already
166+
167+
if [ "x$OVERWRITE" = "xyes" ]; then
168+
# We've been asked to overwrite the existing database
169+
echo "Shutting down any running Redash instance"
170+
if [ -e "$REDASH_BASE_PATH"/compose.yaml ]; then
171+
docker compose -f "$REDASH_BASE_PATH"/compose.yaml down
172+
fi
173+
174+
echo "Moving old Redash PG database directory out of the way"
175+
mv "${REDASH_BASE_PATH}/postgres-data" "${REDASH_BASE_PATH}/postgres-data-${TIMESTAMP_NOW}"
176+
mkdir "$REDASH_BASE_PATH"/postgres-data
177+
fi
178+
else
179+
mkdir "$REDASH_BASE_PATH"/postgres-data
180+
fi
181+
}
182+
183+
create_env() {
184+
echo "** Creating Redash environment file **"
185+
186+
# Minimum mandatory values (when not just developing)
187+
COOKIE_SECRET=$(pwgen -1s 32)
188+
SECRET_KEY=$(pwgen -1s 32)
189+
PG_PASSWORD=$(pwgen -1s 32)
190+
DATABASE_URL="postgresql://postgres:${PG_PASSWORD}@postgres/postgres"
191+
192+
if [ -e "$REDASH_BASE_PATH"/env ]; then
193+
# There's already an environment file
194+
195+
if [ "x$OVERWRITE" = "xno" ]; then
196+
echo
197+
echo "Environment file already exists, reusing that one + and adding any missing (mandatory) values"
198+
199+
# Add any missing mandatory values
200+
REDASH_COOKIE_SECRET=
201+
REDASH_COOKIE_SECRET=$(. "$REDASH_BASE_PATH"/env && echo "$REDASH_COOKIE_SECRET")
202+
if [ -z "$REDASH_COOKIE_SECRET" ]; then
203+
echo "REDASH_COOKIE_SECRET=$COOKIE_SECRET" >> "$REDASH_BASE_PATH"/env
204+
echo "REDASH_COOKIE_SECRET added to env file"
205+
fi
206+
207+
REDASH_SECRET_KEY=
208+
REDASH_SECRET_KEY=$(. "$REDASH_BASE_PATH"/env && echo "$REDASH_SECRET_KEY")
209+
if [ -z "$REDASH_SECRET_KEY" ]; then
210+
echo "REDASH_SECRET_KEY=$SECRET_KEY" >> "$REDASH_BASE_PATH"/env
211+
echo "REDASH_SECRET_KEY added to env file"
212+
fi
213+
214+
POSTGRES_PASSWORD=
215+
POSTGRES_PASSWORD=$(. "$REDASH_BASE_PATH"/env && echo "$POSTGRES_PASSWORD")
216+
if [ -z "$POSTGRES_PASSWORD" ]; then
217+
POSTGRES_PASSWORD=$PG_PASSWORD
218+
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> "$REDASH_BASE_PATH"/env
219+
echo "POSTGRES_PASSWORD added to env file"
220+
fi
221+
222+
REDASH_DATABASE_URL=
223+
REDASH_DATABASE_URL=$(. "$REDASH_BASE_PATH"/env && echo "$REDASH_DATABASE_URL")
224+
if [ -z "$REDASH_DATABASE_URL" ]; then
225+
echo "REDASH_DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@postgres/postgres" >> "$REDASH_BASE_PATH"/env
226+
echo "REDASH_DATABASE_URL added to env file"
227+
fi
228+
229+
echo
230+
return
231+
fi
232+
233+
# Move any existing environment file out of the way
234+
mv -f "${REDASH_BASE_PATH}/env" "${REDASH_BASE_PATH}/env.old-${TIMESTAMP_NOW}"
235+
fi
236+
237+
echo "Generating brand new environment file"
238+
239+
cat <<EOF >"$REDASH_BASE_PATH"/env
240+
PYTHONUNBUFFERED=0
241+
REDASH_LOG_LEVEL=INFO
242+
REDASH_REDIS_URL=redis://redis:6379/0
243+
REDASH_COOKIE_SECRET=$COOKIE_SECRET
244+
REDASH_SECRET_KEY=$SECRET_KEY
245+
POSTGRES_PASSWORD=$PG_PASSWORD
246+
REDASH_DATABASE_URL=$DATABASE_URL
247+
REDASH_ENFORCE_CSRF=true
248+
REDASH_GUNICORN_TIMEOUT=60
249+
EOF
250+
}
251+
252+
setup_compose() {
253+
echo "** Creating Redash Docker compose file **"
254+
255+
cd "$REDASH_BASE_PATH"
256+
GIT_BRANCH="${REDASH_BRANCH:-master}" # Default branch/version to master if not specified in REDASH_BRANCH env var
257+
if [ "x$OVERWRITE" = "xyes" -a -e compose.yaml ]; then
258+
mv -f compose.yaml compose.yaml.old-${TIMESTAMP_NOW}
259+
fi
260+
curl -fsSOL https://raw.githubusercontent.com/getredash/setup/"$GIT_BRANCH"/data/compose.yaml
261+
TAG="10.1.0.b50633"
262+
if [ "x$PREVIEW" = "xyes" ]; then
263+
TAG="preview"
264+
fi
265+
sed -i "s|__TAG__|$TAG|" compose.yaml
266+
export COMPOSE_FILE="$REDASH_BASE_PATH"/compose.yaml
267+
export COMPOSE_PROJECT_NAME=redash
268+
}
269+
270+
create_make_default() {
271+
echo "** Creating redash_make_default.sh script **"
272+
273+
curl -fsSOL https://raw.githubusercontent.com/getredash/setup/"$GIT_BRANCH"/redash_make_default.sh
274+
sed -i "s|__COMPOSE_FILE__|$COMPOSE_FILE|" redash_make_default.sh
275+
sed -i "s|__TARGET_FILE__|$PROFILE|" redash_make_default.sh
276+
chmod +x redash_make_default.sh
277+
}
278+
279+
startup() {
280+
if [ "x$DONT_START" != "xyes" ]; then
281+
echo
282+
echo "*********************"
283+
echo "** Starting Redash **"
284+
echo "*********************"
285+
echo "** Initialising Redash database **"
286+
docker compose run --rm server create_db
287+
288+
echo "** Starting the rest of Redash **"
289+
docker compose up -d
290+
291+
echo
292+
echo "Redash has been installed and is ready for configuring at http://$(hostname -f):5000"
293+
echo
294+
else
295+
echo
296+
echo "*************************************************************"
297+
echo "** As requested, Redash has been installed but NOT started **"
298+
echo "*************************************************************"
299+
echo
300+
fi
301+
}
302+
303+
echo
304+
echo "Redash installation script. :)"
305+
echo
306+
307+
TIMESTAMP_NOW=$(date +'%Y.%m.%d-%H.%M')
308+
309+
# Run the distro specific Docker installation
310+
PROFILE=.profile
311+
if [ "$SKIP_DOCKER_INSTALL" = "yes" ]; then
312+
echo "Docker and Docker Compose are already installed, so skipping that step."
313+
else
314+
DISTRO=$(. /etc/os-release && echo "$ID")
315+
case "$DISTRO" in
316+
debian)
317+
install_docker_debian
318+
;;
319+
fedora)
320+
install_docker_fedora
321+
;;
322+
ubuntu)
323+
install_docker_ubuntu
324+
;;
325+
almalinux|centos|ol|rhel|rocky)
326+
PROFILE=.bashrc
327+
install_docker_rhel
328+
;;
329+
*)
330+
echo "This doesn't seem to be a Debian, Fedora, Ubuntu, nor RHEL (compatible) system, so this script doesn't know how to add Docker to it."
331+
echo
332+
echo "Please contact the Redash project via GitHub and ask about getting support added, or add it yourself and let us know. :)"
333+
echo
334+
exit
335+
;;
336+
esac
337+
fi
338+
339+
# Do the things that aren't distro specific
340+
create_directories
341+
create_env
342+
setup_compose
343+
create_make_default
344+
startup
345+
346+
echo "If you want Redash to be your default Docker Compose project when you login to this server"
347+
echo "in future, then please run $REDASH_BASE_PATH/redash_make_default.sh"
348+
echo
349+
echo "That will set some Docker specific environment variables just for Redash. If you"
350+
echo "already use Docker Compose on this computer for other things, you should probably skip it."

0 commit comments

Comments
 (0)