Ubuntu ä¸ã§ç°å¢æ§ç¯ãã¦ãã Redash ã Docker ä¸ã§åä½ããç°å¢ã«ç§»è¡ããæé
ãã®è¨äºã¯ Redash Advent Calendar 2018 25æ¥ç®ãæçµæ¥ã®è¨äºã§ãï¼
åå ããã ããã¿ãªãã¾ããèªãã§ããã ããçæ§ããããã¨ããããã¾ãï¼
ãé¡
ç¾å¨ãRedash ã®ç°å¢æ§ç¯ã¯ Docker ã使ç¨ããæ¹æ³ã®ã¿ãå ¬å¼ããã¥ã¡ã³ããªã©ã§ãè¨è¼ããã¦ãã¾ãããå¤ãããã® Redash ã¦ã¼ã¶ã¼ã«ã¨ã£ã¦ã¯ãUbuntu ã®ä¸ã«ã¤ã³ã¹ãã¼ã«ããå½¢ã§éç¨ãã¦ããæ¹ãå¤ããç§ããã®ã²ã¨ãã§ãã
ãã®è¨äºã§ã¯ãæ§æ¥ã® Ubuntu ä¸ã«ç°å¢æ§ç¯ããã Redash(以éãã¬ã¬ã·ã¼ã»ããã¢ãã)ã Docker ã§æ§ç¯ããã Redashï¼ä»¥éãDocker ã»ããã¢ããï¼ã«ç§»è¡ããæ¹æ³ãç´¹ä»ãã¾ãã
注æäºé
ãã®è¨äºã§ç´¹ä»ããæ¹æ³ã¯ããããç°å¢ãç¶²ç¾ ãããã®ã§ã¯ããã¾ããã
ã使ãã®ç°å¢ã移è¡ããéã¯ãå¿ ããèªèº«ã§æ¤è¨¼ãã¦ãã ããã
ã¾ãããã®æé ã¯ç§ãæ¥å㧠Redash ã移è¡ããéã«ãå©ç¨ãã¦ããããã移è¡ä½æ¥ã®çµæã«ãã£ã¦ããã®è¨äºãå çä¿®æ£ããå ´åãããã¾ãã
åææ¡ä»¶
ãã®è¨äºã®æ¤è¨¼ã§ä½¿ç¨ãã Ubuntu 㨠Dockerã Docker Compose ã®ãã¼ã¸ã§ã³ã¯ä»¥ä¸ã¨ãªã£ã¦ãã¾ãã
- Ubuntu 16.04.4 LTS
- Docker version 18.09.0, build 4d60db4
- docker-compose version 1.8.0, build unknown
ãã®è¨äºã§ã¯ Docker ã®å°å ¥ã«ã¤ãã¦ã¯å²æãã¾ãããç§ã¯ä»¥ä¸ã®è¨äºãåèã«ã㦠Docker ãå°å ¥ãã¾ããã
How To Install and Use Docker on Ubuntu 16.04 | DigitalOcean
æé
PostgreSQL 以å¤ã® Redash é¢é£ã®ãµã¼ãã¹ãåæ¢
PostgreSQL ã® DB ãã³ããåå¾ããåã«ãRedash é¢é£ã®ãµã¼ãã¹ããã¹ã¦åæ¢ãã¾ãã
$ sudo service nginx stop $ sudo service supervisord stop $ sudo service redis_6379 stop
ãµã¼ãã¹å㯠Redash ãã©ã®ãã¼ã¸ã§ã³ããå©ç¨ãã¦ãããã«ãã£ã¦ç°ãªãå ´åãããã¾ãã
æ¢åã® Redash ãã DB ãã³ããåå¾ãã
Docker ã»ããã¢ããç°å¢ã§ä½¿ç¨ãã PostgreSQL ã«ãªã¹ãã¢ããããã® DB ãã³ããåå¾ãã¾ãã
ã¬ã¬ã·ã¼ã»ããã¢ããã§ã¯ PostgreSQL ã« redash
ã¦ã¼ã¶ã¼ãä½æãã¾ãããDocker ã»ããã¢ããã§ã¯ postgres
ã¦ã¼ã¶ã¼ã使ãã¾ããããã®ãããæ¢åç°å¢ã®ãã³ããã¡ã¤ã«åå¾æã«ãªã¼ãã¼æ
å ±ãé¤å»ãã¦ããã¾ãã
$ sudo -u postgres bash -c "pg_dump --no-owner --no-acl redash | gzip > /tmp/dump.sql.gz"
ãã³ããã¡ã¤ã«ã®åºåå
㯠/opt/docker/redash
ã¨ãã¦ããã®è¨äºå
ã§ã¯ä»¥éã®èª¬æã§ãããã®ãã£ã¬ã¯ããªå
ã§ä½æ¥ãã¾ã
æ¢åã® PostgreSQL ãåæ¢
ãã³ããã¡ã¤ã«ãåå¾ããããæ¢åã® PostgreSQL ã¯ä¸è¦ã«ãªããããµã¼ãã¹ãåæ¢ãã¾ãã
$ sudo service postgresql stop
docker-compose.yml ããã¦ã³ãã¼ããã
移è¡å
ãã¼ã¸ã§ã³ã® docker-compose.production.yml
ããã¦ã³ãã¼ããã¾ãã
ãã®è¨äºã§ã¯ç§»è¡å
ã« v5.0.2
ã使ç¨ãããããGitHub ä¸ã§ã¿ã°ãæå®ãã¦ãã¦ã³ãã¼ããã¦ãã¾ãã
$ wget -o /opt/docker/redash/docker-compose.yml https://raw.githubusercontent.com/getredash/redash/v5.0.2/docker-compose.production.yml
docker-compose.yml ãæ¸ãæãã
Docker ã»ããã¢ããã§ä½¿ç¨ãããã¼ã¸ã§ã³ã«åãã㦠docker-compose.yml
ãæ¸ãæãã¾ãã
ãã¼ã¸ã§ã³ã®æå®
Docker ã¤ã¡ã¼ã¸ã®ã¿ã°ä¸è¦§ ãåç §ããå©ç¨ããããã¼ã¸ã§ã³ã®ã¿ã°ãæå®ãã¾ãã
$ sed -i s/redash\\/redash:latest/redash\\/redash:5.0.2.b5486/g /opt/docker/redash/docker-compose.yml
postgres ãµã¼ãã¹ã®ããªã¥ã¼ã æå®
PostgreSQL ã®ãã¼ã¿ãä¿æããããªã¥ã¼ã ãæå®ãã¾ãã
postgres
ãµã¼ãã¹ã® volumes
ãã³ã¡ã³ãã¢ã¦ãããã¦ããã®ã§ããããã¢ã³ã³ã¡ã³ããã¦ãã¹ãå´ã®ãã¹ãæ¸ãæãã¾ã
...çç¥... postgres: image: postgres:9.5.6-alpine volumes: - /opt/docker/redash/postgres-data:/var/lib/postgresql/data restart: always ...çç¥...
ç°å¢å¤æ°ãè¨å®ãã
æ¢åã® Redash ã® .env
ããå¿
è¦ãªè¨å®ã server
, worker
ãµã¼ãã¹ã® environment
ã«è¨å®ãã¾ãã
ããã§ã¯è©³ç´°ãªèª¬æãçãã¾ãããã¡ã¼ã«ãµã¼ãã¼ã®è¨å®ãªã©ã¯ .env
ã«ã§è¨å®ãããã¨ãå¤ãã®ã§ãå¿ããã«è¨å®ãã¾ãããã
ã¾ããserver
ã®ã¿ã«è¨å®ãã¦ãã¾ã worker
ã«ç°å¢å¤æ°ãé©ç¨ãããªãã¨ããã±ã¼ã¹ãããã®ã§ãå¿ããã«ä¸¡æ¹ã® environment
ã«è¨å®ãã¦ãã ããã
Docker Compose ã§èµ·åãã
æºåãã§ãããããµã¼ãã¹ãèµ·åãã¾ãã
$ sudo docker-compose up -d
postgres
ã«ãã³ããã¡ã¤ã«ãã³ãã¼ããã
æ°è¦ã¤ã³ã¹ãã¼ã«ã®æé ã§ããã°ãã㧠create_db
ãå®è¡ããã¨ããã§ãããä»åã¯æ¢åç°å¢ããã®ç§»è¡ãªã®ã§ããã¼ã¿ãã¼ã¹ã®ä½æã¯ããã«ãå
ç¨åå¾ãããã³ããã¡ã¤ã«ããªã¹ãã¢ãã¾ãã
ãã®ããããã³ããã¡ã¤ã«ã postgres
ãµã¼ãã¹ãåãã¦ããã³ã³ããã«ã³ãã¼ãã¾ãã
$ sudo docker cp /tmp/dump.sql.gz `sudo docker ps|grep postgres|awk '{print $1}'`:/tmp/
DB ããªã¹ãã¢ãã
ã³ãã¼ãããã³ããã¡ã¤ã«ã使ã£ã¦ã以ä¸ã®ã³ãã³ãã§ãªã¹ãã¢ãã¾ãã
$ sudo docker-compose exec postgres bash -c "zcat /tmp/dump.sql.gz | psql -U postgres"
ãã¤ã°ã¬ã¼ã·ã§ã³ãå®è¡ãã
ãã®æç¹ã§ãDB ã¯ä½ããã¦ãã¾ãããå¤ããã¼ã¸ã§ã³ã®ãã¼ãã«æ§é ã®ã¾ã¾ã«ãªã£ã¦ããããããã¤ã°ã¬ã¼ã·ã§ã³ãå®è¡ãã¦ç§»è¡å ã®ãã¼ã¸ã§ã³ã«ãã£ããã¼ãã«æ§æã«ãã¾ãã
$ sudo docker-compose run --rm server manage db upgrade
ããã¾ã§ã§ã¬ã¬ã·ã¼ã»ããã¢ãããã Docker ã»ããã¢ããã¸ã®ç§»è¡ã¯å®äºã§ãã
çé確èª
æå¾ã«ãcurl
ã§ç°¡åã«çé確èªãã¦ã¿ã¾ãã
$ curl -I localhost/api/config
JSON æååã表示ããã¦ããã°ã移è¡ãã Redash ãåä½ãã¦ãããã¨ã確èªã§ãã¦ãã¾ãã
ã¾ã¨ã
ãã¼ã¸ã§ã³ã¢ããã«ããã¹ãããã«è °ãéããªããããªç§»è¡ä½æ¥ã§ãããç§ãä»å¾ã®ã¢ããã°ã¬ã¼ããè¦æ®ãã¦ç§»è¡ãé²ãã¦ãã¾ãã移è¡ã¯è¨ç»çã«é²ãã¾ãããã