196 lines
7.0 KiB
Plaintext
196 lines
7.0 KiB
Plaintext
|
|
pipeline {
|
|
agent { label 'chapter6-mac-agent-secure' }
|
|
|
|
options {
|
|
disableConcurrentBuilds()
|
|
timeout(time: 60, unit: 'MINUTES')
|
|
buildDiscarder(logRotator(numToKeepStr: '5'))
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
checkout scm
|
|
}
|
|
}
|
|
|
|
stage('Secret Security Gate') {
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
export PATH=/opt/homebrew/bin:$PATH
|
|
gitleaks version
|
|
gitleaks git . --redact=100 --exit-code 42
|
|
'''
|
|
}
|
|
}
|
|
|
|
stage('Verify Node.js') {
|
|
steps {
|
|
sh 'node --version'
|
|
sh 'npm --version'
|
|
}
|
|
}
|
|
|
|
stage('Syntax Check') {
|
|
steps {
|
|
dir('app') {
|
|
sh 'npm run check'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Automated Tests') {
|
|
steps {
|
|
dir('app') {
|
|
sh 'npm test'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Verify Python') {
|
|
steps {
|
|
sh 'python3 --version'
|
|
}
|
|
}
|
|
|
|
stage('Dependency Security Audit') {
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
export PATH=/opt/homebrew/bin:$PATH
|
|
export UV_CACHE_DIR="$WORKSPACE/.uv-cache"
|
|
uv tool run --from pip-audit==2.10.1 pip-audit --disable-pip -r pricing-service/requirements-production.lock.txt > pip-audit-report.txt 2>&1 || {
|
|
cat pip-audit-report.txt
|
|
exit 1
|
|
}
|
|
cat pip-audit-report.txt
|
|
'''
|
|
}
|
|
post {
|
|
always {
|
|
archiveArtifacts artifacts: 'pip-audit-report.txt', allowEmptyArchive: false
|
|
}
|
|
}
|
|
}
|
|
stage('Container Security Gate') {
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
export PATH=/opt/homebrew/bin:$PATH
|
|
trivy image --platform linux/amd64 --scanners vuln --severity HIGH,CRITICAL --exit-code 1 --format table --output trivy-report.txt git.nageshwaran.dev/ssw590-startup/startup-pricing@sha256:14d520f6fbe60c9cc5e661551a03e944de3a2ad777a64c316ec397ee765db22d
|
|
'''
|
|
}
|
|
post {
|
|
always {
|
|
archiveArtifacts artifacts: 'trivy-report.txt', allowEmptyArchive: true
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Staging Verification and Smoke Tests') {
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
date -u
|
|
|
|
ssh -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o ConnectTimeout=10 -i "$HOME/.ssh/chapter6_deploy" chapter6deploy@git.nageshwaran.dev verify-staging > staging-verification.txt
|
|
|
|
cat staging-verification.txt
|
|
|
|
python3 -c 'import json; lines=open("staging-verification.txt").read().splitlines(); data=[json.loads(x) for x in lines if x.startswith("{")]; assert len(data)==2; assert data[0]["status"]=="healthy"; assert data[0]["version"]=="v2"; assert data[1]["version"]=="v2"; assert {p["name"]:p["price"] for p in data[1]["plans"]}=={"Starter":5,"Basic":12,"Pro":30,"Enterprise":60}; print("SUCCESS: All staging smoke tests passed")'
|
|
'''
|
|
}
|
|
post {
|
|
always {
|
|
archiveArtifacts artifacts: 'staging-verification.txt', allowEmptyArchive: true
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Production Approval') {
|
|
steps {
|
|
timeout(time: 30, unit: 'MINUTES') {
|
|
script {
|
|
def approver = input(
|
|
message: 'Approve Chapter 6 production promotion?',
|
|
ok: 'Approve Production',
|
|
submitter: 'chapter6-approver',
|
|
submitterParameter: 'APPROVED_BY'
|
|
)
|
|
if (approver != 'chapter6-approver') {
|
|
error('Production approval requires the designated approver')
|
|
}
|
|
echo "Production approved by: ${approver}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Server Authorization') {
|
|
steps {
|
|
timeout(time: 10, unit: 'MINUTES') {
|
|
input message: 'Administrator: confirm server-side authorization is ready',
|
|
ok: 'Authorization Ready',
|
|
submitter: 'chapter6-approver'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Production Promotion') {
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
date -u > production-promotion.txt
|
|
|
|
ssh -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o ConnectTimeout=10 -i "$HOME/.ssh/chapter6_deploy" chapter6deploy@git.nageshwaran.dev promote-production >> production-promotion.txt 2>&1 || {
|
|
cat production-promotion.txt
|
|
exit 1
|
|
}
|
|
|
|
cat production-promotion.txt
|
|
date -u
|
|
'''
|
|
}
|
|
post {
|
|
always {
|
|
archiveArtifacts artifacts: 'production-promotion.txt', allowEmptyArchive: false
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Production HTTPS Verification') {
|
|
steps {
|
|
sh '''
|
|
set -eu
|
|
date -u > production-verification.txt
|
|
curl -fsS --max-time 10 https://pricing.nageshwaran.dev/health > production-health.json
|
|
curl -fsS --max-time 10 https://pricing.nageshwaran.dev/pricing > production-pricing.json
|
|
|
|
python3 -c 'import json; h=json.load(open("production-health.json")); p=json.load(open("production-pricing.json")); assert h["status"]=="healthy" and h["version"]=="v2"; assert p["version"]=="v2"; assert {x["name"]:x["price"] for x in p["plans"]}=={"Starter":5,"Basic":12,"Pro":30,"Enterprise":60}'
|
|
|
|
cat production-health.json production-pricing.json >> production-verification.txt
|
|
echo "SUCCESS: Production HTTPS smoke tests passed" >> production-verification.txt
|
|
cat production-verification.txt
|
|
'''
|
|
}
|
|
post {
|
|
always {
|
|
archiveArtifacts artifacts: 'production-verification.txt,production-health.json,production-pricing.json', allowEmptyArchive: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
echo 'DELIVERY PASSED: Security gates, approval, production promotion and HTTPS verification completed.'
|
|
}
|
|
|
|
failure {
|
|
echo 'CI FAILED: Review the Jenkins console output.'
|
|
}
|
|
}
|
|
}
|