before_script:
  - echo $NGINX_VERSION
  - echo $NGINX_BINARY

  # Relies on latest binary build artifact from https://git.ethitter.com/debian/nginx-build.
  - curl -o nginx-build "${NGINX_BINARY}"
  - chmod +x nginx-build
  - ./nginx-build -V

after_script:
  - mkdir -p ${CI_PROJECT_DIR}/${BUILD_DIR}
  - mv $CI_PROJECT_DIR/nginx_${NGINX_VERSION}* $BUILD_DIR
  - mv $CI_PROJECT_DIR/nginx-dbgsym_* $BUILD_DIR

build-deb:jessie:
  stage: build
  image: containers.ethitter.com:443/docker/images/debian:jessie
  variables:
    NGINX_BINARY: $NGINX_BINARY_JESSIE
    NGINX_VERSION: $NGINX_VERSION_JESSIE
    BUILD_DIR: 'build-jessie'
  script:
    - cd source
    - debuild -us -uc
  artifacts:
    paths:
      - $BUILD_DIR

test-deb:jessie:
  stage: test
  image: containers.ethitter.com:443/docker/images/debian:jessie
  before_script:
    - export BUILD_DIR="${CI_PROJECT_DIR}/build-jessie"
  script:
    - dpkg -i ${BUILD_DIR}/nginx_${NGINX_VERSION_JESSIE}*.deb
    - nginx -V
  after_script:
    - ''
  dependencies:
    - build-deb:jessie

build-deb:stretch:
  stage: build
  image: containers.ethitter.com:443/docker/images/debian:stretch
  variables:
    NGINX_BINARY: $NGINX_BINARY_STRETCH
    NGINX_VERSION: $NGINX_VERSION_STRETCH
    BUILD_DIR: 'build-stretch'
  script:
    - cd source
    - debuild -us -uc
  artifacts:
    paths:
      - $BUILD_DIR

test-deb:stretch:
  stage: test
  image: containers.ethitter.com:443/docker/images/debian:stretch
  before_script:
    - export BUILD_DIR="${CI_PROJECT_DIR}/build-stretch"
  script:
    - dpkg -i ${BUILD_DIR}/nginx_${NGINX_VERSION_STRECTH}*.deb
    - nginx -V
  after_script:
    - ''
  dependencies:
    - build-deb:stretch

build-deb:buster:
  stage: build
  image: containers.ethitter.com:443/docker/images/debian:buster
  variables:
    NGINX_BINARY: $NGINX_BINARY_BUSTER
    NGINX_VERSION: $NGINX_VERSION_BUSTER
    BUILD_DIR: 'build-buster'
  script:
    - cd source
    - debuild -us -uc
  artifacts:
    paths:
      - $BUILD_DIR

test-deb:buster:
  stage: test
  image: containers.ethitter.com:443/docker/images/debian:buster
  before_script:
    - export BUILD_DIR="${CI_PROJECT_DIR}/build-buster"
  script:
    - dpkg -i ${BUILD_DIR}/nginx_${NGINX_VERSION_BUSTER}*.deb
    - nginx -V
  after_script:
    - ''
  dependencies:
    - build-deb:buster

aptly:
  stage: deploy
  image: containers.ethitter.com:443/docker/images/debian:stretch
  before_script:
    - ''
  script:
    - find ./ -name "*.deb" -exec tar -rvf packages.tar {} \;
    - gzip -9 packages.tar
    - ls -la packages.tar.gz
  after_script:
    - ''
  artifacts:
    paths:
      - packages.tar.gz
    expire_in: 3 hours
