sue445
2015/12/09 Itamae Meetup #1
だいたい作ったgemの紹介するだけです
specinfra-plain_sudo
(社内gem)drecom-itamae
(社内gem)itamae-plugin-recipe-drecom_rails
(社内gem)itamae-plugin-resource-encrypted_remote_file
(OSS)Ralefileでhosts.ymlを読み込んでrake taskを動的生成
staging:
- hostname: myapp-staging-01
ip_address: xxx.xxx.xxx.xxx
role_suite: staging
production:
- hostname: myapp-01
ip_address: xxx.xxx.xxx.xxx
role_suite: production_master
- hostname: myapp-02
ip_address: xxx.xxx.xxx.xxx
role_suite: production_slave
rake recipe:production # Run itamae recipes to [production] all
rake recipe:production:myapp-01 # Run itamae recipes to [production] myapp-01 (xxx.xxx.xxx.xxx)
rake recipe:production:myapp-02 # Run itamae recipes to [production] myapp-02 (xxx.xxx.xxx.xxx)
rake recipe:staging # Run itamae recipes to [staging] all
rake recipe:staging:myapp-staging-01 # Run itamae recipes to [staging] myapp-staging-01 (xxx.xxx.xxx.xxx)
rake spec:production # Run serverspec tests to [production] all
rake spec:production:myapp-01 # Run serverspec tests to [production] myapp-01 (xxx.xxx.xxx.xxx)
rake spec:production:myapp-02 # Run serverspec tests to [production] myapp-02 (xxx.xxx.xxx.xxx)
rake spec:staging # Run serverspec tests to [staging] all
rake spec:staging:myapp-staging-01 # Run serverspec tests to [staging] myapp-staging-03 (xxx.xxx.xxx.xxx)
sudo /bin/sh -c <元のコマンド>
がうちのインフラだと一部OSでエラーになる
/etc/sudoers
を紐付けるのが原因だと思うんだけど詳細不明itamae ssh
すると /tmpにディレクトリを作れなくてこけるINFO : Starting Itamae...
ERROR : Command mkdir -p /tmp/itamae_tmp failed. (exit status: 1)
ERROR : stdout | ユーザー sueyoshi_go は'/bin/sh -c mkdir -p /tmp/itamae_tmp' を root として sue445-dev-01 上で実行することは許可されていません。すみません。
specinfra-plain_sudo
(社内gem)sudo /bin/sh -c <元のコマンド>
してるところを sudo <元のコマンド>
に整形し直すgemSpecinfra::Backend::DrecomSsh
のように新しいBackendを追加する形式だとitamaeで使えないので Specinfra::Backend::Ssh
にパッチを当てる方式drecom-itamae
(社内gem)disable_sudo
を有効にするラッパ#!/usr/bin/env ruby
require 'itamae/cli'
require 'drecom-itamae'
require 'specinfra/helper/set'
include Specinfra::Helper::Set
set :disable_sudo, true # 【ここだけ追加】
Itamae::CLI.start
module Itamae
class Runner
def initialize_with_enable_sudo(*args)
initialize_without_enable_sudo(*args)
# itamaeの初期化が終わってrecipe実行する直前にsudo使えるようにする
Specinfra.configuration.disable_sudo = false
end
alias_method_chain :initialize, :enable_sudo
end
end
itamae-plugin-recipe-drecom_rails
(社内gem)Railsアプリあるあるミドルのレシピをひとまとめにgemにした
lib
└── itamae
└── plugin
└── recipe
├── drecom_rails
│ ├── cookbooks
│ │ ├── files/
│ │ ├── memcached.rb
│ │ ├── myhome.rb
│ │ ├── nginx.rb
│ │ ├── nodejs.rb
│ │ ├── percona.rb
│ │ ├── redis.rb
│ │ ├── ruby.rb
│ │ ├── setup.rb
│ │ └── templates/
│ ├── roles
│ │ ├── all.rb # ミドル全部入り
│ │ ├── cache.rb # memcachedをインストール
│ │ ├── db.rb # perconaをインストール
│ │ ├── kvs.rb # redisをインストール
│ │ └── web.rb # nginx,nodejsをインストール
│ └── version.rb
└── drecom_rails.rb
incliue_recipe
しているroles/staging.rb
include_recipe "drecom_rails::roles::all"
# アプリで個別に必要なパッケージをインストール
include_recipe "../cookbooks/packages/default.rb"
itamae-plugin-resource-encrypted_remote_file
(OSS)https://github.com/sue445/itamae-plugin-resource-encrypted_remote_file
encrypted_remote_file "/home/deployer/.ssh/id_rsa" do
owner "root"
group "root"
source "remote_files/id_rsa.encrypted"
password ENV["ID_RSA_PASSWORD"]
end
remote_file
とだいたい同じ