LoginSignup
5
3

More than 5 years have passed since last update.

aws elastic beanstalkでdeployが失敗する

Posted at

今日ebにdeployを実施したところ、大した修正でも無いのにdeployが失敗するようになってしまった。
deployに失敗するとそのEC2インスタンスはshutdownされて新たに新しいインスタンスがspawnされるため原因を探るのに一苦労した。
ログをtailで追っていくと /opt/elasticbeanstalk/hooks/appdeploy/pre/13_test_for_puma.sh で固まっている。
更に追っていくと 13_test_for_puma.sh から呼んでいる /opt/elasticbeanstalk/support/scripts/check-for-gem.rb で詰まっていた。

#!/usr/bin/env /opt/rubies/ruby-current/bin/ruby
#==============================================================================
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Amazon Software License (the "License"). You may not use
# this file except in compliance with the License. A copy of the License is
# located at
#
#       https://aws.amazon.com/asl/
#
# or in the "license" file accompanying this file. This file is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or
# implied. See the License for the specific language governing permissions
# and limitations under the License.
#==============================================================================
require 'bundler'

Dir.chdir '/var/app/ondeck'
groups = Bundler.definition.groups

begin
    Bundler.definition.resolve_with_cache!
rescue Bundler::GemNotFound
    Bundler.definition(true).resolve_remotely!
end

gems = Bundler.definition.specs_for(groups).collect(&:name)
exit 0 if gems.include? ARGV[0]
exit 1

こいつを実行してみると、 Bundler.definition(true).resolve_remotely! で固まっていた。
Bundler.definition(true).resolve_remotely! が何をやっているのかを調べれては無いけど、timeoutを入れて回避するようにしてみた(この対応で大丈夫なのかよりdeployが通ることを優先)。

.ebextensions/xxx.configcheck-for-gem.rb を上書きするようにして対応。

files:
  "/opt/elasticbeanstalk/support/scripts/check-for-gem.rb":
    mode: "000755"
    owner: "root"
    group: "root"
    content: |
      #!/usr/bin/env /opt/rubies/ruby-current/bin/ruby
      require 'bundler'
      require 'timeout'

      Dir.chdir '/var/app/ondeck'
      groups = Bundler.definition.groups

      begin
          Bundler.definition.resolve_with_cache!
      rescue Bundler::GemNotFound
          begin
              timeout(5) do
                  Bundler.definition(true).resolve_remotely!
              end
          rescue Timeout::Error
              puts $!
          end
      end

      gems = Bundler.definition.specs_for(groups).collect(&:name)
      exit 0 if gems.include? ARGV[0]
      exit 1

deployは通るようになったので原因究明して、そのうち追記する。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3