Travis CI通过SSH脚本/主机部署问题

时间:2017-12-18 17:00:20

标签: django ssh travis-ci

我有一个django站点,每次分支合并到master时我都想部署到Digital Ocean服务器。我大部分都在工作,并遵循了这个tutorial

.travis.yml

language: python
python:
- '2.7'
env:
 - DJANGO_VERSION=1.10.3
addons:
   ssh_known_hosts: mywebsite.com
git:
  depth: false
before_install:
- openssl aes-256-cbc -K *removed encryption details* -in travis_rsa.enc -out travis_rsa -d
- chmod 600 travis_rsa
install:
- pip install -r backend/requirements.txt
- pip install -q Django==$DJANGO_VERSION
before_script:
- cp backend/local.env backend/.env
script: python manage.py test
deploy:
  skip_cleanup: true
  provider: script
  script: "./travis-deploy.sh"
  on:
    all_branches: true

travis-deploy.sh - 在travis'deploy'任务调用它时运行

#!/bin/bash

# print outputs and exit on first failure
set -xe

if [ $TRAVIS_BRANCH == "master" ] ; then

    # setup ssh agent, git config and remote
    echo -e "Host mywebsite.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
    eval "$(ssh-agent -s)"
    ssh-add travis_rsa
    git remote add deploy "travis@mywebsite.com:/home/dean/se_dockets"
    git config user.name "Travis CI"
    git config user.email "travis@mywebsite.com"

    git add .
    git status # debug
    git commit -m "Deploy compressed files"
    git push -f deploy HEAD:master
    echo "Git Push Done"
    ssh -i travis_rsa -o UserKnownHostsFile=/dev/null travis@mywebsite.com 'cd /home/dean/se_dockets/backend; echo hello; ./on_update.sh'


else

     echo "No deploy script for branch '$TRAVIS_BRANCH'"

fi

一切正常,直到事情进入“部署”阶段。我不断收到如下错误消息:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for mywebsite.com has changed,
and the key for the corresponding IP address *REDACTED FOR STACK OVERFLOW*
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
* REDACTED FOR STACK OVERFLOW *
Please contact your system administrator.
Add correct host key in /home/travis/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/travis/.ssh/known_hosts:11
  remove with: ssh-keygen -f "/home/travis/.ssh/known_hosts" -R mywebsite.com
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Permission denied (publickey,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Script failed with status 128

有趣 - 如果我重新运行这项工作,'git push'命令将成功推送到部署远程(我的服务器)。但是,部署脚本中的下一步是SSH进入服务器并运行一些postupdate命令将因同样的原因而失败(主机指纹更改或其他内容)。或者,它将要求输入travis@mywebsite.com密码(它没有)并将在输入提示符处挂起。

此外,当我调试Travis CI构建并使用SSH URL时,您将SSH连接到运行Travis CI的机器上 - 我可以通过它连接到我自己的服务器。但是,需要多次尝试才能解决错误。

所以 - 这似乎是一个流动的问题,在重试时会有一些东西从构建持续到下一次导致不同的错误/结尾。

正如您在我的.yml文件和部署脚本中看到的那样,我试图禁用各种主机名检查并将域添加到已知主机等......但都无济于事。

我知道我有99%的东西设置正确,因为当我重新尝试几次时,事情大部分都成功了。

之前有人见过这个吗?

干杯, 迪恩

0 个答案:

没有答案