global_job_config:
  secrets:
    - name: docker-hub
  prologue:
    commands:
      - checkout
      - export REPO_DIR="$(pwd)"
      - mkdir artifacts
      # 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
      # 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*}
      - echo $DOCKERHUB_PASSWORD | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
      # Disable initramfs update to save space on the Semaphore VM (and we don't need it because we're not going to reboot).
      - sudo apt-get install -y -u crudini
      - sudo crudini --set /etc/initramfs-tools/update-initramfs.conf '' update_initramfs no
      - cat /etc/initramfs-tools/update-initramfs.conf
  epilogue:
    commands:
      - cd "$REPO_DIR"
      - .semaphore/publish-artifacts
