Skip to content

Instantly share code, notes, and snippets.

@ohsawa0515
Last active February 7, 2020 06:34
Show Gist options
  • Save ohsawa0515/4ae6fa3decfb6ba19de12087db996d09 to your computer and use it in GitHub Desktop.
Save ohsawa0515/4ae6fa3decfb6ba19de12087db996d09 to your computer and use it in GitHub Desktop.
Setup scirpt for Redash with Docker on Mac OS
#!/usr/bin/env bash
# This script setups dockerized Redash on Mac OS.
set -eu
REDASH_BASE_PATH=/opt/redash
create_directories() {
sudo mkdir -p $REDASH_BASE_PATH/postgres-data
sudo chown -R $USER $REDASH_BASE_PATH
}
create_config() {
if [[ -e $REDASH_BASE_PATH/env ]]; then
rm -f $REDASH_BASE_PATH/env
touch $REDASH_BASE_PATH/env
fi
COOKIE_SECRET=$(pwgen -1s 32)
SECRET_KEY=$(pwgen -1s 32)
POSTGRES_PASSWORD=$(pwgen -1s 32)
REDASH_DATABASE_URL="postgresql://postgres:${POSTGRES_PASSWORD}@postgres/postgres"
echo "PYTHONUNBUFFERED=0" >> $REDASH_BASE_PATH/env
echo "REDASH_LOG_LEVEL=INFO" >> $REDASH_BASE_PATH/env
echo "REDASH_REDIS_URL=redis://redis:6379/0" >> $REDASH_BASE_PATH/env
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> $REDASH_BASE_PATH/env
echo "REDASH_COOKIE_SECRET=$COOKIE_SECRET" >> $REDASH_BASE_PATH/env
echo "REDASH_SECRET_KEY=$SECRET_KEY" >> $REDASH_BASE_PATH/env
echo "REDASH_DATABASE_URL=$REDASH_DATABASE_URL" >> $REDASH_BASE_PATH/env
}
setup_compose() {
REQUESTED_CHANNEL=stable
LATEST_VERSION=`curl -s "https://version.redash.io/api/releases?channel=$REQUESTED_CHANNEL" | json_pp | grep "docker_image" | head -n 1 | awk 'BEGIN{FS=":"}{print $3}' | awk 'BEGIN{FS="\""}{print $1}'`
cd $REDASH_BASE_PATH
GIT_BRANCH="${REDASH_BRANCH:-master}" # Default branch/version to master if not specified in REDASH_BRANCH env var
if [[ -e docker-compose.yml ]]; then
rm -f docker-compose.yml
fi
wget https://raw.githubusercontent.com/getredash/setup/${GIT_BRANCH}/data/docker-compose.yml
sed -i '.bak' "s/image: redash\/redash:([A-Za-z0-9.-]*)/image: redash\/redash:$LATEST_VERSION/" docker-compose.yml
echo "export COMPOSE_PROJECT_NAME=redash" >> ~/.profile
echo "export COMPOSE_FILE=/opt/redash/docker-compose.yml" >> ~/.profile
export COMPOSE_PROJECT_NAME=redash
export COMPOSE_FILE=/opt/redash/docker-compose.yml
docker-compose run --rm server create_db
COMPOSE_HTTP_TIMEOUT=120 docker-compose up -d
}
create_directories
create_config
setup_compose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment