5

Context

I have an application in which, I m using unit tests and I need to continuous deliver this. I chose to use github + travis + docker.

My Docker container is an Ubuntu 12.04 with openSSL that I cant connect from outside, and I dont have any problem with this

I need, when the travis build is okay, to connect my docker container via SSH and to run a script.

Problem

Actually, I m using :

enter image description here

But this doesn't work at all, because sshpass is not in the whitelist. It seems that I cant you before_install command, because I m on a container based infrastructure.

NB : The port is 22, I missed it during the picture taken.

Questions

  • How can I do to connect my ssh container from travis to deploy my app (only run a script that git clone / git pull if the directory exists)
  • Is this a good way to make it like this with travis, or does it exist something else ?

EDIT :

The travis new file : enter image description here

And the log

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.
mfrachet
  • 8,772
  • 17
  • 55
  • 110

3 Answers3

2

sshpass can be installed in a Travis CI container by adding:

addons:
  apt:
    packages:
    - sshpass
xsc27
  • 146
  • 1
  • 3
1

I see two possible solutions to your problem:

Guillaume Pascal
  • 845
  • 1
  • 9
  • 19
  • I tried, nothing happened. No error message, but nothing telling me that it's working... :( – mfrachet Jun 16 '15 at 06:04
  • @Skahrz Could you please post a link to your .travis config file? Your last build log may also help too. – Guillaume Pascal Jun 16 '15 at 06:36
  • Private repository with private informations. I edit my post to show you with screenshots – mfrachet Jun 16 '15 at 06:37
  • @Skahrz Thanks. I don't think sshpass will tell you anything when the connection worked. So it should have worked here. Now, you should try to run a command using your ssh connection to check. – Guillaume Pascal Jun 16 '15 at 07:05
  • Last question so, how Can I pass command to my connected ssh ? If I add new lines in after_success, it's using the current travis server – mfrachet Jun 16 '15 at 09:04
  • I am not very familiar with sshpass, but I found this: https://stackoverflow.com/questions/19302572/how-to-put-sshpass-command-inside-a-bash-script As you can see in the question, to run a single command, you just need to append it to your sshpass command. If you want to run several commands on the remote server, you will have to use a delimiter as shown in this answer (same topic) http://stackoverflow.com/a/19302674/4186872 And as shown in the answer, it should be a good idea to put the whole result (connection+commands) into a separated script and call this script in your travis config – Guillaume Pascal Jun 16 '15 at 16:51
  • sshpass will actually display what is run (if and when it connects) in the travis CI console output. – risa_risa Sep 08 '15 at 20:33
0

Can you use an SSH key instead of sshpass? That way you can simply use the SSH key to connect to the Docker container instead of using a password.

Viktor Benei
  • 3,447
  • 2
  • 28
  • 37
  • I will try SSH Key after I'll be okay with SSH with login / password. Not enough experience with travis to generate one actually – mfrachet Jun 16 '15 at 06:05
  • @Skahrz you can create an SSH key on your own machine, configure it for your Docker container and upload it to a secure server (S3 for example) - you can then just download the SSH key on Travis (or any CI / environment). The URL can be encrypted if you want to / have to, Travis supports secret/encrypted inputs. – Viktor Benei Jun 16 '15 at 12:47