10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Redash を Docker for Mac で最速で動かす

Posted at

概要

Redash の Docker for Mac 上で最速で動かします。
Redash の開発はしないので、用意されたセットアップを実行するだけになります。
セットアップファイルの実行から Redash の起動までに少し修正が必要でした。

環境

macOS 10.15.3 Catalina
Docker for Mac 2.2.0.3
Redash v8.0.0.b32245

ディレクトリ構成

setup ディレクトリは、公式から git clone してきたもの。
その中の setup.sh を実行すると、redash ディレクトリが作成されます。

setup/
  ├ setup.sh
redash/
  ├ postgres-data/
  ├ env
  ├ docker-compose.yml

事前準備

setup.sh で pwgen, wget が必要なので予めインストールしておきます

$ brew install pwgen
$ brew install wget

手順

セットアップファイルをとってくる

$ git clone git@github.com:getredash/setup.git

セットアップファイルの中にある setup.sh を編集

とってきた setup.sh は Ubuntu 用なので、Mac で動くように編集する

もとのファイルから変更している箇所は

  • Redash のディレクトリ作成箇所
  • 不要な Docker インストールの削除
  • 不要な sudo 削除
  • sed が Mac で動くように修正
  • docker-compose は手動でやるのでコメントアウト
    あたりです。
    もとのセットアップファイルは /opt/redash に作成しようとしていますが
    Mac上では、自分の好きなディレクトリに設置したいので変更します。
    今回はこの setup ディレクトリと同じ階層にしました。
setup.sh
# !/usr/bin/env bash
# This script setups dockerized Redash on Mac OS.
set -eu

REDASH_BASE_PATH=../redash

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

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

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)
    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
    wget https://raw.githubusercontent.com/getredash/setup/${GIT_BRANCH}/data/docker-compose.yml
    sed -Ei '' "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
    # docker-compose up -d
}

create_directories
create_config
setup_compose

docker-compose.yml を編集

  • 生成された docker-compose.yml で /opt/redash となっている箇所を . に差し替える(setup.sh で Redash のディレクトリ作成箇所を変えたため)
  • restart : always を消す(必須ではない)
  • nginx の ports を 8080:80 にする(必須ではない)
docker-compose.yml
version: "2"
x-redash-service: &redash-service
  image: redash/redash:8.0.0.b32245
  depends_on:
    - postgres
    - redis
  env_file: ./env
services:
  server:
    <<: *redash-service
    command: server
    ports:
      - "5000:5000"
    environment:
      REDASH_WEB_WORKERS: 4
  scheduler:
    <<: *redash-service
    command: scheduler
    environment:
      QUEUES: "celery"
      WORKERS_COUNT: 1
  scheduled_worker:
    <<: *redash-service
    command: worker
    environment:
      QUEUES: "scheduled_queries,schemas"
      WORKERS_COUNT: 1
  adhoc_worker:
    <<: *redash-service
    command: worker
    environment:
      QUEUES: "queries"
      WORKERS_COUNT: 2
  redis:
    image: redis:5.0-alpine
  postgres:
    image: postgres:9.6-alpine
    env_file: ./env
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
  nginx:
    image: redash/nginx:latest
    ports:
      - "8080:80"
    depends_on:
      - server
    links:
      - server:redash

起動

$ docker-compose run --rm server create_db
$ docker-compose up -d

接続

http://localhost:8080 にアクセスして、この画面が出てきたら成功
スクリーンショット 2020-02-24 16.12.28.png

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?