LoginSignup
18
26

More than 5 years have passed since last update.

Redashの開発環境を作る手順

Last updated at Posted at 2017-10-17

Redash の開発環境を作った時の手順を書いてみます。

作業はざっくり次の流れです。

  1. ソースコードの取得
  2. 必要なパッケージのインストール
  3. Docker Compose の修正とコンテナの起動
  4. 起動時の設定
  5. 初期データベース登録
  6. Webサーバの起動
  7. Workerの起動
  8. webpack の開発用サーバの起動

はじめに

Redash の開発環境を構築する方法は大きく分けて次の3つになると思います。

  • AMI または Google Compute Engine のイメージから構築
  • Docker イメージから構築
  • プロビジョニングスクリプトから構築

当初 AMI でインスタンスを作成して構築しようとしていたのですが、無料枠で使える t2.micro インスタンスだと非力すぎて断念しました。この時の手順は別記事にしています。

また、ドキュメントによるとプロビジョニングスクリプトは Ubuntu でのみしかテストされていないのと、他の環境を壊してしまう事が怖かったため、最終的に Docker を選択しました。

Docker Compose として Redash 本体と、それ以外の関連サービスである Redis, Postgres, nginx にイメージが分かれていたので Redash 本体は clone したソースを使い、それ以外はこれらのイメージから作成したコンテナを使うことにしました。

ソースコードの取得

適当な作業用ディレクトリでプロジェクトを clone します。

% git clone git@github.com:getredash/redash.git

必要なパッケージのインストール

まず、pip で Python パッケージのインストールを行います。注意点として Python は2.7系を使ってインストールします。

% sudo pip install -r requirements.txt -r requirements_dev.txt -r requirements_all_ds.txt

sudo を付けているのはインストールするパッケージによって、root 権限が必要なディレクトリにアクセスするためです。

次に Node.js パッケージのインストールを行います。ここでも注意点として、npm は package-lock.json をサポートしたv5以上を使った方が安全です。

古いバージョン使っていたので、参照しているパッケージに問題があった場合に気づくのに時間がかかります。自分は Issue まで立ててました。

% npm install

初回ビルドを行います。

% npm run build

Docker Compose の修正とコンテナの起動

docker-compose.ymlでも良いのですが、docker-compose.production.yml を編集しました。

docker-compose.production.yml
version: '2'
services:
  redis:
    image: redis:3.0-alpine
    restart: always
    ports:
      - "6370:6379"
  postgres:
    image: postgres:9.5.6-alpine
    restart: always
    ports:
      - "6543:5432"

server, worker, nginx サービスを削除しています。

server, worker サービスが Redash 本体で、これらは docker イメージではなくソースを利用し、nginx は経由しないためです。

また、別の環境ですでに5432番ポートを使っていたので、Postgres を6543番ポートに割り当てました。

イメージの取得とコンテナの作成、起動を行います。

% docker-compose -f docker-compose.production.yml up -d 

起動時の設定

環境変数で起動時の設定をプロジェクトディレクトリ直下の .env ファイルに指定します。

.env
export PYTHONUNBUFFERED=0
export REDASH_LOG_LEVEL="DEBUG"
export REDASH_DATABASE_URL="postgresql://postgres:postgres@localhost:6543/postgres"
export REDASH_COOKIE_SECRET=veryverysecret
export REDASH_WEB_WORKERS=4
export REDASH_ADDITIONAL_QUERY_RUNNERS=redash.query_runner.python
export REDASH_REDIS_URL="redis://localhost:6370/0"
export WORKERS_COUNT=2

Postgres, Redis のポートを変更したのでここで指定します。

初期データベース登録

初期データベースを作成します。

% bin/run ./manage.py database create_tables

Webサーバの起動

Webサーバを起動します。

% bin/run ./manage.py runserver --debugger --reload --host 0.0.0.0

--reload オプションによって、コードを編集して保存したタイミングで Web サーバのリロードが行われます。

--host 0.0.0.0 オプションによって、別のマシンからアクセスできるようになります。

Workerの起動

Webサーバと同様に Worker も Docker ではなく clone したソースコードを利用するため、起動します。

% bin/run celery worker --app=redash.worker --beat -Qqueries,celery,scheduled_queries~~

webpack の開発用サーバの起動

webpack の開発用サーバを起動します。

% npm run start

この後、localhost:8080 にブラウザからアクセスするとログインページが表示されるはずです。

welcome_redash.png

これで開発環境の構築はひとまず完了になります。実際のデータソースは

などを参考に追加します。

開発するゾ :muscle:

ログインページが表示されない場合

以下の内容を確認して対応します。

  • docker psworker, redis, postgres のコンテナが起動しているか
  • Webサーバ起動 bin/run ./manage.py runserver --debugger --reload のログにエラーが出ていないか
  • webpack の開発用サーバ起動 npm run start のログにエラーが出ていないか

webpacknode-sass のビルドエラーが出る場合

npm run build もしくは npm run start時に次のようなエラーが出る事があります。

       [0] ./node_modules/css-loader?{"minimize":false}!./node_modules/sass-loader/lib/loader.js!./client/app/assets/css/main.scss 1.46 kB {0} [built] [failed] [1 error]

    ERROR in ./node_modules/css-loader?{"minimize":false}!./node_modules/sass-loader/lib/loader.js!./client/app/assets/css/main.scss
    Module build failed: Error: Missing binding /Users/katsuhiko.yoshida/work/redash/node_modules/node-sass/vendor/darwin-x64-57/binding.node
    Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 8.x

    Found bindings for the following environments:
      - OS X 64-bit with Node.js 6.x
      - OS X 64-bit with Node.js 7.x

    This usually happens because your environment has changed since running `npm install`.
    Run `npm rebuild node-sass --force` to build the binding for your current environment.
        at module.exports (/Users/katsuhiko.yoshida/work/redash/node_modules/node-sass/lib/binding.js:15:13)
        at Object.<anonymous> (/Users/katsuhiko.yoshida/work/redash/node_modules/node-sass/lib/index.js:14:35)
        at Module._compile (module.js:624:30)
        at Object.Module._extensions..js (module.js:635:10)
        at Module.load (module.js:545:32)
        at tryModuleLoad (module.js:508:12)
        at Function.Module._load (module.js:500:3)
        at Module.require (module.js:568:17)
        at require (internal/module.js:11:18)
        at Object.<anonymous> (/Users/katsuhiko.yoshida/work/redash/node_modules/sass-loader/lib/loader.js:3:14)
        at Module._compile (module.js:624:30)
        at Object.Module._extensions..js (module.js:635:10)
        at Module.load (module.js:545:32)
        at tryModuleLoad (module.js:508:12)
        at Function.Module._load (module.js:500:3)
        at Module.require (module.js:568:17)

この場合、node-sass を再構築すると解消されました。

% npm rebuild node-sass

参考

18
26
1

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
18
26