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

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

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

        stage ('build & push') {
            steps {
                container ('nodejs') {
                    sh 'docker build -f Dockerfile --build-arg project=xuhui-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")
          }
        }
    }
}
