Skip to content

Travis: docker push at deploy instead of after_success? #12

@junaruga

Description

@junaruga

I found a tip for docker push. This tip can be used for not only multiarch/fedora, but also other multiarch/*.

Right now our .travis.yml's docker push logic is like this.

after_success:
    - |
      if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then
          docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" "$DOCKER_SERVER" && \
              docker push $DOCKER_REPO
      fi

This logic 's challenge is

  • We cat not catch an script failure in the process of after_success. If the error happens in it, the Travis CI still succeeds.

I assume when using deploy: for docker login and docker push, we can catch an error in the deploy, also can write conditional statement like "if branch == master" simply.

https://medium.com/mobileforgood/5-tips-to-optimise-your-travis-ci-file-eced09d2d74e
3. Docker image caching

.travis.yml

before_deploy:
    - echo -n "$REGISTRY_PASS" | docker login -u "$REGISTRY_USER" --password-stdin
deploy:
    provider: script
    script: docker push "$IMAGE_TAG"
    on:
        branch: master

https://docs.travis-ci.com/user/docker/#branch-based-registry-pushes
https://docs.travis-ci.com/user/deployment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions