.build_template: &build_definition
  variables:
    # Try to save some time by only grabbing the most recent commit
    GIT_DEPTH: '1'
  stage: build
  image: docker:stable
  services:
    - docker:stable-dind
  script:
    - IMAGE_NAME=${CI_JOB_NAME/build-/}
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker pull $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest || true
    - >
      docker build
      --pull
      --cache-from $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest
      --rm=false
      --tag $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest .
      --file .dockerfiles/$IMAGE_NAME
    - docker push $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest
  allow_failure: true
  retry: 2
  only:
    - schedules

build-alpine:
  <<: *build_definition

build-alpine-edge:
  <<: *build_definition

build-alpine-pages:
  <<: *build_definition

build-alpine-seccomp:
  <<: *build_definition

build-centos-latest:
  <<: *build_definition

build-clang:
  <<: *build_definition

build-debian-oldstable:
  <<: *build_definition

build-debian-stable:
  <<: *build_definition

build-debian-stable-i386:
  <<: *build_definition

build-debian-stable-mdns:
  <<: *build_definition

build-debian-testing:
  <<: *build_definition

build-debian-unstable:
  <<: *build_definition

build-fedora-latest:
  <<: *build_definition

build-fedora-rawhide:
  <<: *build_definition

build-fedora-rawhide-gpsd:
  <<: *build_definition

build-gentoo:
  <<: *build_definition

build-gentoo-hardened:
  <<: *build_definition

build-opensuse-leap:
  <<: *build_definition

build-opensuse-tumbleweed:
  <<: *build_definition

build-python3-rc:
  <<: *build_definition

build-ubuntu-latest:
  <<: *build_definition

build-ubuntu-rolling:
  <<: *build_definition

build-ubuntu-devel:
  <<: *build_definition
