version: v1.0
name: Publish node 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 node 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:
      # The node build takes a long time due to some architectures, so we split it up.
      # TODO: Add support for other architectures
      - name: "Linux amd64"
        env_vars:
        - name: DEV_REGISTRIES
          value: quay.io/calico docker.io/calico
        commands:
        - if [ -z "${SEMAPHORE_GIT_PR_NUMBER}" ]; then make VALIDARCHES=amd64 -C node image-all cd-common CONFIRM=true; fi

      - name: "windows"
        env_vars:
        - name: DEV_REGISTRIES
          value: quay.io/calico docker.io/calico
        commands:
        - if [ -z "${SEMAPHORE_GIT_PR_NUMBER}" ]; then make -C node build-windows-upgrade-archive image-tar-windows-all cd-windows-all CONFIRM=true; fi
