 pipeline {
  agent {
    node {
      label 'nodejs'
    }
  }

    environment {
        KUBECONFIG_CREDENTIAL_ID = 'devops-kubeconfig'
        REGISTRY = '10.0.6.228:5000'
        DOCKERHUB_NAMESPACE = 'house-manage-yp'
        APP_NAME = 'web-main'
        NAMESPACE = 'house-manage-yp'
    }

    stages {
        stage ('checkout scm') {
            steps {
                checkout(scm)
            }
        }

        stage ('build & push') {
            steps {
                container ('nodejs') {
                    sh 'docker build -f Dockerfile --build-arg project=yangpu-sit -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER .'
                    sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER'
                }
            }
        }

        stage('deploy') {
          steps {
            kubernetesDeploy(configs: 'deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
          }
        }
    }
}
