Redashの開発環境をあえてVagrantで構築する

はじめに

Redash は公式ドキュメントでは、開発環境には Docker を使うことを推奨されています。

Guide · Redash Help Center

以前は Redash のリポジトリVagrantfile も含まれていましたが、今ではDocker移行を推奨するためか削除されています。

Docker を使うようになったことで、環境構築がかなり気軽にできるようになりました。 Redash Meetup ハンズオンで使用している以下の資料も、Docker を使った環境構築手順になっています。

github.com

しかし、Redash のコードを追っていったり、ミドルウェア周りの調査で DB や稼働プロセスを覗き見したりするときは、VagrantVM を1台起動して、その中にRedash も PostgreSQL も Redis も入っている方が便利なことがあります。

この記事では、あえて今 Vagrant で Redash の環境構築をする方法を紹介します。

環境構築

前置きが長くなりましたが、とても簡単です。

前提条件

以下の環境で動作確認しました。

手順

Redash のバージョン v3.0.0 の環境を構築します。

$ mkdir redash_on_vagrant
$ cd redash_on_vagrant
$ wget https://raw.githubusercontent.com/ariarijp/vagrantfiles/master/redash/Vagrantfile
$ vagrant up

Vagrant が使える状態になっていれば、手順は上記のコマンドだけです。

VM が起動するまで10-15分ほど時間がかかりますが、ほとんど cassandra-driver のビルド待ちです。気長に待ちましょう。

動作確認

ブラウザで http://localhost:8080/setup にアクセスすると、Redash ユーザーには見慣れた画面が表示されます。

f:id:ariarijp:20180104212003p:plain

Vagrant で環境構築をするメリットである、「全部入り」になっていることを確認するため、 VM 上で ps コマンドを実行してみます。

$ vagrant ssh -- ps axuf
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
...省略...
postgres 14048  0.0  1.1 293424 24424 ?        S    12:10   0:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf
postgres 14050  0.0  0.3 293556  6316 ?        Ss   12:10   0:00  \_ postgres: checkpointer process   
postgres 14051  0.0  0.2 293424  5624 ?        Ss   12:10   0:00  \_ postgres: writer process   
postgres 14052  0.0  0.4 293424  8800 ?        Ss   12:10   0:00  \_ postgres: wal writer process   
postgres 14053  0.0  0.3 293852  6628 ?        Ss   12:10   0:00  \_ postgres: autovacuum launcher process   
postgres 14054  0.0  0.1 148568  3188 ?        Ss   12:10   0:00  \_ postgres: stats collector process   
postgres 17700  0.0  0.7 300764 16148 ?        Ss   12:18   0:00  \_ postgres: redash redash [local] idle
postgres 17701  0.0  0.7 300716 15868 ?        Ss   12:18   0:00  \_ postgres: redash redash [local] idle
postgres 17702  0.0  0.7 300716 15004 ?        Ss   12:18   0:00  \_ postgres: redash redash [local] idle
postgres 17704  0.0  0.7 301292 16376 ?        Ss   12:19   0:00  \_ postgres: redash redash [local] idle
postgres 17705  0.0  0.7 300716 15068 ?        Ss   12:19   0:00  \_ postgres: redash redash [local] idle
redis    14267  0.1  0.5  37228 10420 ?        Ssl  12:10   0:00 /usr/bin/redis-server 127.0.0.1:6379
root     17621  0.0  0.9  57376 19880 ?        Ss   12:18   0:00 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
redash   17658  0.6  4.7 293576 96684 ?        S    12:18   0:01  \_ [celeryd: celery@ubuntu-xenial:MainProcess] -active- (worker --app=redash.worker --beat -c2 -Qqueries,celery --maxtasksperchild=10 -Ofair)
redash   17695  0.1  4.7 303888 97108 ?        S    12:18   0:00  |   \_ [celeryd: celery@ubuntu-xenial:Worker-2]
redash   17697  0.1  4.7 303892 96996 ?        S    12:18   0:00  |   \_ [celeryd: celery@ubuntu-xenial:Worker-3]
redash   17698  0.0  4.3 301300 90004 ?        S    12:18   0:00  |   \_ [celery beat]
redash   17659  0.0  0.9  55952 18516 ?        S    12:18   0:00  \_ gunicorn: master [redash]
redash   17682  0.4  4.9 293476 101916 ?       S    12:18   0:01  |   \_ gunicorn: worker [redash]
redash   17684  0.4  4.9 293080 101352 ?       S    12:18   0:01  |   \_ gunicorn: worker [redash]
redash   17688  0.4  4.9 293892 102296 ?       S    12:18   0:01  |   \_ gunicorn: worker [redash]
redash   17691  0.4  4.9 294152 102324 ?       S    12:18   0:01  |   \_ gunicorn: worker [redash]
redash   17660  0.6  4.7 293296 96688 ?        S    12:18   0:01  \_ [celeryd: celery@ubuntu-xenial:MainProcess] -active- (worker --app=redash.worker -c2 -Qscheduled_queries --maxtasksperchild=10 -Ofair)
redash   17694  0.0  4.6 302564 94268 ?        S    12:18   0:00      \_ [celeryd: celery@ubuntu-xenial:Worker-1]
redash   17696  0.0  4.6 302564 94476 ?        S    12:18   0:00      \_ [celeryd: celery@ubuntu-xenial:Worker-2]
root     17647  0.0  0.0 124972  1436 ?        Ss   12:18   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 17648  0.0  0.1 125348  3148 ?        S    12:18   0:00  \_ nginx: worker process
www-data 17649  0.0  0.2 125420  4844 ?        S    12:18   0:00  \_ nginx: worker process
...省略...

Redash の主要なプロセスが稼働していることがわかりました。

Redash のソースコード一式は /opt/redash 以下にあります。

$ vagrant ssh -- ls -la /opt/redash
total 16
drwxr-xr-x 3 redash root    4096 Jan  4 12:34 .
drwxr-xr-x 3 root   root    4096 Jan  4 12:34 ..
lrwxrwxrwx 1 root   root      30 Jan  4 12:34 current -> /opt/redash/redash.3.0.0.b3134
-rw-r--r-- 1 redash nogroup  191 Jan  4 12:34 .env
drwxr-xr-x 9 redash nogroup 4096 Jan  4 12:34 redash.3.0.0.b3134

あとは vagrant ssh してコードを変えてみたり、ミドルウェアの設定を変えてみたりといろいろ試せます。

まとめ

Vagrant でも、それなりに簡単に Redash の環境を構築することができるようになりました。

Docker に少し苦手意識があるけど Redash を試してみたい方にも、この記事が参考になるかもしれません。

実践 Vagrant

実践 Vagrant