Skip to content

Commit

Permalink
Add --preview parameter to use Redash preview image instead
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift committed Apr 4, 2024
1 parent 0bf40b9 commit 1299b8f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 24 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,27 @@ and begin using.
## Optional parameters

The setup script has (for now) a single optional parameter, `--overwrite`, used like this:
The setup script has two optional parameters, `--preview` and `--overwrite`.

These can be used independently of each other, or used together.

### --preview

When the `--preview` parameter is given, the setup script will install the latest `preview`
[image from Docker Hub](https://hub.docker.com/r/redash/redash/tags) instead of using the last official release.

```
# ./setup.sh --overwrite
# ./setup.sh --preview
```

When this option is used, the setup script will delete the existing Redash environment file (`/opt/redash/env`) and
Redash database, then set up a brand new (empty) Redash installation.
### --overwrite

When the `--overwrite` option is given, the setup script will delete the existing Redash environment file
(`/opt/redash/env`) and Redash database, then set up a brand new (empty) Redash installation.

```
# ./setup.sh --overwrite
```

> [!CAUTION]
> ***DO NOT*** use this parameter if you want to keep your existing Redash installation! It ***WILL*** be overwritten.
Expand Down
12 changes: 9 additions & 3 deletions data/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
image: redash/redash:__TAG__
depends_on:
- postgres
- redis
Expand All @@ -10,21 +10,27 @@ services:
<<: *redash-service
command: server
ports:
- "5000:5000"
- "__PORT__:5000"
environment:
REDASH_WEB_WORKERS: 4
scheduler:
<<: *redash-service
command: scheduler
depends_on:
- server
scheduled_worker:
<<: *redash-service
command: worker
depends_on:
- server
environment:
QUEUES: "scheduled_queries,schemas"
WORKERS_COUNT: 1
adhoc_worker:
<<: *redash-service
command: worker
depends_on:
- server
environment:
QUEUES: "queries"
WORKERS_COUNT: 2
Expand All @@ -50,5 +56,5 @@ services:
<<: *redash-service
command: worker
environment:
QUEUES: "periodic emails default"
QUEUES: "periodic,emails,default"
WORKERS_COUNT: 1
2 changes: 1 addition & 1 deletion redash_make_default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ cat <<EOF >>~/__TARGET_FILE__
# Added by Redash 'redash_make_default.sh' script
export COMPOSE_PROJECT_NAME=redash
export COMPOSE_FILE=__BASE_PATH__/compose.yaml
export COMPOSE_FILE=__COMPOSE_FILE__
EOF
echo "Redash has now been set as the default Docker Compose project"
80 changes: 64 additions & 16 deletions setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set -eu

REDASH_BASE_PATH=/opt/redash
OVERWRITE=no
PREVIEW=no
PORT=5000

# Ensure the script is being run as root
ID=$(id -u)
Expand All @@ -19,12 +21,38 @@ if [ ! -f /etc/os-release ]; then
exit
fi

# Check if the --overwrite option was set
if [ $# -ne 0 ]; then
if [ "x$1" = "x--overwrite" ]; then
OVERWRITE=yes
fi
fi
# Parse any user provided parameters
opts="$(getopt -o oph -l overwrite,preview,help --name "$0" -- "$@")"
eval set -- "$opts"

while true
do
case "$1" in
-o|--overwrite)
OVERWRITE=yes
shift
;;
-p|--preview)
PREVIEW=yes
PORT=5001
shift
;;
-h|--help)
echo "Redash setup script usage: $0 [-p|--preview] [-o|--overwrite]"
echo " The --preview option uses the Redash 'preview' Docker image instead of the last stable release"
echo " The --overwrite option replaces any existing configuration with a fresh new install"
exit 1
;;
--)
shift
break
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done

install_docker_debian() {
echo "** Installing Docker (Debian) **"
Expand Down Expand Up @@ -114,7 +142,9 @@ create_directories() {
if [ "x$OVERWRITE" = "xyes" ]; then
# We've been asked to overwrite the existing database, so delete the old one
echo "Shutting down any running Redash instance"
docker compose -f "$REDASH_BASE_PATH"/compose.yaml down
if [ -e "$REDASH_BASE_PATH"/compose.yaml ]; then
docker compose -f "$REDASH_BASE_PATH"/compose.yaml down
fi

echo "Removing old Redash PG database directory"
rm -rf "$REDASH_BASE_PATH"/postgres-data
Expand Down Expand Up @@ -175,8 +205,8 @@ create_env() {
return
fi

# Remove existing environment file
rm -f "$REDASH_BASE_PATH"/env
# Move any existing environment file out of the way
mv -f "$REDASH_BASE_PATH"/env "$REDASH_BASE_PATH"/env.old
fi

echo "Generating brand new environment file"
Expand All @@ -189,6 +219,8 @@ REDASH_COOKIE_SECRET=$COOKIE_SECRET
REDASH_SECRET_KEY=$SECRET_KEY
POSTGRES_PASSWORD=$PG_PASSWORD
REDASH_DATABASE_URL=$DATABASE_URL
REDASH_ENFORCE_CSRF=true
REDASH_GUNICORN_TIMEOUT=60
EOF
}

Expand All @@ -197,13 +229,19 @@ setup_compose() {

cd "$REDASH_BASE_PATH"
GIT_BRANCH="${REDASH_BRANCH:-master}" # Default branch/version to master if not specified in REDASH_BRANCH env var
if [ "x$OVERWRITE" = "xyes" ]; then
mv -f compose.yaml compose.yaml.old
fi
curl -fsSOL https://raw.githubusercontent.com/getredash/setup/"$GIT_BRANCH"/data/compose.yaml
curl -fsSOL https://raw.githubusercontent.com/getredash/setup/"$GIT_BRANCH"/redash_make_default.sh
sed -i "s|__BASE_PATH__|${REDASH_BASE_PATH}|" redash_make_default.sh
sed -i "s|__TARGET_FILE__|$1|" redash_make_default.sh
chmod +x redash_make_default.sh
export COMPOSE_PROJECT_NAME=redash
TAG="10.1.0.b50633"
if [ "x$PREVIEW" = "xyes" ]; then
TAG="preview"
fi
sed -i "s|__TAG__|$TAG|" compose.yaml
# The preview image uses a different port to access the web interface
sed -i "s|__PORT__|$PORT|" compose.yaml
export COMPOSE_FILE="$REDASH_BASE_PATH"/compose.yaml
export COMPOSE_PROJECT_NAME=redash

echo "** Initialising Redash database **"
docker compose run --rm server create_db
Expand All @@ -215,6 +253,15 @@ setup_compose() {
docker compose up -d
}

setup_make_default() {
echo "** Creating redash_make_default.sh script **"

curl -fsSOL https://raw.githubusercontent.com/getredash/setup/"$GIT_BRANCH"/redash_make_default.sh
sed -i "s|__COMPOSE_FILE__|$COMPOSE_FILE|" redash_make_default.sh
sed -i "s|__TARGET_FILE__|$PROFILE|" redash_make_default.sh
chmod +x redash_make_default.sh
}

echo
echo "Redash installation script. :)"
echo
Expand Down Expand Up @@ -245,10 +292,11 @@ esac
# Do the things that aren't distro specific
create_directories
create_env
setup_compose "$PROFILE"
setup_compose
setup_make_default

echo
echo "Redash has been installed and is ready for configuring at http://$(hostname -f):5000"
echo "Redash has been installed and is ready for configuring at http://$(hostname -f):$PORT"
echo

echo "If you want Redash to be your default Docker Compose project when you login to this server"
Expand Down

0 comments on commit 1299b8f

Please sign in to comment.