【问题标题】:Continuous deployment using Capistrano and Travis-CI使用 Capistrano 和 Travis-CI 进行持续部署
【发布时间】:2014-01-21 21:49:03
【问题描述】:

在关注this Gist 之后,我正在尝试使用 Travis 将 Rails 应用程序部署到 VPS,但遇到了一些问题。我在我的服务器上生成加密的 ssh 密钥,如下所示:

base64 --wrap=0 ~/.ssh/id_rsa > ~/.ssh/id_rsa_base64
ENCRYPTION_FILTER="echo \$(echo \"-\")\$(travis encrypt theodi/uk-postcodes \"\$FILE='\`cat $FILE\`'\" | grep secure:)"
split --bytes=100 --numeric-suffixes --suffix-length=2 --filter="$ENCRYPTION_FILTER" ~/.ssh/id_rsa_base64 id_rsa_

然后,我将生成的加密变量放入我的 .travis.yml 文件中,并将重构后的私钥 before_install 放入,如下所示:

before_install:
  - echo -n $id_rsa_{00..30} >> ~/.ssh/id_rsa_base64
  - base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
  - chmod 600 ~/.ssh/id_rsa
  - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

在像这样成功构建之后,我正在运行cap production deploy

after_success:
  - "[ \"$TRAVIS_BRANCH\" == \"master\" ] && bundle exec cap production deploy"

但我仍然没有快乐。我在 Travis 输出(来自 Capistrano)上得到的错误如下:

INFO [5a729430] Running /usr/bin/env mkdir -p /tmp/uk-postcodes/ on 162.243.77.171
DEBUG [5a729430] Command: ( RAILS_ENV=production /usr/bin/env mkdir -p /tmp/uk-postcodes/ )
cap aborted!
deploy
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/connection_pool.rb:25:in `create_or_reuse_connection'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:173:in `ssh'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:126:in `block in _execute'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `tap'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `_execute'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/rvm1-capistrano3-1.1.1/lib/rvm1/tasks/capistrano3.rake:5:in `block (3 levels) in <top (required)>'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/travis/build/theodi/uk-postcodes/vendor/bundle/ruby/2.0.0/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'

我还在我的服务器上跟踪了auth.log,我看到了错误error: key_read: uudecode

我可能会出错的任何想法? (第一步涉及到一定数量的货物培养,但我想我明白是怎么回事了)

【问题讨论】:

  • 你生成的key,是给你的机器还是给travis机器的?
  • 它们是给我的服务器的。 Travis 会为每次测试运行生成小框,因此无法进行正常的公钥/私钥身份验证。

标签: ruby-on-rails ruby capistrano travis-ci


【解决方案1】:

travis gem(CLI 工具)有一些更新,可以简化编码。 我在博客文章中描述了一种通过 Capistrano 从 Travis 部署应用程序的方法:https://cowbell-labs.com/2014-03-06-capistrano-deploys-from-travis.html

【讨论】:

  • 啊,酷。这听起来很明智。然而,经过一番摆弄(我不得不从解密命令的'$DEPLOY_KEY' 部分删除引号),我仍然收到Authentication failed 错误。我假设这可能与我在 Capistrano 3 上的事实有关?
  • 我也用过 Capistrano 3。capistrano 向服务器进行身份验证时是否会抛出此错误?如果是,则可能是 RSA 密钥设置(服务器上的authorized_keys 文件)存在问题 - 您可以使用此密钥从您的计算机登录吗?
  • 啊,我错过了这一重要信息:“确保将生成的公钥添加到服务器上的 ~/.ssh/authorized_keys 文件中。”但是,现在我从 github 克隆 repo 时遇到问题:Error reading response length from authentication socket. Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
  • 啊,我知道是怎么回事了,我需要将公钥添加到 Github。现在都整理好了。谢谢!
猜你喜欢
  • 2016-01-12
  • 1970-01-01
  • 2014-10-13
  • 2014-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-09
  • 1970-01-01
相关资源
最近更新 更多