官术网_书友最值得收藏!

Explaining the setup.sh script

The setup.sh script is the core of all the cloud based installation options. Regarding an image-based installation, you don't have to dive into the details of this script, but if you want to install Redash manually (or are just curious about the internals), it's better to take a quick look at it.

In case you intend to use the setup.sh script for production environment:

For small scale deployments you can use it as is.

But for large scale deployments where Redash is mission critical, and needs to be Highly Available, it's recommend that you set up a separate server for PostgreSQL and Redis, as well as set up at least 2 servers for Redash for redundancy.

The number of celery workers can be modified based on your usage patterns.

Let's break the script into parts while going over it.

At first, we set Redash base installation path, and start defining helper functions.

The following is the definition of helper function, which installs the docker compose as well as surrounding components:

#!/usr/bin/env bash
# This script setups dockerized Redash on Ubuntu 18.04.
set -eu

REDASH_BASE_PATH=/opt/redash

install_docker(){
    # Install Docker
    sudo apt-get update 
    sudo apt-get -yy install apt-transport-https ca-certificates curl software-properties-common wget pwgen
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    sudo apt-get update && sudo apt-get -y install docker-ce

    # Install Docker Compose
    sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose

    # Allow current user to run Docker commands
    sudo usermod -aG docker $USER
    newgrp docker
}

The following is a helper function that creates the directories for Redash installation: 

create_directories() {
    if [[ ! -e $REDASH_BASE_PATH ]]; then
        sudo mkdir -p $REDASH_BASE_PATH
        sudo chown $USER:$USER $REDASH_BASE_PATH
    fi

    if [[ ! -e $REDASH_BASE_PATH/postgres-data ]]; then
        mkdir $REDASH_BASE_PATH/postgres-data
    fi
}

The following is a helper function that creates and persists Environment Variables used in Redash:

create_config() {
    if [[ -e $REDASH_BASE_PATH/env ]]; then
        rm $REDASH_BASE_PATH/env
        touch $REDASH_BASE_PATH/env
    fi

    COOKIE_SECRET=$(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_DATABASE_URL=$REDASH_DATABASE_URL" >> $REDASH_BASE_PATH/env
}

The following helper function fetches the latest docker image, as well as docker-compose file, and runs it:

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
    REDASH_BRANCH="${REDASH_BRANCH:-master}" # Default branch/version to master if not specified in REDASH_BRANCH env var
    wget https://raw.githubusercontent.com/getredash/redash/${REDASH_BRANCH}/setup/docker-compose.yml
    sed -ri "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
    source ~/.profile
    docker-compose run --rm server create_db
    docker-compose up -d
}

The following code invokes all the previously defined functions (the order here is important):

install_docker
create_directories
create_config
setup_compose
主站蜘蛛池模板: 西安市| 哈巴河县| 邵阳市| 金山区| 汉阴县| 阿勒泰市| 龙里县| 故城县| 大渡口区| 深圳市| 黄梅县| 沂南县| 施甸县| 华阴市| 安阳市| 东乡族自治县| 池州市| 抚远县| 嵊州市| 太湖县| 苗栗市| 江城| 新民市| 闵行区| 宁德市| 石嘴山市| 张家川| 明溪县| 含山县| 瑞昌市| 武穴市| 鹤岗市| 德钦县| 蒲江县| 朔州市| 惠水县| 衡南县| 乌苏市| 屯昌县| 思茅市| 阿图什市|