前提・実現したいこと
CDを構築時に起きているエラーで困っています。
CircleCi上でEC2とSSH接続を行いたいです。
Rails 5.0.7
CircleCi 2.0
発生している問題・エラーメッセージ
試しにビルドしたところ以下のようなログがでます。。
/home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as *********@ip: Net::SSH::ConnectionTimeout (SSHKit::Runner::ExecuteError) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as *********@ip: Net::SSH::ConnectionTimeout /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' Caused by: Net::SSH::ConnectionTimeout: Net::SSH::ConnectionTimeout /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/session.rb:92:in `rescue in initialize' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/session.rb:59:in `initialize' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:246:in `new' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:246:in `start' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/connection_pool.rb:63:in `call' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/connection_pool.rb:63:in `with' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:130:in `execute_command' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `tap' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:61:in `test' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/capistrano-rbenv-2.1.6/lib/capistrano/tasks/rbenv.rake:10:in `block (3 levels) in <top (required)>' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `run' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' Caused by: Errno::ETIMEDOUT: Connection timed out - connect(2) for ip /usr/local/lib/ruby/2.5.0/socket.rb:64:in `connect' /usr/local/lib/ruby/2.5.0/socket.rb:64:in `connect_internal' /usr/local/lib/ruby/2.5.0/socket.rb:137:in `connect' /usr/local/lib/ruby/2.5.0/socket.rb:641:in `block in tcp' /usr/local/lib/ruby/2.5.0/socket.rb:227:in `each' /usr/local/lib/ruby/2.5.0/socket.rb:227:in `foreach' /usr/local/lib/ruby/2.5.0/socket.rb:631:in `tcp' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/session.rb:73:in `initialize' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:246:in `new' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:246:in `start' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/connection_pool.rb:63:in `call' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/connection_pool.rb:63:in `with' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:130:in `execute_command' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `tap' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:61:in `test' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/capistrano-rbenv-2.1.6/lib/capistrano/tasks/rbenv.rake:10:in `block (3 levels) in <top (required)>' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `run' /home/circleci/project/vendor/bundle/ruby/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' Tasks: TOP => rbenv:validate
検索したところsshkeyの登録ができていないようなのですが、https://qiita.com/AK4747471/items/882b70f663f4a80ae770
こちらの記事の通り正常に登録できております
(CircleCiの Project/settings/ssh parmition下にEC2に接続するためのpem鍵を登録しております。)
ホストネームをIP,ドメイン,空白と3種類試しましたがうまくいきません。
該当のソースコード
config.yml
1version: 2 # use CircleCI 2.0 2jobs: # a collection of steps 3 build: # runs not using Workflows must have a `build` job as entry point 4 parallelism: 3 # run three instances of this job in parallel 5 docker: # run the steps with Docker 6 - image: circleci/ruby:2.5.1-node-browsers # ...with this image as the primary container; this is where all `steps` will run 7 environment: # environment variables for primary container 8 BUNDLE_JOBS: 3 9 BUNDLE_RETRY: 3 10 BUNDLE_PATH: vendor/bundle 11 RAILS_ENV: test 12 - image: circleci/mysql:5.6 13 environment: 14 MYSQL_ALLOW_EMPTY_PASSWORD: true 15 MYSQL_ROOT_PASSWORD: '' 16 MYSQL_DATABASE: app_test 17 MYSQL_HOST: 127.0.0.1 18 MYSQL_ROOT_HOST: '%' 19 MYSQL_USER: root 20 steps: # a collection of executable commands 21 - checkout # special step to check out source code to working directory 22 23 # Which version of bundler? 24 - run: 25 name: Which bundler? 26 command: bundle -v 27 28 # Restore bundle cache 29 # Read about caching dependencies: https://circleci.com/docs/2.0/caching/ 30 - restore_cache: 31 keys: 32 - rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }} 33 - rails-demo-bundle-v2- 34 35 - run: # Install Ruby dependencies 36 name: Bundle Install 37 command: bundle check --path vendor/bundle || bundle install --deployment 38 39 # Store bundle cache for Ruby dependencies 40 - save_cache: 41 key: rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }} 42 paths: 43 - vendor/bundle 44 45 - run: 46 name: Yarn Install 47 command: yarn install --cache-folder ~/.cache/yarn 48 49 # Store yarn / webpacker cache 50 - save_cache: 51 key: rails-demo-yarn-{{ checksum "yarn.lock" }} 52 paths: 53 - ~/.cache/yarn 54 55 - run: 56 name: Wait for DB 57 command: dockerize -wait tcp://127.0.0.1:3306 -timeout 120s 58 59 - run: bundle exec rake db:create 60 - run: bundle exec rake db:schema:load 61 62 - run: 63 name: Run rspec in parallel 64 command: | 65 bundle exec rspec --profile 10 \ 66 --format RspecJunitFormatter \ 67 --out test_results/rspec.xml \ 68 --format progress \ 69 $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) 70 71 # Save test results for timing analysis 72 - store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/ 73 path: test_results 74 # See https://circleci.com/docs/2.0/deployment-integrations/ for example deploy configs 75 76 - add_ssh_keys: 77 fingerprints: 78 - "41xxxxxxxxxxx"
設定しているKEYではcapistranoでのデプロイ、ssh接続共にできるのを確認しているのでKEY自体が間違っている事はないと思うのですが、ぜひ詳しい方いらっしゃいましたら教えてください!
追記
Circleciのデバック方法を調べCi上に ssh -p でssh接続をするという方法から、
Ci上で ssh -i ~/.ssh/key.pem user@ipでサーバーに接続を試みましたが、No such file or directory.となりました。
回答1件
あなたの回答
tips
プレビュー