Retrobot on Docker
2å¹´åã®å¤ããããããwhite_retro ã¨ããååã® twitter bot ãéç¨ãã¦ãã
ãã®ã¢ã«ã¦ã³ãï¼botï¼ã§ã¯ã
- 1å¹´åã® @7kajii ã®çºè¨
- 2å¹´åã® @7kajii ã®çºè¨
- 1å¹´åã® whitech0c0late ã®ããã¯ãã¼ã¯ããè¨äº *1
ããã¤ã¼ããã¦ããã
éç¨ææ
2å¹´å¼±ãéç¨ãã¦ãããã©èªåï¼æé·ããã¨ããæé·ãã¦ãªãã¨ããã¤ãã³ããªã©ï¼ ãæ¯ãè¿ãã¨ã¦ããããã¼ã«ã ãªãã¨æãã¦ããã
ä»åãã£ããã¨
1,2 å¹´åã®çºè¨ã¯ Heroku ã§éç¨ãã¦ãããããã®ãã³Â Herokuã®æéä½ç³»ï¼ç¡ææ ï¼ãå¤æ´ã«ãªãã¨ãããã¨ã§ã DigitalOcean ã«å¼ã£è¶ãã¤ãã§ã« Dockerï¼CoreOSï¼ã§åãããã¨ã«ããã
DegitalOcean *2
DegitalOcean ã¯ãåãã¦ä½¿ã£ãã以ä¸ã®ã¹ã©ã¤ããè¶ çµ¶ããããããã
API ãå å®ãã¦ãã¦ãããããªè¨å®ã»ç®¡çãããã°ã©ããã«ã«ã§ããã ä»åã¯ãVagrant 㧠Droplet ãèµ·åãã¦ã¿ãã vagrant-digitalocean *3 ã使ãã°ãVagrant ã®æ±ãã¨ã»ã¼åãæãã§ã¡ããããã§ãããã試ããã¨ãã§ããã
# Vagrantfile # -*- mode: ruby -*- # vi: set ft=ruby : Dotenv.load if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"] $num_instance = ENV["NUM_INSTANCES"].to_i end Vagrant.configure('2') do |config| config.ssh.username = 'core' (1..$num_instance).each do |i| config.vm.define "core-retrobot-#{i}" do |config| config.vm.provider :digital_ocean do |provider, override| override.ssh.private_key_path = '~/.ssh/id_rsa' override.vm.box = 'digital_ocean' override.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box" provider.token = "#{ENV['TOKEN']}" provider.image = 'coreos-stable' provider.region = 'sgp1' provider.size = '512MB' provider.ssh_key_name = "YOUR SSH KEY NAME" provider.setup = false provider.private_networking = true provider.user_data = File.read('user-data.yml') end end end end
fleet ã使ã£ã¦ã¿ããã£ãã®ã§ã2ã¤ã®Dropletï¼ã¤ã³ã¹ã¿ã³ã¹ï¼ãç«ã¦ã¦ãuser-data.yml ãåããã£ã¬ã¯ããªä»¥ä¸ã«é
ç½®ãã¦ããã
ããã¯ãããªã«ã
èµ·å
$ vagrant up $ vagrant status Current machine states: core-retrobot-1 active (digital_ocean) core-retrobot-2 active (digital_ocean) This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`.
ã¨ã¤ãªã¢ã¹è¨å®ãã¨ã
$ vagrant ssh-config core-retrobot-1 >> ~/.ssh/config $ vagrant ssh-config core-retrobot-2 >> ~/.ssh/config
ãã°ã¤ã³
$ ssh core-retrobot-â»
ããã«ã
CoreOS stable (647.0.0) core@core-retrobot-1 ~ $ docker -v Docker version 1.5.0, build a8a31ef-dirty core@core-retrobot-1 ~ $ etcdctl -v etcdctl version 0.4.6 core@core-retrobot-1 ~ $ fleetctl -version fleetctl version 0.9.2
Dockerå
retrobot ç¨ã®Dockerfile *4 ãã¤ããå¿ è¦ãããã
FROM ruby:2.2.2 ENV LANG C.UTF-8 RUN cd /opt && git clone https://github.com/mirakui/retrobot.git WORKDIR /opt/retrobot RUN bundle install ADD retrobot.yml retrobot.yml ADD tweets tweets # CMD bundle exec get-twitter-oauth-token ENTRYPOINT ["retrobot"] CMD ["-c", "rebtrobot.yml"]
retrobot.yml ã« twitter ã® TOKEN ãªã©ãè¨å® ï¼ tweets.zip ã解åãã¦é ç½®ããã ãã«ããã¦ãpushã
$ docker build -t 7kaji/retrobot . $ docker push 7kaji/retrobot
ãã¡ãããã©ã¤ãã¼ããªãã¸ããªã«ã«ããã
Quay.io ãå©ç¨ããã®ãããããã
retrobot èµ·å
$ docker login
ã¯ã©ã¹ã¿ç¢ºèª
$ fleetctl list-machines
èµ·åï¼Unit ãã¡ã¤ã«ï¼
$ fleetctl start retrobot.service # fleet ã使ããªãå ´å㯠docker run ã§èµ·å
ãã°ç¢ºèª
$ fleetctl journal -f retrobot.service
retrobot.service
# retrobot.service [Unit] Description=Retrobot: tweet what 7kajii tweets in 1 year ago # Requirements After=docker.service [Service] User=core TimeoutStartSec=0 KillMode=none Restart=always RestartSec=5 # Start ExecStartPre=-/usr/bin/docker kill retrobot ExecStartPre=-/usr/bin/docker rm retrobot ExecStart=/usr/bin/docker run --name retrobot 7kaji/retrobot ExecStop=/usr/bin/docker stop retrobot
X-Fleet ã®ã»ã¯ã·ã§ã³ã¯ã使ã£ã¦ããªãã
Unitãã¡ã¤ã«ã«ã¤ãã¦ã¯ã以ä¸ã®è¨äºãã¨ã¦ãä¸å¯§ã§ããããããã
Fleetã®ä½¿ãæ¹ï¼Unitãã¡ã¤ã«ã®æ¸ãæ¹ | SOTA : http://deeeet.com/writing/2014/11/20/fleet/
åä½ç¢ºèª
ã¡ããã¨åãã¦ããã£ã½ããÂ
ãããããã°ã£
— ãªãªããã¬ãã (@white_retro) 2015, 5æ 16
ä»å¾ãããããã¨
- Datadog ã¨ãã使ã£ã¦ç£è¦ã¨ããã¦ã¿ãã
- failover ã¨ãã®å®é¨ï¼etcd, fleet ã®ãã¨ããããç¥ãããï¼
- 1ã¢ã«ã¦ã³ãããåãã¦ããªããããªã«ãããã«æå¹æ´»ç¨ããã ï¼retrobot éç¨åè¨ãã¦ããããããããªãï¼
REF
*1:1å¹´åã® whitech0c0late ã®ããã¯ãã¼ã¯ããè¨äºã¯ãèªåã®ããã¯ãã¼ã¯ãRSS ã¨ãã¦çºä¿¡ï¼ Pipes: Rewire the webï¼ã㦠IFTTT ã§ããã¯ãã¦çºè¨ãã¦ãããããé¢ä¿ãªãã
*2:ããã使ãå§ãããªãããããï¼https://www.digitalocean.com/?refcode=e88d63da1e6d