pipeline {
    agent any

    parameters {
        string(name: 'TAG', defaultValue: 'latest', description: 'Image tag to build and push')
    }

    environment {
        REGISTRY = 'atl.vultrcr.com/vllm/vllm-kimi25-eagle'
        REGISTRY_CREDS = credentials('ATL_VCR_VLLM')
    }

    stages {
        stage('Build') {
            steps {
                script {
                    def tag = params.TAG ?: 'latest'
                    sh "docker build -t ${env.REGISTRY}:${tag} ."
                }
            }
        }

        stage('Push') {
            steps {
                script {
                    def tag = params.TAG ?: 'latest'
                    sh """
                        echo '${env.REGISTRY_CREDS_PSW}' | docker login atl.vultrcr.com -u '${env.REGISTRY_CREDS_USR}' --password-stdin
                        docker push ${env.REGISTRY}:${tag}
                    """
                }
            }
        }
    }

    post {
        always {
            sh 'docker logout atl.vultrcr.com || true'
        }
    }
}
