pipeline {
    agent {
        node {
            label 'dongho' // Runs the deployment on the 'dongho' agent
        }
    }

    stages {
        stage('Checkout') {
            steps {
                // Pulls the latest changes from the Git repository
                checkout scm
                
                // Initialize and update Git submodules (necessary for themes like themes/paper)
                sh 'git submodule update --init --recursive'
            }
        }

        stage('Build & Deploy') {
            steps {
                echo 'Building Docker image and starting service...'
                // Build the image and recreate container with minimal downtime
                sh 'docker compose up -d --build --remove-orphans'
            }
        }
    }

    post {
        always {
            // Clean up the temporary Jenkins workspace since the files are baked into the image
            cleanWs()
        }
    }
}
