【问题标题】:SShpass not allowed with Travis CITravis CI 不允许使用 SShpass
【发布时间】:2016-11-12 16:59:53
【问题描述】:

上下文

我有一个应用程序,我在其中使用单元测试,我需要持续交付它。我选择使用 github + travis + docker。

我的 Docker 容器是一个带有 openSSL 的 Ubuntu 12.04,我无法从外部连接,我对此没有任何问题

当 travis 构建正常时,我需要通过 SSH 连接我的 docker 容器并运行脚本。

问题

其实我在用:

但这根本不起作用,因为 sshpass 不在白名单中。看来我不能使用 before_install 命令,因为我在基于容器的基础架构上。

注意:端口是22,我在拍照的时候错过了。

问题

  • 如何从 travis 连接我的 ssh 容器以部署我的应用程序(仅在目录存在时运行 git clone / git pull 的脚本)
  • 这是用 travis 制作成这样的好方法,还是存在其他东西?

编辑:

travis 新文件:

还有日志

Using worker: worker-linux-968a87ce-1.bb.travis-ci.org:travis-linux-14
system_info
Build system information
Build language: node_js
Build image provisioning date and time
Wed Feb  4 18:22:50 UTC 2015
Operating System Details
Distributor ID: Ubuntu
Description:    Ubuntu 12.04 LTS
Release:    12.04
Codename:   precise
Linux Version
2.6.32-042stab090.5
Cookbooks Version
23bb455 https://github.com/travis-ci/travis-cookbooks/tree/23bb455
GCC version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
LLVM version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Pre-installed Ruby versions
ruby-1.9.3-p551
Pre-installed Node.js versions
v0.10.36
Pre-installed Go versions
1.4.1
Redis version
redis-server 2.8.19
riak version
2.0.2
MongoDB version
MongoDB 2.4.12
CouchDB version
couchdb 1.6.1
Neo4j version
1.9.4
Cassandra version
2.0.9
RabbitMQ Version
3.4.3
ElasticSearch version
1.4.0
Installed Sphinx versions
2.0.10
2.1.9
2.2.6
Default Sphinx version
2.2.6
Installed Firefox version
firefox 31.0esr
PhantomJS version
1.9.8
ant -version
Apache Ant(TM) version 1.8.2 compiled on December 3 2011
mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)
Maven home: /usr/local/maven
Java version: 1.7.0_76, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-042stab090.5", arch: "amd64", family: "unix"
git.checkout
0.26s$ git clone --depth=50 --branch=master git://myPrivateRepo/Project
Cloning into 'user/Project'...
remote: Counting objects: 1363, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 1363 (delta 4), reused 0 (delta 0), pack-reused 1354
Receiving objects: 100% (1363/1363), 874.89 KiB | 0 bytes/s, done.
Resolving deltas: 100% (263/263), done.
Checking connectivity... done.
$ cd user/Project
$ git checkout -qf commitId
1.56s$ nvm install 0.10
######################################################################## 100.0%
Now using node v0.10.38
$ node --version
v0.10.38
$ npm --version
1.4.28
$ nvm --version
0.23.3
before_install
6.72s$ sudo apt-get install sshpass
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libgeos-3.2.2
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  sshpass
0 upgraded, 1 newly installed, 0 to remove and 102 not upgraded.
Need to get 10.5 kB of archives.
After this operation, 56.3 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/universe sshpass amd64 1.05-1 [10.5 kB]
Fetched 10.5 kB in 0s (234 kB/s)
Selecting previously unselected package sshpass.
(Reading database ... 75363 files and directories currently installed.)
Unpacking sshpass (from .../sshpass_1.05-1_amd64.deb) ...
Processing triggers for man-db ...
Setting up sshpass (1.05-1) ...
install
1.12s$ npm install 
npm WARN package.json UnitTest@0.0.0 No description
npm WARN package.json UnitTest@0.0.0 No repository field.
npm WARN package.json UnitTest@0.0.0 No README data
0.95s$ npm test
> UnitTest@0.0.0 test /home/travis/build/user/project
> node test
    First test should fail:   1) First test should fail
  0 passing (8ms)
  1 failing
  1) First test should fail:
      AssertionError: true == false
      + expected - actual
      -true
      +false

      at Context.<anonymous> (test/first.js:8:16)
The command "npm test" exited with 0.
after_success
0.91s$ sudo sshpass -p password ssh root@ip -p 7000
Done. Your build exited with 0.

【问题讨论】:

    标签: ssh continuous-integration travis-ci continuous-deployment


    【解决方案1】:

    sshpass 可以通过添加以下内容安装到 Travis CI 容器中:

    addons:
      apt:
        packages:
        - sshpass
    

    【讨论】:

    • 超级有帮助!通过 90 秒左右不需要 sudo 来加快我的构建速度。
    【解决方案2】:

    我看到您的问题有两种可能的解决方案:

    【讨论】:

    • 我试过了,什么也没发生。没有错误消息,但没有告诉我它正在工作...... :(
    • @Skahrz 您能否发布一个指向您的 .travis 配置文件的链接?您的上一个构建日志也可能会有所帮助。
    • 具有私有信息的私有存储库。我编辑我的帖子给你看截图
    • @Skahrz 谢谢。我不认为 sshpass 会在连接工作时告诉你任何事情。所以它应该在这里工作。现在,您应该尝试使用您的 ssh 连接运行命令来检查。
    • 最后一个问题,如何将命令传递给我连接的 ssh ?如果我在 after_success 中添加新行,它正在使用当前的 travis 服务器
    【解决方案3】:

    您可以使用 SSH 密钥代替 sshpass 吗?这样您就可以简单地使用 SSH 密钥连接到 Docker 容器,而不是使用密码。

    【讨论】:

    • 我会在使用登录名/密码的 SSH 没问题后尝试 SSH 密钥。没有足够的 travis 经验来实际生成一个
    • @Skahrz 您可以在自己的机器上创建一个 SSH 密钥,为您的 Docker 容器配置它并将其上传到安全服务器(例如 S3) - 然后您可以在 Travis 上下载 SSH 密钥(或任何 CI / 环境)。如果您愿意/必须对 URL 进行加密,Travis 支持秘密/加密输入。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 2015-07-28
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 2016-11-11
    相关资源
    最近更新 更多