Document secure delivery evidence and production monitoring
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
pipeline {
|
||||
agent { label 'assignment8-trusted' }
|
||||
options { disableConcurrentBuilds(); timeout(time: 45, unit: 'MINUTES'); timestamps() }
|
||||
stages {
|
||||
stage('Prepare reviewed v1 configuration') {
|
||||
steps {
|
||||
deleteDir()
|
||||
git url: 'https://myfileagent.tech/myfileagent/myfileagent-pipeline.git', branch: 'main'
|
||||
sh '''set -eu
|
||||
git checkout --detach 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2
|
||||
test "$(git rev-parse HEAD)" = 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2
|
||||
mkdir -p reports
|
||||
cat > reports/v1-production.yml <<'EOF'
|
||||
target_env: production
|
||||
release_image: myfileagent.tech/myfileagent/pricing@sha256:715a3c80d5fff4319e275583e73e58cd80bffadea6e25796dd4867135ff036c2
|
||||
expected_version: v1
|
||||
expected_commit: 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2
|
||||
configuration_commit: 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2
|
||||
expected_total: 30
|
||||
public_url: https://app.myfileagent.tech
|
||||
proxy_network: myfileagent-gitea_gitea-private
|
||||
EOF
|
||||
curl -fsS https://app.myfileagent.tech/ > reports/before-identity.json
|
||||
curl -fsS 'https://app.myfileagent.tech/price?quantity=3' > reports/before-price.json
|
||||
python3 -c 'import json; a=json.load(open("reports/before-identity.json")); p=json.load(open("reports/before-price.json")); assert a["version"]=="v2" and a["commit"]=="ee128d18bddd1763b916b40f05829f2e769f0654" and p["total"]==36'
|
||||
'''
|
||||
}
|
||||
}
|
||||
stage('Human rollback approval') {
|
||||
steps {
|
||||
script {
|
||||
def approver = timeout(time: 30, unit: 'MINUTES') { input message: 'Approve the Assignment 8 production rollback exercise from verified v2/36 to v1/30 using configuration 0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2 and image sha256:715a3c80d5fff4319e275583e73e58cd80bffadea6e25796dd4867135ff036c2? Recreating the container may interrupt traffic.', ok: 'Roll back', submitter: 'ssw590', submitterParameter: 'APPROVER' }
|
||||
writeFile file: 'reports/approval.txt', text: "Approver: ${approver}\nDecision: approved\nTime UTC: ${sh(script: 'date -u +%FT%TZ', returnStdout: true).trim()}\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Roll back and verify') {
|
||||
steps {
|
||||
withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
|
||||
sh '''#!/bin/sh
|
||||
set +x
|
||||
set -eu
|
||||
export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts"
|
||||
(
|
||||
while :; do
|
||||
stamp=$(date -u +%FT%TZ)
|
||||
code=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 https://app.myfileagent.tech/health 2>/dev/null || true)
|
||||
printf '%s %s\n' "$stamp" "$code" >> reports/availability-samples.txt
|
||||
sleep 1
|
||||
done
|
||||
) &
|
||||
probe=$!
|
||||
trap 'kill "$probe" 2>/dev/null || true; wait "$probe" 2>/dev/null || true' EXIT
|
||||
date -u +%FT%TZ > reports/rollback-start.txt
|
||||
ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @reports/v1-production.yml > reports/rollback-ansible.txt 2>&1
|
||||
date -u +%FT%TZ > reports/rollback-verified.txt
|
||||
curl -fsS https://app.myfileagent.tech/health > reports/after-health.json
|
||||
curl -fsS https://app.myfileagent.tech/ > reports/after-identity.json
|
||||
curl -fsS 'https://app.myfileagent.tech/price?quantity=3' > reports/after-price.json
|
||||
python3 -c 'import json; h=json.load(open("reports/after-health.json")); a=json.load(open("reports/after-identity.json")); p=json.load(open("reports/after-price.json")); assert h["status"]=="ok" and a["version"]=="v1" and a["commit"]=="0cb5a34cc4c2709ea3eb95f58bf5b0b2fa350ef2" and p["total"]==30'
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post { always { archiveArtifacts artifacts: 'reports/*', allowEmptyArchive: true } }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
pipeline {
|
||||
agent { label 'assignment8-trusted' }
|
||||
options { disableConcurrentBuilds(); timeout(time: 20, unit: 'MINUTES'); timestamps() }
|
||||
stages {
|
||||
stage('Prepare staging-only failure') {
|
||||
steps {
|
||||
deleteDir()
|
||||
git url: 'https://myfileagent.tech/myfileagent/myfileagent-pipeline.git', branch: 'assignment8/staging-failure-exercise'
|
||||
sh '''set -eu
|
||||
test "$(git rev-parse HEAD)" = c0cdd9159b430b8a27543a293cdd23aa05c8ee34
|
||||
mkdir -p reports
|
||||
cat > reports/staging.yml <<'EOF'
|
||||
target_env: staging
|
||||
release_image: myfileagent.tech/myfileagent/pricing@sha256:2ab86894ada4c12bd066ae1d29be40a296b1a037f379c494dead5cad4d8b88f9
|
||||
expected_version: v2
|
||||
expected_commit: ee128d18bddd1763b916b40f05829f2e769f0654
|
||||
configuration_commit: c0cdd9159b430b8a27543a293cdd23aa05c8ee34
|
||||
expected_total: 36
|
||||
public_url: https://staging.myfileagent.tech
|
||||
proxy_network: myfileagent-gitea_gitea-private
|
||||
EOF
|
||||
date -u +%FT%TZ > reports/failure-start.txt
|
||||
'''
|
||||
}
|
||||
}
|
||||
stage('Deploy deliberate mismatch') {
|
||||
steps {
|
||||
withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
|
||||
sh '''#!/bin/sh
|
||||
set +x
|
||||
set -eu
|
||||
export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts"
|
||||
ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @reports/staging.yml > reports/failure-ansible.txt 2>&1
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Must not run after failure') { steps { error('Unexpected success: the staging failure did not block the pipeline') } }
|
||||
}
|
||||
post { always { archiveArtifacts artifacts: 'reports/*', allowEmptyArchive: true } }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
pipeline {
|
||||
agent { label 'assignment8-trusted' }
|
||||
options { disableConcurrentBuilds(); timeout(time: 20, unit: 'MINUTES'); timestamps() }
|
||||
stages {
|
||||
stage('Restore reviewed staging configuration') {
|
||||
steps {
|
||||
deleteDir()
|
||||
git url: 'https://myfileagent.tech/myfileagent/myfileagent-pipeline.git', branch: 'main'
|
||||
sh '''set -eu
|
||||
git checkout --detach ee128d18bddd1763b916b40f05829f2e769f0654
|
||||
test "$(git rev-parse HEAD)" = ee128d18bddd1763b916b40f05829f2e769f0654
|
||||
mkdir -p reports
|
||||
cat > reports/staging.yml <<'EOF'
|
||||
target_env: staging
|
||||
release_image: myfileagent.tech/myfileagent/pricing@sha256:2ab86894ada4c12bd066ae1d29be40a296b1a037f379c494dead5cad4d8b88f9
|
||||
expected_version: v2
|
||||
expected_commit: ee128d18bddd1763b916b40f05829f2e769f0654
|
||||
configuration_commit: ee128d18bddd1763b916b40f05829f2e769f0654
|
||||
expected_total: 36
|
||||
public_url: https://staging.myfileagent.tech
|
||||
proxy_network: myfileagent-gitea_gitea-private
|
||||
EOF
|
||||
date -u +%FT%TZ > reports/recovery-start.txt
|
||||
'''
|
||||
withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
|
||||
sh '''#!/bin/sh
|
||||
set +x
|
||||
set -eu
|
||||
export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts"
|
||||
ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @reports/staging.yml > reports/recovery-ansible.txt 2>&1
|
||||
date -u +%FT%TZ > reports/recovery-verified.txt
|
||||
curl -fsS https://staging.myfileagent.tech/health > reports/health.json
|
||||
curl -fsS https://staging.myfileagent.tech/ > reports/identity.json
|
||||
curl -fsS 'https://staging.myfileagent.tech/price?quantity=3' > reports/price.json
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post { always { archiveArtifacts artifacts: 'reports/*', allowEmptyArchive: true } }
|
||||
}
|
||||
Reference in New Issue
Block a user