Upgrade to Pro — share decks privately, control downloads, hide ads and more …

capistrano-bundle_rsync使ったらオートスケールが高速化した話

ryonext
June 17, 2015

 capistrano-bundle_rsync使ったらオートスケールが高速化した話

ryonext

June 17, 2015
Tweet

More Decks by ryonext

Other Decks in Programming

Transcript

  1. ௨ৗσϓϩΠ࣌ͷεΫϦϓτ 15 production: 16 branch: master 17 commands: 18 -

    ssh {Ϣʔβ}@{σϓϩΠαʔό} 'source ~/.bash_profile; branch=master stage=production sh' < deploy.sh DJSDMFZNM
  2. ௨ৗσϓϩΠ࣌ͷεΫϦϓτ 1 #!/bin/sh 2 3 mkdir -p deploy/{app_name} 4 5

    if [ ! -d ./deploy/{app_name}/$branch ] ; then 6 git clone [email protected]:{github_user}/{github_repo} ~/deploy/ {app_name}/$branch 7 fi 8 cd /home/ubuntu/deploy/{app_name}/$branch 9 git fetch 10 git checkout -f origin/$branch 11 bundle 12 bundle exec cap $stage deploy EFQMPZTI
  3. ௨ৗσϓϩΠ࣌ͷεΫϦϓτ 1 set :stage, :production 2 set :branch, ENV['BRANCH_NAME'] ||

    'master' 3 set :rails_env, 'production' 4 5 require 'aws-sdk' 6 7 AWS.config( 8 access_key_id: ENV['AWS_ACCESS_KEY_ID'], 9 secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], 10 region: ‘{region}’ 11 ) 12 13 instances = AWS.ec2.instances.with_tag(:Name, ‘{instance_name}’).select{|i| i.status == :running}.map(&:dns_name) 14 15 role :app, instances, user: 'ubuntu' 16 role :web, instances, user: 'ubuntu' 17 role :db, instances.first, user: 'ubuntu' DPOpHEFQMPZQSPEVDUJPOSC
  4. Φʔτεέʔϧ࣌ 1 #!/bin/bash 2 sudo su - {Ϣʔβ} -c "ssh

    {Ϣʔβ}@{σϓϩΠαʔό} -o StrictHostKeyChecking=no 'source ~/.bash_profile; HOST=`hostname` branch=master stage=autoscale sh /home/ubuntu/deploy/{app_name}/ master/deploy.sh’” >> /tmp/autoscale.log 6TFS%BUB
  5. Φʔτεέʔϧ࣌ DPOpHEFQMPZBVUPTDBMFSC 1 set :stage :production 2 set :rails_env, 'production'

    3 set :host, ENV['HOST'] 4 5 server fetch(:host), user: 'ubuntu', roles: %w{app web db}