Implement Chapter 6 release gates and immutable deployment

This commit is contained in:
2026-11-13 18:36:19 -05:00
parent 88575c6612
commit 391007464d
6 changed files with 136 additions and 106 deletions
+39 -99
View File
@@ -1,126 +1,66 @@
pipeline {
agent { label 'REPLACE_TRUSTED_AGENT_LABEL' }
agent { label 'chapter6-trusted' }
options {
skipDefaultCheckout()
disableConcurrentBuilds()
timeout(time: 60, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '20'))
timestamps()
}
environment {
APP_DIR = 'secure-delivery'
IMAGE = 'git.sespinal590.dev/group10-startup/pricing'
ANSIBLE_HOST_KEY_CHECKING = 'True'
}
stages {
stage('Checkout') {
stage('Checkout and test') {
steps {
deleteDir()
checkout scm
sh '''
set -eu
git rev-parse HEAD
python3 --version
'''
sh 'bash secure-delivery/delivery.sh test'
}
}
stage('Python Syntax Check') {
stage('Dependency, secret, and image gates') {
steps { sh 'bash secure-delivery/delivery.sh scan' }
}
stage('Publish scanned image') {
steps {
dir('secure-delivery') {
sh '''
set -eu
python3 -m py_compile app.py test_app.py
'''
withCredentials([usernamePassword(credentialsId: 'chapter6-registry-write', usernameVariable: 'REG_USER', passwordVariable: 'REG_TOKEN')]) {
sh 'bash secure-delivery/delivery.sh publish'
}
}
}
stage('Unit Tests') {
stage('Deploy and verify staging') {
steps { script { deployPricing('staging') } }
}
stage('Production approval') {
steps {
dir('secure-delivery') {
sh '''
set -eu
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
python -m unittest -v
'''
script {
if (!env.CHAPTER6_APPROVERS?.trim()) {
error('Configure CHAPTER6_APPROVERS on the restricted release job')
}
def digest = readFile('evidence/digest.txt').trim()
def revision = readFile('evidence/source.txt').trim()
def approver = timeout(time: 20, unit: 'MINUTES') {
input message: "Promote ${revision} / ${digest}? Scans, staging HTTPS checks and Ansible idempotence passed.",
submitter: env.CHAPTER6_APPROVERS, submitterParameter: 'APPROVER'
}
writeFile file: 'evidence/approval.txt', text: "Approved by ${approver}\n"
sh 'date -u +%FT%TZ >> evidence/approval.txt'
}
}
}
stage('Security Gates') {
steps {
error(
'Chapter 6 security gates are not yet configured. ' +
'Sergio must integrate verified dependency and secret ' +
'scanners before enabling release execution.'
)
}
}
stage('Build and Publish') {
when {
branch 'main'
}
steps {
error(
'Release execution is disabled until trusted-agent, ' +
'registry, image scanning, and credential controls ' +
'have been configured and verified.'
)
}
}
stage('Deploy Staging') {
when {
branch 'main'
}
steps {
error(
'Staging deployment requires verified Ansible, SSH, ' +
'immutable image digest, and HTTPS configuration.'
)
}
}
stage('Production Approval') {
when {
branch 'main'
}
steps {
error(
'Production approval must be implemented with an ' +
'authorized submitter restriction and timeout.'
)
}
}
stage('Deploy Production') {
when {
branch 'main'
}
steps {
error(
'Production deployment is disabled until all release ' +
'gates and authorized approval are operational.'
)
}
stage('Deploy and verify production') {
steps { script { deployPricing('production') } }
}
}
post {
always {
echo 'Chapter 6 pipeline execution finished.'
}
success {
echo 'All configured stages passed.'
}
failure {
echo 'Pipeline failed or was blocked by an incomplete gate.'
always { archiveArtifacts artifacts: 'evidence/*', allowEmptyArchive: true }
}
}
def deployPricing(String target) {
withEnv(["TARGET_ENV=${target}"]) {
withCredentials([sshUserPrivateKey(credentialsId: 'chapter6-deploy-ssh', keyFileVariable: 'DEPLOY_KEY', usernameVariable: 'DEPLOY_USER'),
file(credentialsId: 'chapter6-known-hosts', variable: 'DEPLOY_KNOWN_HOSTS')]) {
sh 'bash secure-delivery/delivery.sh deploy'
}
}
}
}