まっしろけっけ

めもてきなやーつ

vagrant shareがすごいらしい

vagrant shareが凄いっていうのを見かけたので
早速使ってみた。

最新版をinstall

こちらから1.5.0をDLしてinstallします。

Vagrant Cloudに登録

こちらからアカウントを登録
username + mail address + passwordを入力するだけの簡単な(ry

vagrant upしてみる

こちらこちらの記事で作成していたkitchenを使用

今回はrails serverにアクセスを向けたいのでguest: 80, host: 3001を指定

$ vi Vagrantfile
+ config.vm.network :forwarded_port, guest: 80, host: 3001
$ vagrant up
Vagrant experienced a version conflict with some installed plugins!
This usually happens if you recently upgraded Vagrant. As part of the
upgrade process, some existing plugins are no longer compatible with
this version of Vagrant. The recommended way to fix this is to remove
your existing plugins and reinstall them one-by-one. To remove all
plugins:

    rm -r ~/.vagrant.d/plugins.json ~/.vagrant.d/gems

The error message is shown below:

Bundler could not find compatible versions for gem "celluloid":
  In Gemfile:
    vagrant (= 1.5.0) ruby depends on
      celluloid (>= 0.15.2) ruby

    vagrant-berkshelf (>= 0) ruby depends on
      celluloid (0.14.1)

エラーがでた。
とりあえず言われた通りにする。

$ rm -r ~/.vagrant.d/plugins.json ~/.vagrant.d/gems
$ vagrant up
`unlink': Permission denied - /hogehoge/.vagrant.d/boxes/base/virtualbox
$ sudo rm -rf /hogehoge/.vagrant.d/boxes/base/virtualbox
$ vagrant up
There are errors in the configuration of this machine. Please fix
the following errors and try again:

Vagrant:
* Unknown configuration section 'berkshelf'.
* Unknown configuration section 'omnibus'.

さっき消したからpuluginをもう一回

$ vagrant plugin install vagrant-omnibus
$ vagrant plugin install vagrant-berkshelf
The plugin(s) can't be installed due to the version conflicts below.
This means that the plugins depend on a library version that conflicts
with other plugins or Vagrant itself, creating an impossible situation
where Vagrant wouldn't be able to load the plugins.

You can fix the issue by either removing a conflicting plugin or
by contacting a plugin author to see if they can address the conflict.

Vagrant could not find compatible versions for gem "celluloid":
  In Gemfile:
    vagrant-berkshelf (>= 0) ruby depends on
      celluloid (~> 0.13.0) ruby

    vagrant (= 1.5.0) ruby depends on
      celluloid (0.15.2)

調べたらこんなpull requestがあったのでこのbranchを使用してみる

$ git clone https://github.com/chulkilee/vagrant-berkshelf.git
$ cd vagrant-berkshelf/
$ git branch 26f7477ca66790b5c34c6326eca63147461d0e70
$ git checkout 26f7477ca66790b5c34c6326eca63147461d0e70
$ echo 'require "bundler/gem_tasks"' > Rakefile
$ bundle exec rake build
$ vagrant plugin install pkg/vagrant-berkshelf-1.4.0.dev1.gem
$ vagrant up

ここら辺で何をやっているかはこちらの記事と同じ感じです。
立ち上がったよ!長かった

shareするよ!

shareする前にrails serverを立ち上げとく

$ vagrant ssh 
$ cd /rails_dir
$ rails server

とりあえずlogin

$ vagrant login
Username or Email: 
Password (will be hidden): 

先ほど登録したusername or email + passwordを入力
成功すれば「You're now logged in!」って言われる。

$ vagrant share
==> hoge: Detecting network information for machine...
    hoge: Local machine address: 192.168.50.25
    hoge: Local HTTP port: 3000
    hoge: Local HTTPS port: disabled
==> hoge: Checking authentication and authorization...
==> hoge: Creating Vagrant Share session...
    hoge: Share will be at: slow-dugong-8574
==> hoge: Your Vagrant Share is running! Name: slow-dugong-8574
==> hoge: URL: http://slow-dugong-8574.vagrantshare.com

http://slow-dugong-8574.vagrantshare.com
これがurlなのでブラウザでアクセスしてみましょう。
railsの「Welcome aboard」が表示されると思います。
rails側のlogもアクセスがある度にしっかり流れることが確認出来るかと


f:id:shiro-16:20140314002023p:plain
スマホでアクセスしてもこんな感じでちゃんと表示されます。

気になるパターンを試してみる

rails serverを止めてみる

rails serverを立ち上げて再びアクセス

  • 「Your share has expired. We'll show this page to anyone who visits this link and display the following message:」が表示された。shareに期限があるのか?

もう一回shareしてみる

shareをきってみる

  • 「Your share has expired. We'll show this page to anyone who visits this link and display the following message:」が表示された。

まとめてきな

  • 成功したときは思わず声が出るほどテンションあがったw
  • 今回はvagrant-berkshelfがうまく入らなかったのでごにょごにょやったけど、pull requestがmergeされれば問題なくなるはず
  • お仕事で使う場合は生成されたURLは誰でもアクセス出来ることに注意しないといけないよ(最低限basic認証かけておくとか)
  • 500 Internal Server Errorを返していた状態で勝手にshareが切れていたので、どのタイミングでshareが勝手に切れるのか調査したい
  • まだドキュメントやヘルプを完全に読めていない、share以外にも色々あるみたい