
stages:
  - build-rpms
  - docker-build-ngx-httpg-voms

build-rpms:
  stage: build-rpms
  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++
    - source .devcontainer/assets/build-library.sh 
    - CI_PROJECT_DIR=$PWD
    - downloadNginx
    - buildHttpgNginxRPM
    - buildVomsModuleRPM
    - cd ${CI_PROJECT_DIR}/docker && mkdir artifacts
    - cp ~/rpmbuild/SRPMS/* artifacts/ 
    - cp ~/rpmbuild/RPMS/x86_64/* artifacts/
  artifacts:
    paths:
      - docker/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-rpms
  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
    - 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
