apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: gpu-operator-ci
  name: operator-image-builder-script
  namespace: gpu-operator-ci
data:
  run_operator_image_builder.sh: |
    #! /bin/bash
    set -ex

    IMAGE_STREAM=image-registry.openshift-image-registry.svc:5000/${IMAGESTREAM_NAME}:${IMAGESTREAM_TAG}

    mkdir /work && cd /work

    git clone ${OPERATOR_GIT_REPO} gpu-operator -b ${OPERATOR_GIT_REF} --depth 1

    cd gpu-operator

    if [ "${BUILDER_FROM_IMAGE}" ]; then
      sed "s|FROM golang:1.13|FROM ${BUILDER_FROM_IMAGE}|" -i ./docker/Dockerfile.ubi8.prod
    fi

    # avoid docker.io quotas ...
    sed -i 's|FROM nvidia/cuda:|FROM nvcr.io/nvidia/cuda:|' ./docker/Dockerfile.ubi8.prod

    make DOCKER="podman --cgroup-manager=cgroupfs" prod-image

    # push the image locally

    AUTH="--tls-verify=false --authfile /tmp/.dockercfg"
    cp /var/run/secrets/openshift.io/push/.dockercfg /tmp
    (echo "{ \"auths\": " ; cat /var/run/secrets/openshift.io/push/.dockercfg ; echo "}") > /tmp/.dockercfg

    podman push $AUTH nvidia/gpu-operator:latest $IMAGE_STREAM

    echo "GPU-operator from $OPERATOR_GIT_REPO / $OPERATOR_GIT_REF pushed to $IMAGE_STREAM"
