version: v1.0
name: Publish ALP images
agent:
  machine:
    type: f1-standard-2
    os_image: ubuntu2004
execution_time_limit:
  minutes: 60
global_job_config:
  env_vars:
    - name: DEV_REGISTRIES
      value: quay.io/calico docker.io/calico
  secrets:
    - name: docker
    - name: quay-robot-calico+semaphoreci
  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 ~/{.kerl,.kiex,.npm,.nvm,.phpbrew,.rbenv,.sbt} /opt/{apache-maven*,firefox*,scala} /usr/lib/jvm /usr/local/{aws2,golang,phantomjs*}
      # Semaphore is doing shallow clone on a commit without tags.
      # unshallow it for GIT_VERSION:=$(shell git describe --tags --dirty --always)
      - retry 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
blocks:
  - name: Publish ALP images
    dependencies: []
    skip:
      when: "branch !~ '.+'"
    task:
      jobs:
        - name: Linux multi-arch
          commands:
            - if [ -z "${SEMAPHORE_GIT_PR_NUMBER}" ]; then make -C app-policy cd CONFIRM=true; fi
  - name: Publish ALP multi-arch manifests
    dependencies:
      - Publish ALP images
    skip:
      when: "branch !~ '.+'"
    task:
      jobs:
        - name: Linux multi-arch manifests
          commands:
            - if [ -z "${SEMAPHORE_GIT_PR_NUMBER}" ]; then make -C app-policy push-manifests-with-tag CONFIRM=true; fi
