Harden delivery checks and record test-gate evidence
myfileagent-python-ci/pipeline/pr-main This commit looks good

This commit is contained in:
Codex
2026-11-07 21:23:35 +00:00
parent b8a2529ce9
commit 65e401172b
5 changed files with 65 additions and 8 deletions
+25 -6
View File
@@ -13,7 +13,14 @@ git fetch origin main
git merge-base --is-ancestor HEAD origin/main git merge-base --is-ancestor HEAD origin/main
mkdir -p reports releases/generated mkdir -p reports releases/generated
''' '''
script { env.SOURCE_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() } script {
env.SOURCE_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
env.RELEASE_VERSION = sh(script: "python3 -c 'import json; print(json.load(open(\"secure-delivery/release-intent.json\"))[\"version\"])'", returnStdout: true).trim()
if (!(env.RELEASE_VERSION in ['v1', 'v2'])) { error('Unknown release version') }
env.EXPECTED_TOTAL = env.RELEASE_VERSION == 'v1' ? '30' : '36'
def configured = sh(script: "python3 -c 'import json; print(json.load(open(\"secure-delivery/release-intent.json\"))[\"quantity3_total\"])'", returnStdout: true).trim()
if (configured != env.EXPECTED_TOTAL) { error('Release intent total does not match the version') }
}
} }
} }
stage('Tests and dependency audit') { stage('Tests and dependency audit') {
@@ -52,13 +59,25 @@ docker image inspect "$IMAGE_REPO:$SOURCE_COMMIT" --format '{{index .RepoDigests
} }
} }
} }
stage('Pull published digest on target') {
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY', usernameVariable: 'DEPLOY_USER')]) {
sh '''#!/bin/sh
set +x
set -eu
ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$WORKSPACE/secure-delivery/ansible/known_hosts" -i "$DEPLOY_KEY" "$DEPLOY_USER@172.20.0.1" sudo -n docker pull "$RELEASE_IMAGE" > reports/target-pull.txt
cat reports/target-pull.txt
'''
}
}
}
stage('Deploy staging') { stage('Deploy staging') {
steps { steps {
script { writeFile file: 'releases/generated/v1-staging.yml', text: "target_env: staging\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: v1\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: 30\npublic_url: https://staging.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" } script { writeFile file: "releases/generated/${env.RELEASE_VERSION}-staging.yml", text: "target_env: staging\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: ${env.RELEASE_VERSION}\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: ${env.EXPECTED_TOTAL}\npublic_url: https://staging.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" }
withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) { withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
sh '''set +x sh '''set +x
export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" 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 @releases/generated/v1-staging.yml ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/$RELEASE_VERSION-staging.yml
''' '''
} }
} }
@@ -69,7 +88,7 @@ ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansibl
sh '''set +x sh '''set +x
set -eu set -eu
export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" 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 @releases/generated/v1-staging.yml > reports/staging-second-run.txt ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/$RELEASE_VERSION-staging.yml > reports/staging-second-run.txt
cat reports/staging-second-run.txt cat reports/staging-second-run.txt
grep -Eq 'startup[[:space:]]*:.*changed=0[[:space:]]+unreachable=0[[:space:]]+failed=0' reports/staging-second-run.txt grep -Eq 'startup[[:space:]]*:.*changed=0[[:space:]]+unreachable=0[[:space:]]+failed=0' reports/staging-second-run.txt
''' '''
@@ -86,11 +105,11 @@ grep -Eq 'startup[[:space:]]*:.*changed=0[[:space:]]+unreachable=0[[:space:]]+fa
} }
stage('Deploy production') { stage('Deploy production') {
steps { steps {
script { writeFile file: 'releases/generated/v1-production.yml', text: "target_env: production\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: v1\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: 30\npublic_url: https://app.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" } script { writeFile file: "releases/generated/${env.RELEASE_VERSION}-production.yml", text: "target_env: production\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: ${env.RELEASE_VERSION}\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: ${env.EXPECTED_TOTAL}\npublic_url: https://app.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" }
withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) { withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
sh '''set +x sh '''set +x
export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" 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 @releases/generated/v1-production.yml ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/$RELEASE_VERSION-production.yml
''' '''
} }
} }
@@ -0,0 +1,26 @@
pipeline {
agent { label 'assignment8-trusted' }
options { timeout(time: 10, unit: 'MINUTES') }
stages {
stage('Checkout v1') {
steps { git branch: 'assignment8/secure-delivery', url: 'https://myfileagent.tech/myfileagent/myfileagent-pipeline.git' }
}
stage('Controlled failing test') {
steps {
dir('secure-delivery/v1') {
sh '''#!/bin/sh
set -eu
python3 -m venv .test-venv
.test-venv/bin/pip install -r requirements.txt
trap 'git checkout -- test_app.py' EXIT
python3 -c 'from pathlib import Path; p=Path("test_app.py"); s=p.read_text(); old="self.assertEqual(total_price(3), 30)"; assert old in s; p.write_text(s.replace(old,"self.assertEqual(total_price(3), 31)",1))'
.test-venv/bin/python -m unittest -v
'''
}
}
}
stage('Delivery would proceed') {
steps { echo 'This stage must be skipped when tests fail.' }
}
}
}
+9
View File
@@ -73,3 +73,12 @@
- Jenkins assignment8-validation #5 authenticated the Droplet root Docker client with assignment8-registry-read; login succeeded. Docker warned that its root configuration stores credentials without encryption; restrict access and remove after assessment. Actual image pull has not yet been proven. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/5/console . - Jenkins assignment8-validation #5 authenticated the Droplet root Docker client with assignment8-registry-read; login succeeded. Docker warned that its root configuration stores credentials without encryption; restrict access and remove after assessment. Actual image pull has not yet been proven. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/5/console .
- Draft release pipeline parsed and Jenkins build #6 stopped at the protected-main ancestry guard for the unmerged feature commit; image publication and deployment stages were skipped. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/6/console . Added a workspace clean before checkout to prevent old reports being archived in future runs; that revision remains untested. - Draft release pipeline parsed and Jenkins build #6 stopped at the protected-main ancestry guard for the unmerged feature commit; image publication and deployment stages were skipped. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/6/console . Added a workspace clean before checkout to prevent old reports being archived in future runs; that revision remains untested.
- Build #6 used a reused workspace and its post step archived pre-existing reports; those artifacts are stale and must not be presented as build #6 scan evidence. The draft now deletes the workspace before checkout to prevent recurrence; that correction is not yet verified. - Build #6 used a reused workspace and its post step archived pre-existing reports; those artifacts are stale and must not be presented as build #6 scan evidence. The draft now deletes the workspace before checkout to prevent recurrence; that correction is not yet verified.
## 2026-11-07 release draft review
- Verified branch b8a2529 on Gitea, shared services healthy and pricing routes still return 502 while application is absent. Jenkins guard build #7 rejected unmerged source before image publication; no files were archived. https://ci.myfileagent.tech/job/assignment8-validation/7/console
- Extended the local release draft to explicitly pull the published digest on the target and read a reviewed version/expected-total intent for v1 and v2. Jenkins Groovy 2.4 parser accepted syntax only; stages after the source guard, registry publication, promotion, and recovery remain untested. The v2 source is not yet applied.
- Hardened the secret scan to fail if the source archive fails, then directly tested it on the trusted agent: zero findings and exit 0. No claim is made about a new Jenkins pipeline run.
- Registry permission-only check #4 returned token scope write:package; this does not prove glovely can publish to the organization. https://ci.myfileagent.tech/job/assignment8-registry-check/4/console
- Jenkins assignment8-test-gate-demo #1 deliberately changed one pricing assertion in its own workspace; the test failed (30 versus 31), and its following demonstration delivery stage was skipped. The trap restored the test, git diff confirmed no test change, and all three tests subsequently passed directly on the agent. https://ci.myfileagent.tech/job/assignment8-test-gate-demo/1/console
- Supplied v2 starter was tested separately on the trusted agent: all three tests passed. It has not been applied to the reviewed v1 source, committed as v2, built, published, or deployed.
+1
View File
@@ -0,0 +1 @@
{"version": "v1", "quantity3_total": 30}
+4 -2
View File
@@ -1,9 +1,11 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
scanner="a8-secret-${BUILD_NUMBER}" scanner="a8-secret-${BUILD_NUMBER}"
trap 'docker rm -f "$scanner" >/dev/null 2>&1 || true; rm -f secret-report.json' EXIT archive=$(mktemp)
trap 'docker rm -f "$scanner" >/dev/null 2>&1 || true; rm -f secret-report.json "$archive"' EXIT
docker create --name "$scanner" aquasec/trivy@sha256:1c78ed1ef824ab8bb05b04359d186e4c1229d0b3e67005faacb54a7d71974f73 fs --quiet --scanners secret --exit-code 1 --format json /repo >/dev/null docker create --name "$scanner" aquasec/trivy@sha256:1c78ed1ef824ab8bb05b04359d186e4c1229d0b3e67005faacb54a7d71974f73 fs --quiet --scanners secret --exit-code 1 --format json /repo >/dev/null
tar --exclude=./.git --exclude=./secure-delivery/v1/.test-venv --exclude='*/__pycache__' --exclude=./reports --transform='s,^\.,repo,' -cf - . | docker cp - "$scanner":/ tar --exclude=./.git --exclude=./secure-delivery/v1/.test-venv --exclude='*/__pycache__' --exclude=./reports --transform='s,^\.,repo,' -cf "$archive" .
docker cp - "$scanner":/ < "$archive"
set +e set +e
docker start -a "$scanner" > secret-report.json docker start -a "$scanner" > secret-report.json
result=$? result=$?