# Forces travis to use VM insted container, required to be able to build containers.
sudo: required

services:
    - docker

env:
    global:
        # Should be encrypted or set as private travis variables (in travis settings):
        # DOCKER_HUB_EMAIL
        # DOCKER_HUB_USERNAME
        # DOCKER_HUB_PASSWORD

        # Docker repository name
        - DOCKER_REPOSITORY="mendersoftware/api-gateway"

script:
    # Build docker image from docker file
    - sudo docker build -t $DOCKER_REPOSITORY .

before_deploy:
    # Master is always lastest
    - if [ ! -z "$TRAVIS_TAG" ]; then export IMAGE_TAG=$TRAVIS_TAG; else export IMAGE_TAG=$TRAVIS_BRANCH; fi
    - docker tag $DOCKER_REPOSITORY $DOCKER_REPOSITORY:$IMAGE_TAG

    # Upload image to docker registry only on PUSH
    - docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD
    - docker push $DOCKER_REPOSITORY:$IMAGE_TAG

deploy:
    # Force before_deploy for branches
    -
        provider: script
        script: /bin/true 
        on:
            all_branches: true

    # Force before_deploy for tags
    -
        provider: script
        script: /bin/true 
        on:
            tags: true
            all_branches: true
# Forces travis to use VM insted container, required to be able to build containers.
sudo: required

services:
    - docker

env:
    global:
        # Should be encrypted or set as private travis variables (in travis settings):
        # DOCKER_HUB_EMAIL
        # DOCKER_HUB_USERNAME
        # DOCKER_HUB_PASSWORD

        # Docker repository name
        - DOCKER_REPOSITORY="mendersoftware/api-gateway"

before_script:
    # Rename the branch we're on, so that it's not in the way for the
    # subsequent fetch. It's ok if this fails, it just means we're not on any
    # branch.
    - git branch -m temp-branch || true
    # Git trick: Fetch directly into our local branches instead of remote
    # branches.
    - git fetch origin 'refs/heads/*:refs/heads/*'
    # Get last remaining tags, if any.
    - git fetch --tags origin

script:
    # Build docker image from docker file
    - sudo docker build -t $DOCKER_REPOSITORY .

before_deploy:
    # Master is always lastest
    - if [ ! -z "$TRAVIS_TAG" ]; then export IMAGE_TAG=$TRAVIS_TAG; else export IMAGE_TAG=$TRAVIS_BRANCH; fi
    - docker tag $DOCKER_REPOSITORY $DOCKER_REPOSITORY:$IMAGE_TAG

    # Upload image to docker registry only on PUSH
    - docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD
    - docker push $DOCKER_REPOSITORY:$IMAGE_TAG

deploy:
    # Force before_deploy for branches
    -
        provider: script
        script: /bin/true 
        on:
            all_branches: true

    # Force before_deploy for tags
    -
        provider: script
        script: /bin/true 
        on:
            tags: true
            all_branches: true
Fix inability to use branches and tags interchangably.
Fix inability to use branches and tags interchangably.

Changelog: None
Signed-off-by: Kristian Amlie <505e66ae45028a0596c853559221f0b72c1cee21@mender.io>
