version: v1.0
name: Publish typha images
agent:
  machine:
    type: e1-standard-4
    os_image: ubuntu1804

execution_time_limit:
  minutes: 60

blocks:
  # Build and push images.
  # We'll only do this on non-PR builds, where we have credentials to do so.
  - name: "Publish typha images"
    skip:
      # Only run on branches, not PRs.
      when: "branch !~ '.+'"
    task:
      prologue:
        commands:
        - checkout
        # Semaphore mounts a copy-on-write FS as /var/lib/docker in order to provide a pre-loaded cache of
        # some images. However, the cache is not useful to us and the copy-on-write FS is a big problem given
        # how much we churn docker containers during the build.  Disable it.
        - sudo systemctl stop docker
        - sudo umount /var/lib/docker && sudo killall qemu-nbd || true
        - sudo systemctl start docker
        # Free up space on the build machine.
        - sudo rm -rf ~/.kiex ~/.phpbrew ~/.rbenv ~/.nvm ~/.kerl ~/.sbt ~/.npm /usr/lib/jvm /opt/firefox* /opt/apache-maven* /opt/scala /usr/local/golang
        # Semaphore is doing shallow clone on a commit without tags.
        # unshallow it for GIT_VERSION:=$(shell git describe --tags --dirty --always)
        - git fetch --unshallow
        - echo $DOCKER_TOKEN | docker login --username "$DOCKER_USER" --password-stdin
        - echo $QUAY_TOKEN | docker login --username "$QUAY_USER" --password-stdin quay.io
        - export BRANCH_NAME=$SEMAPHORE_GIT_BRANCH
      secrets:
      - name: quay-robot-calico+semaphoreci
      - name: docker
      jobs:
      - name: "typha"
        env_vars:
        - name: DEV_REGISTRIES
          value: quay.io/calico docker.io/calico
        commands:
        - if [ -z "${SEMAPHORE_GIT_PR_NUMBER}" ]; then make -C typha image-all cd CONFIRM=true; fi
