
stages:
  - build-ngx
  - build-voms
  - docker-build-ngx

build-ngx-httpg-rpm:
  stage: build-ngx
  image: centos:7
  script: 
    - env | sort
    - sh docker/library-scripts/provide-deps.sh
    - 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-voms-rpm:
  stage: build-voms
  image: centos:7
  script:
    - env | sort
    - sh docker/library-scripts/provide-deps.sh
    - 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-container:
  stage: docker-build-ngx
  image: docker:latest
  services:
    - name: docker:dind
      command: ["--tls=false"]
  dependencies:
    - build-ngx-httpg-rpm
    - build-voms-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
    - cp ${CI_PROJECT_DIR}/ngx-artifacts/nginx-1.22.1-1.el7.ngx.x86_64.rpm ${CI_PROJECT_DIR}/docker/
    - cp ${CI_PROJECT_DIR}/voms-artifacts/nginx-module-http-voms-1.22.1-1.el7.x86_64.rpm ${CI_PROJECT_DIR}/docker/
    - 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
