stages:
  - source
  - binary
  - test
  - upload

variables:
  DOCKER_IMAGE_BASE: registry.icinga.com/build-docker
  #ICINGA_BUILD_RELEASE_TYPE: testing
  ICINGA_BUILD_TYPE: snapshot

.source: &source
  stage: source
  tags:
    - docker
  image: ${DOCKER_IMAGE_BASE}/${DOCKER_IMAGE}
  script:
    - icinga-build-deb-source
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - 'icinga2.git'
  artifacts:
    paths:
      - build/*
    expire_in: 1 week

.binary: &binary
  stage: binary
  tags:
    - docker
  image: ${DOCKER_IMAGE_BASE}/${DOCKER_IMAGE}
  script:
    - icinga-build-deb-binary
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - ccache/
  artifacts:
    paths:
      - build/*
    expire_in: 1 week

.test: &test
  stage: test
  tags:
    - docker
  image: ${DOCKER_IMAGE_BASE}/${DOCKER_IMAGE}
  script:
    - find build/
    - icinga-build-test

.upload: &upload
  stage: upload
  tags:
    - docker
  image: ${DOCKER_IMAGE_BASE}/upload
  script:
    - find build/
    - icinga-build-upload-aptly
  only:
    - master
    - tags

###################################
# Debian
###################################

# buster
debian/buster:
  <<: *source
  variables:
    DOCKER_IMAGE: debian/buster

debian/buster:x86_64:
  <<: *binary
  variables:
    DOCKER_IMAGE: debian/buster
  dependencies:
    - debian/buster

test/debian/buster:x86_64:
  <<: *test
  variables:
    DOCKER_IMAGE: debian/buster
  dependencies:
    - debian/buster

debian/buster:x86:
  <<: *binary
  variables:
    DOCKER_IMAGE: debian/buster:x86
  dependencies:
    - debian/buster

test/debian/buster:x86:
  <<: *test
  variables:
    DOCKER_IMAGE: debian/buster:x86
  dependencies:
    - debian/buster:x86
    - debian/buster:x86_64

upload/debian/buster:
  <<: *upload
  dependencies:
    - debian/buster:x86
    - debian/buster:x86_64
    - debian/buster

# stretch
debian/stretch:
  <<: *source
  variables:
    DOCKER_IMAGE: debian/stretch

debian/stretch:x86_64:
  <<: *binary
  variables:
    DOCKER_IMAGE: debian/stretch
  dependencies:
    - debian/stretch

test/debian/stretch:x86_64:
  <<: *test
  variables:
    DOCKER_IMAGE: debian/stretch
  dependencies:
    - debian/stretch

debian/stretch:x86:
  <<: *binary
  variables:
    DOCKER_IMAGE: debian/stretch:x86
  dependencies:
    - debian/stretch

test/debian/stretch:x86:
  <<: *test
  variables:
    DOCKER_IMAGE: debian/stretch:x86
  dependencies:
    - debian/stretch:x86
    - debian/stretch:x86_64

upload/debian/stretch:
  <<: *upload
  dependencies:
    - debian/stretch:x86
    - debian/stretch:x86_64
    - debian/stretch

###################################
# Ubuntu
###################################

# hirsute
ubuntu/hirsute:
  <<: *source
  variables:
    DOCKER_IMAGE: ubuntu/hirsute

ubuntu/hirsute:x86_64:
  <<: *binary
  variables:
    DOCKER_IMAGE: ubuntu/hirsute
  dependencies:
    - ubuntu/hirsute

test/ubuntu/hirsute:x86_64:
  <<: *test
  variables:
    DOCKER_IMAGE: ubuntu/hirsute
  dependencies:
    - ubuntu/hirsute

upload/ubuntu/hirsute:
  <<: *upload
  dependencies:
    - ubuntu/hirsute:x86_64
    - ubuntu/hirsute

# groovy
ubuntu/groovy:
  <<: *source
  variables:
    DOCKER_IMAGE: ubuntu/groovy

ubuntu/groovy:x86_64:
  <<: *binary
  variables:
    DOCKER_IMAGE: ubuntu/groovy
  dependencies:
    - ubuntu/groovy

test/ubuntu/groovy:x86_64:
  <<: *test
  variables:
    DOCKER_IMAGE: ubuntu/groovy
  dependencies:
    - ubuntu/groovy

upload/ubuntu/groovy:
  <<: *upload
  dependencies:
    - ubuntu/groovy:x86_64
    - ubuntu/groovy

ubuntu/focal:
  <<: *source
  variables:
    DOCKER_IMAGE: ubuntu/focal

ubuntu/focal:x86_64:
  <<: *binary
  variables:
    DOCKER_IMAGE: ubuntu/focal
  dependencies:
    - ubuntu/focal

test/ubuntu/focal:x86_64:
  <<: *test
  variables:
    DOCKER_IMAGE: ubuntu/focal
  dependencies:
    - ubuntu/focal

upload/ubuntu/focal:
  <<: *upload
  dependencies:
    - ubuntu/focal:x86_64
    - ubuntu/focal

# bionic
ubuntu/bionic:
  <<: *source
  variables:
    DOCKER_IMAGE: ubuntu/bionic

ubuntu/bionic:x86_64:
  <<: *binary
  variables:
    DOCKER_IMAGE: ubuntu/bionic
  dependencies:
    - ubuntu/bionic

test/ubuntu/bionic:x86_64:
  <<: *test
  variables:
    DOCKER_IMAGE: ubuntu/bionic
  dependencies:
    - ubuntu/bionic

ubuntu/bionic:x86:
  <<: *binary
  variables:
    DOCKER_IMAGE: ubuntu/bionic:x86
  dependencies:
    - ubuntu/bionic

test/ubuntu/bionic:x86:
  <<: *test
  variables:
    DOCKER_IMAGE: ubuntu/bionic:x86
  dependencies:
    - ubuntu/bionic:x86
    - ubuntu/bionic:x86_64

upload/ubuntu/bionic:
  <<: *upload
  dependencies:
    - ubuntu/bionic:x86
    - ubuntu/bionic:x86_64
    - ubuntu/bionic

# xenial
ubuntu/xenial:
  <<: *source
  variables:
    DOCKER_IMAGE: ubuntu/xenial

ubuntu/xenial:x86_64:
  <<: *binary
  variables:
    DOCKER_IMAGE: ubuntu/xenial
  dependencies:
    - ubuntu/xenial

test/ubuntu/xenial:x86_64:
  <<: *test
  variables:
    DOCKER_IMAGE: ubuntu/xenial
  dependencies:
    - ubuntu/xenial

ubuntu/xenial:x86:
  <<: *binary
  variables:
    DOCKER_IMAGE: ubuntu/xenial:x86
  dependencies:
    - ubuntu/xenial

test/ubuntu/xenial:x86:
  <<: *test
  variables:
    DOCKER_IMAGE: ubuntu/xenial:x86
  dependencies:
    - ubuntu/xenial:x86
    - ubuntu/xenial:x86_64

upload/ubuntu/xenial:
  <<: *upload
  dependencies:
    - ubuntu/xenial:x86
    - ubuntu/xenial:x86_64
    - ubuntu/xenial
