// pipeline {
//     agent { label 'node3' }
//     tools { nodejs 'node' }
//     stages {
//         stage('notify') {
//             steps {
//                 script {
//                     slack_send_start()
//                 }
//             }
//         }
//         // stage('build') {
//         //     steps {
//         //         sh '''
//         //             make dist-latest lvl=dev
//         //         '''
//         //     }
//         // }
//         stage('build sidecar') {
//             steps {
//                 sh '''
//                     cd sidecar
//                     make dist-latest lvl=dev
//                 '''
//             }
//         }
//     }

//     post {
//         success {
//             script {
//                 slack_send_success()
//             }
//         }
//         failure {
//             script {
//                 slack_send_failure()
//             }
//         }
//     }
// }
pipeline {
    agent { label 'node3' }
    tools { nodejs 'node' }
    stages {
        stage('notify') {
            steps {
                script {
                    slack_send_start()
                }
            }
        }
        stage('ensure cli') {
            steps {
                sh '''
                npm install -g gatsby-cli@4.24.0
                gatsby -v
                '''
            }
        }
        stage('build') {
            options {
                timeout(time: 5, unit: 'MINUTES')
            }
            steps {
                git branch: 'main',
                credentialsId: 'tgsiegel-gitlab-ssh',
                url: 'git@gitlab.cs.umd.edu:dawn/dawn-docs.git'
                // gatsby clean

                sh '''
                npm i @lmdb/lmdb-linux-x64
                npm i
                npm run build:internal
            '''
            }
        }

        stage('copy build') {
            options {
                timeout(time: 5, unit: 'MINUTES')
            }
            steps {
                sh '''
                sudo rm -rf /var/www/dawn_docs/public
                sudo cp -r public /var/www/dawn_docs
            '''
            }
        }

        stage('restart nginx') {
            steps {
                sh '''
                sudo service nginx restart
            '''
            }
        }
    }

    post {
        success {
            script {
                slack_send_success()
            }
        }
        failure {
            script {
                slack_send_failure()
            }
        }
    }
}
