
stages:
  - build-nginx-httpg-rpm
  - build-voms-module-rpm
  - docker-build-ngx-httpg-voms

build-ngx-httpg-rpm:
  stage: build-nginx-httpg-rpm
  image: centos:7
  script: 
    - env | sort
    - yum install -y wget openssl-devel zlib-devel pcre2-devel make rpmdevtools rpmlint
    - sh rpm/build-httpg-nginx-rpm.sh
    - cd ${CI_PROJECT_DIR} && mkdir ngx-artifacts
    - cp ~/rpmbuild/SRPMS/* ngx-artifacts/ 
    - cp ~/rpmbuild/RPMS/x86_64/* ngx-artifacts/
  artifacts:
    paths:
      - ngx-artifacts/

build-ngx-voms-module-rpm:
  stage: build-voms-module-rpm
  image: centos:7
  script: 
    - env | sort
    - yum -y install epel-release
    - yum install -y wget openssl-devel zlib-devel pcre2-devel make rpmdevtools rpmlint boost-devel voms-devel gcc-c++
    - sh rpm/build-voms-rpm.sh
    - cd ${CI_PROJECT_DIR} && mkdir voms-artifacts
    - cp ~/rpmbuild/SRPMS/* voms-artifacts/
    - cp ~/rpmbuild/RPMS/x86_64/* voms-artifacts/
  artifacts:
    paths:
      - voms-artifacts/

build-ngx-httpg-voms-module-container:
  stage: docker-build-ngx-httpg-voms
  image: docker:latest
  services:
    - name: docker:dind
      command: ["--tls=false"]
  dependencies:
    - build-ngx-httpg-rpm
    - build-ngx-voms-module-rpm
  script:
    - apk add git bash
    - git clone https://baltig.infn.it/mw-devel/helper-scripts.git helper-scripts
    - cp helper-scripts/scripts/* /usr/local/bin
    - mkdir ${CI_PROJECT_DIR}/docker/artifacts/
    - cp ${CI_PROJECT_DIR}/ngx-artifacts/*.x86_64.rpm ${CI_PROJECT_DIR}/docker/artifacts/
    - cp ${CI_PROJECT_DIR}/voms-artifacts/*.x86_64.rpm ${CI_PROJECT_DIR}/docker/artifacts/
    - rm ${CI_PROJECT_DIR}/docker/artifacts/*-debuginfo*.rpm
    - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
    - export DOCKER_REGISTRY_HOST=${CI_REGISTRY}
    - export DOCKER_REGISTRY_NAMESPACE=${CI_PROJECT_PATH}
    - cd docker && build-docker-image.sh && push-docker-image.sh
