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

build-all-rpm:
  stage: build-rpm
  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 artifacts
    - cp ~/rpmbuild/SRPMS/* artifacts/ 
    - cp ~/rpmbuild/RPMS/x86_64/* artifacts/
    - rm -rf ~/rpmbuild/
    - sh rpm/build-voms-rpm.sh
    - cd ${CI_PROJECT_DIR}
    - cp ~/rpmbuild/SRPMS/* artifacts/
    - cp ~/rpmbuild/RPMS/x86_64/* artifacts/
  artifacts:
    paths:
      - artifacts/

build-ngx-httpg-container:
  stage: docker-build-ngx
  image: docker:latest
  services:
    - name: docker:dind
      command: ["--tls=false"]
  dependencies:
    - build-all-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}/artifacts/*.x86_64.rpm ${CI_PROJECT_DIR}/docker/
    - rm ${CI_PROJECT_DIR}/docker/*-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
