0
votes

I am trying to build my docker image as part of my travis ci pipeline and push it up to docker hub.

Looking at travis ci logs seems like everything work but when a command to docker login is executed this error comes up:

0.02s$ if [ "$TRAVIS_BRANCH" == "master" ]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin docker push "$DOCKER_USERNAME"/mysite:travis-$TRAVIS_BUILD_NUMBER; fi
    "docker login" requires at most 1 argument.
    See 'docker login --help'.
    Usage:  docker login [OPTIONS] [SERVER]
    Log in to a Docker registry
    Done. Your build exited with 0.

I have gone through travis docks and the commands in my travis.yml for login are according to the documentation. I have tried googling the error but i cannot see any solutions.

travis.yml:

sudo: required
language: node_js
node_js: 
  - "stable"
cache:
  directories:
    - "node_modules"
services:
  - docker
before_install:
  - docker build -t "$DOCKER_USERNAME"/mysite:travis-$TRAVIS_BUILD_NUMBER .
  - docker ps -a
  - docker images
  - echo "$DOCKER_USERNAME"
  - echo $DOCKER_USERNAME
script:
  - npm test
  - npm run build
  - docker images "$DOCKER_USERNAME"/mysite
after_success:
  - if [ "$TRAVIS_BRANCH" == "master" ]; then
    echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
    docker push "$DOCKER_USERNAME"/mysite:travis-$TRAVIS_BUILD_NUMBER; fi

I have added my travis environment variables for my username and password: enter image description here

I have crated my repository in docker hub as well linked travis and docker hub to github repo. Is there a way to see more logs for each build..? Maybe something I am missing..?

1

1 Answers

1
votes

I see you are trying to run docker build -t "$DOCKER_USERNAME"/mysite:travis-$TRAVIS_BUILD_NUMBER .

To be clear, this will generate a docker tag where the registry is identified by "$DOCKER_USERNAME", the repository in that registry is mysite and the tag is travis-$TRAVIS_BUILD_NUMBER.

The registry section should be of the format registry_url and the repository seems like you want it to be mysite, with a tag of travis-$TRAVIS_BUILD_NUMBER. The use of username in the tag is not expected.

Try formatting for two separate lines, but on a single line in .travis.yml, like this, where everything from if to fi is on a single line. Note the omission of "$DOCKER_USERNAME" in the push command, and the semicolon to separate the docker login and docker push commands from each other. Also note the change in the tag name being pushed. That should resolve.

after_success:
  - if [ "$TRAVIS_BRANCH" == "master" ]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; docker push registry_url/mysite:travis-$TRAVIS_BUILD_NUMBER; fi