我被困在这个教程中:
https://oncletom.io/2016/travis-ssh-deploy/
我的.travis.yml
代码:
language: ruby
sudo: false
rvm:
- 2.2
env:
global:
- domain: <..>
- site_path: <..>
addon:
ssh_known_hosts: <..>
before_script:
- npm install -g bower
- bower install
script: bundle exec jekyll build
before_deploy:
- openssl aes-256-cbc -K $encrypted_<..>_key -iv $encrypted_<..>_iv -in deploy/deploy_key.enc -out /tmp/deploy_key -d
- eval "$(ssh-agent -s)"
- chmod 600 /tmp/deploy_key
- ssh-add /tmp/deploy_key
deploy:
provider: script
skip_cleanup: true
script: "./deploy/deploy.sh"
on:
branch: master
我的结果:
$ openssl aes-256-cbc -K $encrypted_<..>_key -iv $encrypted_<..>_iv -in deploy/deploy_key.enc -out /tmp/deploy_key -d
$ eval "$(ssh-agent -s)"
Agent pid 2583
$ chmod 600 /tmp/deploy_key
$ ssh-add /tmp/deploy_key
Enter passphrase for /tmp/deploy_key:
Done: Job Cancelled
换句话说,作业因超时而取消。重新创建没有密码的密钥会导致此错误:
# <..> SSH-2.0-OpenSSH_7.5
|1|<..>
Creating public keys..
copying site to <..>...
Warning: Permanently added the RSA host key for IP address '<..>' to the list of known hosts.
deploy@<..>'s password:
No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received
The build has been terminated
因此我无法部署该网站。那么问题来了,为什么会卡在密码和密码上呢?我认为安装 ssh 密钥是为了消除密码短语和密码?
下面是相关脚本。
deploy.sh
#!/usr/bin/env bash
set -e
if [ ! "env:$TRAVIS_BRANCH" == "env:master" ]; then
echo not on master, not deploying
exit 0
fi
echo "on master ✓"
if [ -z "$domain" ]; then
echo "domain" variable not set
exit 1
fi
echo "domain: $domain ✓"
if [ -z "$site_path" ]; then
echo "site_path" variable not set
exit 1
fi
echo "site path: $site_path ✓"
echo "zipping _site to site.zip..."
(cd _site/ && zip -r - .) > site.zip 2>/dev/null
echo "Check if public key of the server is in known_hosts"
if [ -z `ssh-keygen -F $domain` ]; then
ssh-keyscan -H $domain | tee -a ~/.ssh/known_hosts
echo "Creating public keys.."
fi
echo "copying site to $domain..."
scp -i /tmp/deploy_key site.zip deploy@$domain:~/site.zip
ssh -i /tmp/deploy_key deploy@$domain 'rm -rf "'$site_path'"/* && unzip ~/site.zip -d "'$site_path'" && rm ~/site.zip'
答案1
是的,我知道这是一个非常古老的问题:)但我最近收到了一些询问,我可以提出一个可行的解决方案。
before_install:
- [...]
- chmod 600 ssh.key
- chmod 700 local-ssh-askpass
- eval `ssh-agent -s`
- DISPLAY=1 SSH_ASKPASS_REQUIRE=force SSH_ASKPASS=./local-ssh-askpass ssh-add ssh.key < /dev/null
你必须 :
- 添加 DISPLAY=1 强制本地询问脚本
- 从 /dev/null 重定向输入
通常 travis 可以接受此密钥并将其添加到代理