// Copyright 2020-present Open Networking Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

def dockerRegistry = params.dockerRegistry ? "${params.dockerRegistry}/" : ""

/* sdfabric-onos-publish pipeline.*/
pipeline {

  /* executor is determined by JJB */
  agent {
    label "${params.buildNode}"
  }

  /* lighweight version of the docker-publish pipeline. */
  stages {

    stage('checkout') {
      steps {
        checkout([
          $class: 'GitSCM',
          userRemoteConfigs: [[ url: "${params.gitUrl}", credentialsId: 'onos-jenkins-ssh', refspec: "$GERRIT_REFSPEC"]],
          branches: [[ name: "$GERRIT_PATCHSET_REVISION", ]],
          extensions: [
            [$class: 'WipeWorkspace'],
            [$class: 'RelativeTargetDirectory', relativeTargetDir: "$GERRIT_PROJECT"],
            [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
            [$class: 'SubmoduleOption', recursiveSubmodules: true],
          ],
        ])
        script {
          current_date = sh(returnStdout: true, script: 'date +%Y-%m-%d').trim()
        }
      }
    }

    stage('build'){
      steps {
        script {
          sshagent(credentials: ['github-onf-bot-ssh-key']) {
            withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
              // Required to pull the bf-sde image.
              withDockerRegistry([url: 'https://registry.opennetworking.org', credentialsId: 'onf-internal-registry']) {
                sh( script: """
                  #!/usr/bin/env bash
                  set -eu -o pipefail

                  # checked out in a subdir so the log can be in WORKSPACE
                  cd "$GERRIT_PROJECT"

                  # set registry/repository variables
                  export DOCKER_REGISTRY="$dockerRegistry"
                  export DOCKER_REPOSITORY="$dockerRepo"

                  # Builds having a build date
                  if [ ! -z "$buildDate" ]; then
                    export DOCKER_TAG_BUILD_DATE="-$current_date"
                  fi

                  # Builds having the profiler enabled
                  if [ ! -z "$PROFILER" ]; then
                    export DOCKER_TAG_PROFILER="-profiler"
                  fi

                  # Build w/extraEnvironmentVars
                  echo "Building image with following vars $extraEnvironmentVars"
                  $extraEnvironmentVars make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
                """)
              }
            }
          }
        }
      }
    }

    stage('push'){
      steps {
        script {
          withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
            sh( script:"""
              #!/usr/bin/env bash
              set -eu -o pipefail

              # checked out in a subdir so the log can be in WORKSPACE
              cd "$GERRIT_PROJECT"

              # set registry/repository variables
              export DOCKER_REGISTRY="$dockerRegistry"
              export DOCKER_REPOSITORY="$dockerRepo"

              # Builds having a build date
              if [ ! -z "$buildDate" ]; then
                export DOCKER_TAG_BUILD_DATE="-$current_date"
              fi

              # Builds having the profiler enabled
              if [ ! -z "$PROFILER" ]; then
                export DOCKER_TAG_PROFILER="-profiler"
              fi

              # Push w/extraEnvironmentVars
              echo "Pushing image with following vars $extraEnvironmentVars"
              $extraEnvironmentVars make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
            """)
          }
        }
      }
    }
  }

  post {
    always {
      archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
      deleteDir()
    }
    failure {
      step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false])
    }
  }
}
