OpsWorksのTips集
OpsWorksを使う際のTipsをまとめてみました。 (2015/01/23)
OpsWorks CLI
一度コンソールから実行したコマンドはCLIから実行できます。
##コマンド一覧
$ sudo opsworks-agent-cli list_commands
## クックブック更新
$ sudo opsworks-agent-cli run_command update_custom_cookbooks
## setup
$ sudo opsworks-agent-cli run_command setup
## レシピ実行
$ sudo opsworks-agent-cli run_command execute_recipes COOKBOOK::RECIPE
BerkshelfでCoffeeScript
# Gemfile
source 'https://rubygems.org'
gem 'berkshelf', '3.1.3'
# Berksfile
source 'https://supermarket.getchef.com'
cookbook 'nodejs'
# metadata.rb
depends 'nodejs'
nodejs_npm 'coffee-script'
node[:deploy][‘appshortname’]の例
appshortname
は[Apps]で設定したアプリケーションのShort nameです。
Short nameは後から変更できないので注意しましょう。
ステージング環境を用意する場合はプロダクション環境と同じアプリケーション名にしておいた方が良いです。
{
"deploy_to" => "/srv/www/appshortname",
"chef_provider" => "Timestamped",
"keep_releases" => 5,
"current_path" => "/srv/www/appshortname/current",
"document_root" => "",
"ignore_bundler_groups" => ["test", "development"],
"absolute_document_root" => "/srv/www/appshortname/current/",
"rake" => "/usr/local/bin/rake",
"migrate" => false,
"migrate_command" =>
"if [ -f Gemfile ]; then echo 'OpsWorks: Gemfile found - running migration with bundle exec' && /usr/local/bin/bundle exec /usr/local/bin/rake db:migrate; else echo 'OpsWorks: no Gemfile - running plain migrations' && /usr/local/bin/rake db:migrate; fi",
"rails_env" => "production",
"action" => "deploy",
"user" => "deploy",
"group" => "apache",
"shell" => "/bin/bash",
"home" => "/home/deploy",
"sleep_before_restart" => 0,
"stack" => {"needs_reload" => true},
"enable_submodules" => true,
"shallow_clone" => false,
"delete_cached_copy" => true,
"purge_before_symlink" => ["log", "tmp/pids", "public/system"],
"create_dirs_before_symlink" => ["tmp", "public", "config"],
"symlink_before_migrate" => {},
"symlinks" => {
"system" => "public/system",
"pids" => "tmp/pids",
"log" => "log"
},
"environment" => {
"RAILS_ENV" => nil, "RUBYOPT" => "", "RACK_ENV" => nil, "HOME" => "/home/deploy"
},
"environment_variables" => {},
"ssl_support" => false,
"auto_npm_install_on_deploy" => true,
"nodejs" => {
"restart_command" => "monit restart node_web_app_appshortname",
"stop_command" => "monit stop node_web_app_appshortname",
"port" => 80
},
"application" => "appshortname",
"application_type" => "other",
"auto_bundle_on_deploy" => true,
"deploying_user" => "arn:aws:iam::xxxxxxxxxxx:user/username",
"domains" => ["appshortname"],
"mounted_at" => nil,
"restart_command" => "echo 'restarting app'",
"ssl_certificate" => nil,
"ssl_certificate_key" => nil,
"ssl_certificate_ca" => nil,
"scm" => {
"scm_type" => "other",
"repository" => nil,
"revision" => nil,
"ssh_key" => nil,
"user" => nil,
"password" => nil
},
"database" => {
"host" => "xxx.xxx.xxx.xxx",
"database" => "db",
"port" => 3306,
"username" => "user",
"password" => "password",
"reconnect" => true,
"data_source_provider" => "stack",
"type" => "mysql"
},
"memcached" => {"host" => nil, "port" => 11211}
}