Docs/chapter 11 #26

Merged
samahk13 merged 2 commits from docs/chapter-11 into main 2026-11-13 20:58:40 +00:00
11 changed files with 686 additions and 22 deletions
Vendored
+164 -16
View File
@@ -1,40 +1,188 @@
// CI pipeline for Scrap-Web (SSW 590, Continuous Integration with Jenkins). // Scrap-Web pipeline: Chapter 4 CI checks + Chapter 6 secure delivery.
// Runs for every pull request through the Multibranch Pipeline job and reports //
// its result to Gitea as a commit status. Uses only the Python 3 standard // Trust boundary:
// library, so no packages are downloaded during the build. // * Every build (branches and pull requests) runs the Chapter 4 checks on the
// controller's built-in node. No credentials, no Docker socket.
// * Delivery stages run only for trusted branches, on the 'delivery' agent,
// which holds the Docker socket and the registry/deploy credentials.
// TODO before submission: remove the feature branch from TRUSTED_BRANCH so
// only reviewed code on main can deliver.
def TRUSTED_BRANCH = 'main|feature/issue-24-delivery'
pipeline { pipeline {
// Builds run on the Jenkins controller executor (see the IT manual for the agent none
// documented risk). python3 must be installed in the Jenkins container.
agent any
options { options {
skipDefaultCheckout() skipDefaultCheckout()
timeout(time: 10, unit: 'MINUTES') disableConcurrentBuilds() // no competing releases
timeout(time: 30, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '50'))
} }
environment {
REGISTRY = 'git.ssw590-08.me'
IMAGE = 'git.ssw590-08.me/ssw-590-08/pricing'
}
stages {
// ---------------- Chapter 4 CI (all builds, controller) ----------------
stage('CI checks') {
agent { label 'built-in' }
steps {
checkout scm
sh 'git rev-parse HEAD'
sh 'python3 --version'
sh 'python3 -m py_compile pricing.py tests/test_pricing.py'
sh 'python3 -m unittest discover -s tests -v'
}
}
// ---------------- Chapter 6 delivery (trusted branches, agent) ---------
stage('Delivery') {
when { beforeAgent true; branch pattern: TRUSTED_BRANCH, comparator: 'REGEXP' }
agent { label 'delivery' }
stages { stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
checkout scm checkout scm
// Record exactly which commit is being tested, for traceability. script {
sh 'git rev-parse HEAD' env.APP_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
sh 'python3 --version' env.IMAGE_TAG = "${env.IMAGE}:${env.APP_COMMIT}"
}
echo "Source commit: ${env.APP_COMMIT}"
} }
} }
stage('Syntax check') {
stage('Unit tests') {
steps { steps {
sh 'python3 -m py_compile pricing.py tests/test_pricing.py' dir('pricing') {
sh '''
python3 -m venv .venv
.venv/bin/pip install -q --require-hashes -r requirements.txt
.venv/bin/python -m py_compile app.py test_app.py
.venv/bin/python -m unittest -v
'''
} }
} }
stage('Test') { }
// 6.4.5 (kholmes): dependency + secret checks on the source.
stage('Security scan: source') {
steps { steps {
sh 'python3 -m unittest discover -s tests -v' sh '''
if [ -x security/scan.sh ]; then
security/scan.sh source
else
echo "security/scan.sh not added yet (6.4.5)"
fi
'''
}
}
stage('Build image') {
steps {
dir('pricing') {
sh 'docker build --build-arg APP_COMMIT="$APP_COMMIT" -t "$IMAGE_TAG" .'
}
}
}
// 6.4.5 (kholmes): image vulnerability scan before publishing.
stage('Security scan: image') {
steps {
sh '''
if [ -x security/scan.sh ]; then
security/scan.sh image "$IMAGE_TAG"
else
echo "security/scan.sh not added yet (6.4.5)"
fi
'''
}
}
stage('Publish') {
steps {
withCredentials([usernamePassword(credentialsId: 'gitea-registry-push',
usernameVariable: 'REG_USER',
passwordVariable: 'REG_TOKEN')]) {
// Push, then delete the local copy and pull it back from the
// registry, so the recorded digest is the registry's, not a local ID.
sh '''
printf '%s' "$REG_TOKEN" | docker login "$REGISTRY" -u "$REG_USER" --password-stdin
docker push "$IMAGE_TAG"
docker image rm "$IMAGE_TAG"
docker pull "$IMAGE_TAG"
docker logout "$REGISTRY"
docker image inspect "$IMAGE_TAG" --format '{{index .RepoDigests 0}}' > image-digest.txt
echo "Published: $(cat image-digest.txt)"
'''
}
script { env.IMAGE_DIGEST = readFile('image-digest.txt').trim() }
writeFile file: 'build-record.txt', text: """source_commit: ${env.APP_COMMIT}
image_tag: ${env.IMAGE_TAG}
image_digest: ${env.IMAGE_DIGEST}
jenkins_build: ${env.BUILD_URL}
"""
archiveArtifacts artifacts: 'image-digest.txt, build-record.txt', fingerprint: true
}
}
// 6.4.6: deploy the digest just published to staging with Ansible,
// then rerun unchanged and require changed=0 (idempotence).
stage('Deploy staging') {
steps {
script {
// Expected behaviour comes from the source, not from config.
def version = sh(script: "sed -n 's/^VERSION = \"\\(.*\\)\"/\\1/p' pricing/app.py", returnStdout: true).trim()
def unit = sh(script: "sed -n 's/^UNIT_PRICE = //p' pricing/app.py", returnStdout: true).trim()
env.APP_VERSION = version
writeFile file: "release-${version}-staging.yml", text: """target_env: staging
release_image: ${env.IMAGE_DIGEST}
expected_version: ${version}
expected_commit: ${env.APP_COMMIT}
expected_total: ${3 * (unit as Integer)}
public_url: https://staging.ssw590-08.me
proxy_network: gitea-net
"""
}
archiveArtifacts artifacts: "release-${env.APP_VERSION}-staging.yml", fingerprint: true
withCredentials([sshUserPrivateKey(credentialsId: 'deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
sh '''
export PATH=/opt/ansible-venv/bin:$PATH
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml \
--private-key "$DEPLOY_KEY" -e @release-$APP_VERSION-staging.yml
'''
}
}
}
stage('Staging idempotence') {
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
sh '''
export PATH=/opt/ansible-venv/bin:$PATH
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml \
--private-key "$DEPLOY_KEY" -e @release-$APP_VERSION-staging.yml | tee rerun.log
grep -E 'startup +: .*changed=0 +unreachable=0 +failed=0' rerun.log \
|| { echo "Second run changed something: not idempotent"; exit 1; }
'''
}
}
}
// 6.4.7 (kholmes): approval + production deploy.
stage('Approve and deploy production') {
steps { echo 'Not implemented yet (6.4.7).' }
}
} }
} }
} }
post { post {
success { echo 'All checks passed.' } success { echo 'All stages passed.' }
failure { echo 'A stage failed: see the stage view for which one.' } failure { echo 'A stage failed: see the stage view for which one.' }
} }
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

+4 -3
View File
@@ -41,10 +41,10 @@
\newcommand{\CourseName}{DevOps} \newcommand{\CourseName}{DevOps}
\newcommand{\Instructor}{Samah Keshiro and Kayla Holmes} \newcommand{\Instructor}{Samah Keshiro and Kayla Holmes}
\newcommand{\Organization}{Stevens Institute of Technology} \newcommand{\Organization}{Stevens Institute of Technology}
\newcommand{\DocumentDate}{October 29, 2026} \newcommand{\DocumentDate}{November 13, 2026}
\newcommand{\DueDate}{[Due Date and Time]} \newcommand{\DueDate}{[Due Date and Time]}
\newcommand{\VERSION}{Version 1.6} \newcommand{\VERSION}{Version 1.7 (draft)}
\newcommand{\AssignmentNumber}{6} \newcommand{\AssignmentNumber}{7}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X} \newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}} \newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
@@ -137,6 +137,7 @@
\include{devopsAutomatedManualBuild} \include{devopsAutomatedManualBuild}
\include{devopsCI} \include{devopsCI}
\include{devopsSRE} \include{devopsSRE}
\include{devopsSecureDelivery}
\printglossaries \printglossaries
+2
View File
@@ -10,6 +10,8 @@
\toprule \textbf{Date / Version} & \textbf{Authors} & \textbf{Change} & \textbf{Changed At}\\ \midrule \toprule \textbf{Date / Version} & \textbf{Authors} & \textbf{Change} & \textbf{Changed At}\\ \midrule
\endhead \endhead
November 13, 2026 / 1.7 (draft) & SK, KH & In progress: Secure Delivery and Rollback assignment. Added the trusted Jenkins delivery agent, locked dependencies and pinned base image, the Gitea container registry, staging and production proxy routes, image build and publish by digest, and Ansible deployment to staging with an idempotence check. Security gates, approval and promotion, v2 and recovery, and monitoring sections still to be completed. Updated the Hosts and Passwords tables and the Glossary. & \ChapterRef{SecureDelivery}, \ChapterRef{PWDHST} \\
October 29, 2026 / 1.6 & SK, KH & Completed the Introduction to SRE assignment: deployed Prometheus, Grafana OSS, Node Exporter, and Blackbox Exporter as four pinned, persistent containers on the existing Droplet; published authenticated Grafana at \texttt{metrics.ssw590-08.me}; built a six-panel dashboard; defined an availability SLI and SLO; configured and tested Grafana-managed alerts with a Discord contact point; and ran a controlled Jenkins outage with a blameless review. Updated the Hosts and Passwords tables and the Glossary. & \ChapterRef{SRE}, \ChapterRef{PWDHST} \\ October 29, 2026 / 1.6 & SK, KH & Completed the Introduction to SRE assignment: deployed Prometheus, Grafana OSS, Node Exporter, and Blackbox Exporter as four pinned, persistent containers on the existing Droplet; published authenticated Grafana at \texttt{metrics.ssw590-08.me}; built a six-panel dashboard; defined an availability SLI and SLO; configured and tested Grafana-managed alerts with a Discord contact point; and ran a controlled Jenkins outage with a blameless review. Updated the Hosts and Passwords tables and the Glossary. & \ChapterRef{SRE}, \ChapterRef{PWDHST} \\
October 23, 2026 / 1.5 & SK, KH & Completed the Continuous Integration with Jenkins assignment: deployed a persistent Jenkins LTS container behind HTTPS at \texttt{ci.ssw590-08.me} with firewall-restricted access; integrated Jenkins with the Scrap-Web Gitea repository through a dedicated integration account; added a pricing module, unit tests, and a versioned \texttt{Jenkinsfile}; protected \texttt{main} with a required Jenkins status check and one required approval; and demonstrated a failed, repaired, reviewed, and merged pull request. Updated the Hosts table (Jenkins host and ports) and the Passwords table (Jenkins administrator accounts and the Gitea integration token, hints only). & \ChapterRef{ContinuousIntegration}, \ChapterRef{PWDHST} \\ October 23, 2026 / 1.5 & SK, KH & Completed the Continuous Integration with Jenkins assignment: deployed a persistent Jenkins LTS container behind HTTPS at \texttt{ci.ssw590-08.me} with firewall-restricted access; integrated Jenkins with the Scrap-Web Gitea repository through a dedicated integration account; added a pricing module, unit tests, and a versioned \texttt{Jenkinsfile}; protected \texttt{main} with a required Jenkins status check and one required approval; and demonstrated a failed, repaired, reviewed, and merged pull request. Updated the Hosts table (Jenkins host and ports) and the Passwords table (Jenkins administrator accounts and the Gitea integration token, hints only). & \ChapterRef{ContinuousIntegration}, \ChapterRef{PWDHST} \\
+4
View File
@@ -22,3 +22,7 @@
\newglossaryentry{errorbudget}{name={error budget},description={The amount of failure an SLO allows over its window; for a 99\% target, 1\% of scheduled measurements}} \newglossaryentry{errorbudget}{name={error budget},description={The amount of failure an SLO allows over its window; for a 99\% target, 1\% of scheduled measurements}}
\newglossaryentry{probe}{name={probe},description={A synthetic request, here an HTTPS GET from Blackbox Exporter, that tests whether a service responds as expected}} \newglossaryentry{probe}{name={probe},description={A synthetic request, here an HTTPS GET from Blackbox Exporter, that tests whether a service responds as expected}}
\newglossaryentry{contactpoint}{name={contact point},description={The Grafana destination, such as a Discord webhook or email address, that receives alert notifications}} \newglossaryentry{contactpoint}{name={contact point},description={The Grafana destination, such as a Discord webhook or email address, that receives alert notifications}}
\newglossaryentry{idempotence}{name={idempotence},description={The property that running the same deployment again on an already-correct system changes nothing}}
\newglossaryentry{imagedigest}{name={image digest},description={The SHA-256 content hash that identifies one exact container image in a registry; unlike a tag, it cannot be moved to another image}}
\newglossaryentry{releaserecord}{name={release record},description={A file that ties one deployment to its image digest, source commit, expected behavior, environment, and build}}
\newglossaryentry{trustedagent}{name={trusted agent},description={A Jenkins build node that holds deployment credentials and therefore runs only reviewed code}}
+20 -1
View File
@@ -66,6 +66,17 @@ Discord webhook (Grafana contact point \texttt{team-alerts})
& Webhook URL stored only in Grafana's database; re-created from the Discord channel's Integrations $\rightarrow$ Webhooks settings\\ & Webhook URL stored only in Grafana's database; re-created from the Discord channel's Integrations $\rightarrow$ Webhooks settings\\
\hline \hline
Deployment account (Ansible)
& deploy
& No password; SSH key stored only in Jenkins credential \texttt{deploy-ssh}\\
\hline
Gitea container registry
& Push: Jenkins credential \texttt{gitea-registry-push}; pull: root on the Droplet
& Package-write and package-read tokens; never stored in Git, logs, or screenshots\\
\hline
Jenkins delivery agent
& delivery-agent
& Agent secret in a file on the Droplet beside \texttt{agent/compose.yaml}; not in Git\\
\end{longtable} \end{longtable}
@@ -100,7 +111,7 @@ Jenkins Web Interface & ci.ssw590-08.me & 443 & HTTPS access to Jenkins through
\hline \hline
Jenkins Container & jenkins & 8080 & Internal Docker network web service; not published on the host \\ Jenkins Container & jenkins & 8080 & Internal Docker network web service; not published on the host \\
\hline \hline
Jenkins Agent Port & jenkins & 50000 & Not published on the host; no separate build agent is used \\ Jenkins Agent Port & jenkins & 50000 & Not published on the host and not used; the delivery agent connects over WebSocket through port 8080 on \texttt{gitea-net} \\
\hline \hline
Grafana Web Interface & metrics.ssw590-08.me & 443 & HTTPS access to Grafana through Caddy \\ Grafana Web Interface & metrics.ssw590-08.me & 443 & HTTPS access to Grafana through Caddy \\
\hline \hline
@@ -112,4 +123,12 @@ Node Exporter Container & node-exporter & 9100 & Private, \texttt{monitoring} ne
\hline \hline
Blackbox Exporter Container & blackbox-exporter & 9115 & Private, \texttt{monitoring} network only; HTTPS probes of Gitea and Jenkins \\ Blackbox Exporter Container & blackbox-exporter & 9115 & Private, \texttt{monitoring} network only; HTTPS probes of Gitea and Jenkins \\
\hline \hline
Staging Application & staging.ssw590-08.me & 443 & HTTPS access to the staging pricing service through Caddy \\
\hline
Production Application & app.ssw590-08.me & 443 & HTTPS access to the production-like pricing service through Caddy \\
\hline
Pricing Containers & pricing-staging, pricing-production & 8000 & Private, \texttt{gitea-net} only; Gunicorn; not published on the host; Compose projects under \texttt{/opt/startup/pricing-\{staging,production\}}; no data volume \\
\hline
Jenkins Delivery Agent & jenkins-agent & None & Container on \texttt{gitea-net}; runs Docker builds and Ansible; mounts the host Docker socket; state in volume \texttt{agent\_home} \\
\hline
\end{longtable} \end{longtable}
+45
View File
@@ -95,3 +95,48 @@
url = {https://docs.digitalocean.com/support/why-is-smtp-blocked/}, url = {https://docs.digitalocean.com/support/why-is-smtp-blocked/},
note = {Accessed: Oct. 28, 2026} note = {Accessed: Oct. 28, 2026}
} }
@misc{AnsibleCompose,
author = {{Ansible Project}},
title = {{community.docker.docker\_compose\_v2 module}},
howpublished = {Ansible Documentation},
year = {2026},
url = {https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_v2_module.html},
note = {Accessed: Nov. 13, 2026}
}
@misc{AnsibleInstall,
author = {{Ansible Project}},
title = {{Installing Ansible}},
howpublished = {Ansible Documentation},
year = {2026},
url = {https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html},
note = {Accessed: Nov. 13, 2026}
}
@misc{GiteaContainerRegistry,
author = {{Gitea}},
title = {{Container Registry}},
howpublished = {Gitea Documentation},
year = {2026},
url = {https://docs.gitea.com/usage/packages/container},
note = {Accessed: Nov. 13, 2026}
}
@misc{DockerPullDigest,
author = {{Docker Inc.}},
title = {{docker image pull: Pull an image by digest}},
howpublished = {Docker Documentation},
year = {2026},
url = {https://docs.docker.com/reference/cli/docker/image/pull/},
note = {Accessed: Nov. 13, 2026}
}
@misc{JenkinsAgents,
author = {{Jenkins Project}},
title = {{Using Jenkins agents}},
howpublished = {Jenkins User Documentation},
year = {2026},
url = {https://www.jenkins.io/doc/book/using/using-agents/},
note = {Accessed: Nov. 13, 2026}
}
+445
View File
@@ -0,0 +1,445 @@
\chapter{Secure Delivery and Rollback}
\ChapterLabel{SecureDelivery}
\index{continuous delivery}
\index{Ansible}
\index{rollback}
\sloppy
% Red marker for values still to be filled in from the team's own outputs.
% Search this file for \FillIn before submitting; none should remain.
\providecommand{\FillIn}[1]{\textcolor{devopsRed}{\textbf{[TO FILL: #1]}}}
% Figure helper: shows a labelled box until the screenshot file exists.
\providecommand{\delfig}[4]{%
\begin{figure}[H]\centering
\IfFileExists{HW8 images/#1}{\includegraphics[width=#2\linewidth]{HW8 images/#1}}%
{\fbox{\parbox{0.8\linewidth}{\centering\vspace{1em}\textit{[Screenshot needed: HW8 images/#1]}\vspace{1em}}}}
\caption{#3}\label{#4}\end{figure}}
This chapter closes the delivery loop for the team's startup. The Startup
Pricing Service, a small stateless Flask application served by Gunicorn, is
built once into a container image, published to the Gitea container registry,
and deployed by Ansible to a staging environment on the existing Droplet behind
the existing Caddy proxy. The same image digest is then approved and promoted
to a production-like environment, a second release (v2) is delivered, and two
recovery cases are exercised.
The existing Gitea, Jenkins, Caddy, and monitoring containers from earlier
chapters are reused unchanged. Nothing was reinstalled, and no Kubernetes,
Argo CD, cAdvisor, or database was added. Staging and production share one
Droplet, so they share a failure domain and its CPU, memory, and disk: separate
Compose projects give configuration separation, not high availability.
\textbf{Division of work.} Sections~\ref{sec:del-baseline}--\ref{sec:del-build}
and Section~\ref{sec:del-ansible} were carried out by \texttt{samahk13}, who
holds the Gitea administrator, Jenkins, DNS, and Droplet SSH access.
Sections~\ref{sec:del-security} and~\ref{sec:del-promote}--\ref{sec:del-ops}
were carried out by \texttt{kholmes}.
\section{Deployment Architecture}
\label{sec:del-architecture}
\begin{itemize}
\item \textbf{Source and images:} the existing Gitea server
(\texttt{git.ssw590-08.me}) holds the repository and, with its package
registry enabled~\cite{GiteaContainerRegistry}, the application images under
\texttt{git.ssw590-08.me/ssw-590-08/pricing}.
\item \textbf{Orchestration:} the existing Jenkins controller schedules the
pipeline. Delivery stages run on a new \gls{trustedagent} container~\cite{JenkinsAgents},
\texttt{jenkins-agent} (node \texttt{delivery-agent}, label
\texttt{delivery}), on the same Droplet. Ansible runs inside this agent, not
on the controller and not in the application container.
\item \textbf{Target:} Ansible connects over SSH to the Droplet host as the
dedicated \texttt{deploy} account and applies a separate Compose project
for each environment under \texttt{/opt/startup/pricing-staging} and
\texttt{/opt/startup/pricing-production}.
\item \textbf{Traffic:} browser $\rightarrow$ Caddy (HTTPS 443)
$\rightarrow$ \texttt{pricing-staging:8000} or
\texttt{pricing-production:8000} over the private \texttt{gitea-net}
network. No application port is published on the host.
\item \textbf{Monitoring:} the Chapter~\ref{Chapter:SRE} stack (Prometheus,
Grafana, Blackbox Exporter, Node Exporter) is reused; see
Section~\ref{sec:del-ops}.
\end{itemize}
\FillIn{team deployment diagram (HW8 images/delivery-architecture.png) showing
actual hosts, container boundaries, volumes and bind mounts, Ansible SSH, both
environments, proxy, and monitoring}
\section{Prepare the Repository and Establish a Baseline}
\label{sec:del-baseline}
\textbf{Issue and branch.} The work is tracked in Gitea issue~\#24 and developed
on branch \texttt{feature/issue-24-delivery} of the existing
\texttt{SSW-590-08/Scrap-Web} repository. The supplied v1 starter was copied into
\texttt{pricing/}, the Ansible files into \texttt{ansible/}, and release-record
documentation into \texttt{releases/}.
\textbf{Locked dependencies.} The starter's \texttt{requirements.txt} gives
version ranges (\texttt{Flask>=3.1,<3.2}, \texttt{gunicorn>=23,<24}). These
ranges were moved to \texttt{pricing/requirements.in}, and a lockfile with exact
versions and SHA-256 hashes for every direct and transitive dependency was
generated with:
\begin{minted}[breaklines,breakanywhere]{text}
uv pip compile requirements.in --universal --python-version 3.13 --generate-hashes -o requirements.txt
\end{minted}
\begin{tabularx}{\linewidth}{L{3.2cm}L{2.4cm}Y}
\toprule
\textbf{Package} & \textbf{Version} & \textbf{Role}\\ \midrule
flask & 3.1.3 & Direct: web framework\\
gunicorn & 23.0.0 & Direct: application server\\
werkzeug & 3.1.9 & Transitive (Flask)\\
jinja2 & 3.1.6 & Transitive (Flask)\\
markupsafe & 3.0.4 & Transitive (Jinja2, Werkzeug)\\
itsdangerous & 2.2.0 & Transitive (Flask)\\
click & 8.5.1 & Transitive (Flask)\\
blinker & 1.9.0 & Transitive (Flask)\\
packaging & 26.3 & Transitive (Gunicorn)\\
\bottomrule
\end{tabularx}
\medskip
Both the pipeline's test environment and the image build install with
\texttt{pip install --require-hashes -r requirements.txt}, so a changed or
unlisted package fails the install instead of being used silently. When
dependencies are updated, the lockfile is regenerated and the image is rebuilt
and rescanned. No claim is made that these versions are free of
vulnerabilities; that is the job of the security gates in
Section~\ref{sec:del-security}.
\textbf{Base image.} The Dockerfile pins \texttt{python:3.13-slim} by digest for
\texttt{linux/amd64}, the Droplet's architecture:
\texttt{python:3.13-slim@sha256:e48f59cdba69a3cbd9ed2cf0f348d90d\allowbreak 45a8d350d98134cf1070bc106ee9ed90}. Python 3.13 is
supported by the selected \texttt{ansible-core} release.
\textbf{Baseline and controlled failure.} The v1 unit tests
(\texttt{test\_price}, \texttt{test\_invalid\_quantity},
\texttt{test\_release\_identity}) run in the pipeline's \emph{Unit tests} stage
inside a fresh virtual environment:
\begin{minted}[breaklines,breakanywhere]{text}
python3 -m venv .venv
.venv/bin/pip install -q --require-hashes -r requirements.txt
.venv/bin/python -m py_compile app.py test_app.py
.venv/bin/python -m unittest -v
\end{minted}
\begin{itemize}
\item \textbf{Controlled failure:} Jenkins run
\texttt{feature/issue-24-delivery} \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/6/}{\#6}, started by a push at 11:19 PM EST on
November 12, 2026, ran on \texttt{delivery-agent}. The deliberately
broken test \texttt{test\_price} failed, so the \emph{Unit tests} stage
failed after 6 seconds and every later delivery stage (security scans,
build, publish, deploy) was skipped
(Figure~\ref{fig:del-test-fail}). A failing test therefore prevents
delivery. The test's expected total was changed from 30 to 31, so it
failed with \texttt{AssertionError: 30 != 31} while the application itself
was unchanged.
\item \textbf{Passing baseline and restore:} run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/5/}{\#5} (11:13 PM EST), before the
controlled failure, passed all three tests. The test was then restored to
expect 30, and run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/7/}{\#7} (11:20 PM EST) passed all three tests again. The same tests also
pass locally in a fresh virtual environment (\texttt{Ran 3 tests in
0.085s, OK}).
\end{itemize}
All times in this chapter are Eastern Standard Time (EST), as displayed by Jenkins.
\delfig{build6-unit-test-fail.png}{1.0}{November 12, 2026, 11:19 PM EST ---
Jenkins \texttt{feature/issue-24-delivery} run \#6 on \texttt{delivery-agent}:
\texttt{test\_price} fails, the Unit tests stage stops the run, and the build,
publish, and deploy stages are skipped.}{fig:del-test-fail}
\section{Prepare the Trusted Agent and Target}
\label{sec:del-agent}
\subsection{Trusted Delivery Agent}
The Chapter~\ref{Chapter:ContinuousIntegration} pipeline ran only on the
controller's built-in node, which has no Docker or Ansible. A dedicated agent
was added rather than enabling deployment jobs on the controller. It is built
from \texttt{agent/Dockerfile} and started by \texttt{agent/compose.yaml}, both
in Gitea, so recreating the container keeps every tool:
\begin{itemize}
\item \textbf{Base:} \texttt{jenkins/inbound-agent:latest-jdk21}.
\item \textbf{Tools:} Python 3 with \texttt{venv}; Docker CLI and the
\texttt{buildx} plugin (client only; the daemon is the host's); Trivy;
\texttt{pip-audit} in \texttt{/opt/tools-venv}; and \texttt{ansible-core}
with the \texttt{community.docker} collection~\cite{AnsibleInstall} in
\texttt{/opt/ansible-venv}. Every Jenkins deployment step puts
\texttt{/opt/ansible-venv/bin} first on its \texttt{PATH}.
\item \textbf{Connection:} the agent connects to the controller at
\texttt{http://jenkins:8080/} over WebSocket on the internal
\texttt{gitea-net} network, so no new port is published. Its secret is
read from a file (\texttt{-secret @/run/secrets/jenkins-agent-secret}) that
is not in Git, so it does not appear in the process list or
\texttt{docker inspect}.
\item \textbf{Docker access:} the host Docker socket is mounted so the agent
can build and push images. This is effectively root on the Droplet, so only
trusted-branch delivery stages may run on this agent
(Section~\ref{sec:del-trust}).
\end{itemize}
Installed versions, printed by \texttt{agent/versions.sh} inside the agent:
\begin{tabularx}{\linewidth}{L{3.6cm}Y}
\toprule
\textbf{Tool} & \textbf{Version}\\ \midrule
Java & OpenJDK 21.0.13 LTS\\
Python & 3.13.5\\
Docker client / server & 29.9.3 / 29.8.2\\
Docker buildx & v0.38.2\\
Trivy & 0.76.2\\
pip-audit & 2.10.1\\
ansible-core & 2.22.0\\
community.docker & 5.4.0\\
Agent OS & Debian GNU/Linux 13 (trixie), x86\_64\\
\bottomrule
\end{tabularx}
\medskip
The agent image \texttt{ssw590/jenkins-delivery-agent:1} has image ID
\texttt{sha256:e8e72e1c89d3\allowbreak 72fff4a920b581b1a0daa7c885164ff6668dfcc2e22f85e6aa83}.
\subsection{Target Prerequisites}
The target is the same Droplet (\texttt{147.182.179.191}). Before the first
playbook run its prerequisites were verified:
\begin{tabularx}{\linewidth}{L{4.2cm}Y}
\toprule
\textbf{Requirement} & \textbf{Observed}\\ \midrule
Python 3 & 3.12.3\\
Docker Engine & 29.8.2\\
Compose plugin ($\geq$ 2.18) & v5.5.1 (meets the minimum)\\
\bottomrule
\end{tabularx}
\subsection{Deployment Account and Credentials}
\label{sec:del-trust}
\begin{itemize}
\item \textbf{Deployment account:} a dedicated \texttt{deploy} user on the
Droplet, used only by Ansible. Its private key is stored only in the Jenkins
credential \texttt{deploy-ssh}. It is an Ed25519 key with comment
\texttt{jenkins-deploy} and fingerprint
\texttt{SHA256:jy/MveXnRjD+HOLWi6fuR+WNGA3gpkS0kudqPi/prJY}. The Droplet's
Ed25519 host key was read on the Droplet itself over the existing
administrator SSH session
(\texttt{SHA256:zL7qulFmdVDZQ3oBGvXWyWnKjNWUpPh1BDbfAOC+nbk}). The key
scanned from \texttt{147.182.179.191} had the same fingerprint, and it was
then pinned in the agent's \texttt{known\_hosts}. Its non-interactive
\texttt{sudo} rule, in \texttt{/etc/sudoers.d/}, is
\texttt{deploy ALL=(root) NOPASSWD: ALL}. This scope is deliberately broad:
the playbook uses \texttt{become: true} to create directories under
\texttt{/opt/startup} and to drive Docker Compose as \texttt{root}, and
Docker access is already equivalent to root on the host. The account
therefore effectively administers the Droplet. A separate account limits
who holds the key and makes its use auditable, but it does not remove that
risk, so the key is held only by Jenkins and used only by trusted-branch
delivery stages.
\item \textbf{Registry access:} the Gitea package registry was enabled
(\texttt{[packages] ENABLED = true}). A package-\emph{write} token is held
only in the Jenkins credential \texttt{gitea-registry-push} and used by the
\emph{Publish} stage through \texttt{docker login --password-stdin}. A
package-\emph{read} token is logged in for \texttt{root} on the Droplet,
the account that runs Docker under Ansible escalation. Tokens are never in
Git, command arguments, screenshots, or pipeline logs.
\item \textbf{Trust boundary:} every branch and pull request runs only the
Chapter~\ref{Chapter:ContinuousIntegration} checks on the controller, with
no credentials and no Docker socket. The \emph{Delivery} stages run only for
the trusted branch pattern \texttt{TRUSTED\_BRANCH}. During development it
also allowed \texttt{feature/issue-24-delivery}; for the assessed runs it is
\texttt{main} only, so only reviewed code can build, publish, or deploy.
\FillIn{confirm the change to main only and its commit} No Docker daemon API is published to the Internet.
\end{itemize}
\section{Connect the Application to the Existing Proxy}
\label{sec:del-proxy}
\begin{itemize}
\item \textbf{DNS:} \texttt{staging.ssw590-08.me} and
\texttt{app.ssw590-08.me} point to the Droplet (\texttt{147.182.179.191}).
\item \textbf{Proxy network:} Caddy runs in a container on the existing
\texttt{gitea-net} network. The Compose template joins each pricing
container to that external network with a distinct alias
(\texttt{pricing-staging}, \texttt{pricing-production}) and publishes no
host port, so port 8000 is reachable only from containers on
\texttt{gitea-net}.
\item \textbf{Routes:} added to the existing \texttt{/root/gitea/Caddyfile},
keeping the Gitea, Jenkins, and Grafana routes. The file was validated and
Caddy reloaded, and Caddy obtained valid TLS certificates for both
hostnames automatically.
\end{itemize}
\begin{minted}[breaklines,breakanywhere]{text}
staging.ssw590-08.me {
reverse_proxy pricing-staging:8000
}
app.ssw590-08.me {
reverse_proxy pricing-production:8000
}
\end{minted}
The firewall policy is unchanged: public HTTPS (443, and 80 for redirects),
restricted SSH, and no public infrastructure or metrics ports.
\textbf{Accepted simplification.} Sharing \texttt{gitea-net} means a
compromised pricing container could reach Gitea, Jenkins, Grafana, and the
agent on that network directly, not only through Caddy. A separate proxy-only
network per application would give stronger lateral isolation.
\section{Build Once and Record an Immutable Release}
\label{sec:del-build}
The \texttt{Jenkinsfile} keeps the Chapter~\ref{Chapter:ContinuousIntegration}
checks and adds a \emph{Delivery} block on the \texttt{delivery} agent with
these stages: Checkout, Unit tests, Security scan: source, Build image, Security
scan: image, Publish, Deploy staging, Staging idempotence, and Approve and deploy
production. The pipeline sets \texttt{disableConcurrentBuilds()}, so two runs
cannot change staging or production at the same time.
The image is built once per source commit, with the commit baked in at build
time. The \emph{Publish} stage pushes it, deletes the local copy, and pulls it
back, so the recorded \gls{imagedigest} is the registry's and not a local image ID~\cite{DockerPullDigest}:
\begin{minted}[breaklines,breakanywhere]{bash}
docker build --build-arg APP_COMMIT="$APP_COMMIT" -t "$IMAGE:$APP_COMMIT" .
printf '%s' "$REG_TOKEN" | docker login "$REGISTRY" -u "$REG_USER" --password-stdin
docker push "$IMAGE:$APP_COMMIT"
docker image rm "$IMAGE:$APP_COMMIT"
docker pull "$IMAGE:$APP_COMMIT"
docker logout "$REGISTRY"
docker image inspect "$IMAGE:$APP_COMMIT" --format '{{index .RepoDigests 0}}'
\end{minted}
The stage archives \texttt{image-digest.txt} and \texttt{build-record.txt}
(source commit, tag, digest, and Jenkins build URL) as fingerprinted build
artifacts. The image runs Gunicorn as the non-root user \texttt{10001}, and the
Compose template drops all capabilities and makes the root filesystem read-only
with a \texttt{tmpfs} for \texttt{/tmp}.
\begin{tabularx}{\linewidth}{L{3.2cm}Y}
\toprule
\textbf{Release} & \textbf{v1}\\ \midrule
Source commit & \texttt{2a35f97071c95b23bccb8c973099f2991c998599}\\
Jenkins build & \texttt{feature/issue-24-delivery} \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/8/}{\#8}\\
Image digest & \texttt{git.ssw590-08.me/ssw-590-08/\allowbreak pricing@sha256:\allowbreak ce91d0552da2a4580557ec65aedec04b\allowbreak 278fe918df1f02b23c971ca45cc3d97c}\\
Published & November 12, 2026, 11:51 PM EST\\
\bottomrule
\end{tabularx}
\delfig{publish-digest.png}{1.0}{November 12, 2026, run \#8 --- Jenkins Publish
stage: the v1 image is pushed, the local copy deleted and pulled back from the
registry, and its registry digest recorded. The registry token is masked and
never printed.}{fig:del-publish}
\section{Apply Proportionate Security Gates}
\label{sec:del-security}
\FillIn{kholmes: scan policy, tools and database versions, source and image
scan results, blocked synthetic fixture run, fix and rerun
(\texttt{security/scan.sh})}
\section{Deploy v1 with Ansible and Prove Idempotence}
\label{sec:del-ansible}
\textbf{Inputs.} \texttt{ansible/inventory.ini} names one host,
\texttt{startup}, at \texttt{147.182.179.191} with user \texttt{deploy}; it
contains no secrets. \texttt{ansible/deploy.yml} and
\texttt{ansible/templates/compose.yaml.j2} are the supplied playbook and
template with every placeholder replaced.
\textbf{Release record.} The \emph{Deploy staging} stage writes the
\gls{releaserecord} from the build it belongs to, so the digest and commit cannot be
mistyped. The expected version and total are read from the application source
(\texttt{VERSION} and \texttt{3 $\times$ UNIT\_PRICE}), not from configuration.
The record is archived with the build. For v1 it contains:
\begin{minted}[breaklines,breakanywhere]{yaml}
target_env: staging
release_image: git.ssw590-08.me/ssw-590-08/pricing@sha256:ce91d0552da2a4580557ec65aedec04b278fe918df1f02b23c971ca45cc3d97c
expected_version: v1
expected_commit: 2a35f97071c95b23bccb8c973099f2991c998599
expected_total: 30
public_url: https://staging.ssw590-08.me
proxy_network: gitea-net
\end{minted}
The record holds metadata only, never credentials.
\textbf{Deployment.} The stage runs a syntax check and then the deployment:
\begin{minted}[breaklines,breakanywhere]{bash}
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml \
--private-key "$DEPLOY_KEY" -e @release-v1-staging.yml
\end{minted}
The playbook validates its inputs, creates \texttt{/opt/startup/pricing-staging},
renders the Compose file, starts the selected digest without rebuilding~\cite{AnsibleCompose}, waits
for the container health check, and then checks
\url{https://staging.ssw590-08.me} for \texttt{/health}, version \texttt{v1},
the exact source commit, and a total of USD~30 for \texttt{quantity=3}. It
fails the run if any check fails; it does not roll back on its own.
\textbf{\Gls{idempotence}.} The \emph{Staging idempotence} stage runs exactly the
same command again and fails the build unless the recap shows
\texttt{changed=0 unreachable=0 failed=0}:
\begin{tabularx}{\linewidth}{L{2.6cm}Y}
\toprule
\textbf{Run} & \textbf{PLAY RECAP for \texttt{startup}}\\ \midrule
First & \texttt{ok=9 changed=3 unreachable=0 failed=0 skipped=0}\\
Second & \texttt{ok=9 changed=0 unreachable=0 failed=0 skipped=0}\\
\bottomrule
\end{tabularx}
\medskip
Jenkins run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/8/}{\#8} (November 12, 2026, 11:51 PM EST): the first run created the environment and started the
container (\texttt{changed=3}); the identical second run changed nothing, and the
stage's check matched the recap line
\texttt{startup : ok=9 changed=0 unreachable=0 failed=0}. In the second run every
task reported \texttt{ok}, including the public HTTPS health, release-identity,
and price checks (\texttt{"msg": "All assertions passed"}).
\delfig{staging-idempotence.png}{1.0}{November 12, 2026, run \#8 --- Jenkins
Staging idempotence stage: the second, unchanged run passes every check and
reports \texttt{changed=0}.}{fig:del-idempotence}
\delfig{staging-check.png}{1.0}{November 13, 2026 --- staging, v1:
\url{https://staging.ssw590-08.me/} returns version \texttt{v1} and commit
\texttt{2a35f97}, and \texttt{/price?quantity=3} returns a total of USD 30.}{fig:del-staging}
\section{Approve and Promote the Same Image}
\label{sec:del-promote}
\FillIn{kholmes: restricted Jenkins input step with timeout, approver and
decision, v1-production record with the same digest, production smoke tests}
\section{Release v2 and Exercise Two Recovery Cases}
\label{sec:del-v2}
\FillIn{kholmes: v2 release in both environments, healthy rollback of
production to v1, failed staging deployment (Gunicorn on 8001) and recovery,
timeline and measured interruption, state-compatibility discussion}
\section{Reuse Monitoring and Document Operations}
\label{sec:del-ops}
\FillIn{kholmes: production /health Blackbox probe and Grafana panel, release
and rollback timestamps correlated with monitoring, runbooks, approvers,
resource use, cleanup plan}
\section{Traceability}
\label{sec:del-trace}
\begin{tabularx}{\linewidth}{L{3.4cm}YY}
\toprule
\textbf{Item} & \textbf{v1} & \textbf{v2}\\ \midrule
Source commit & \texttt{2a35f97} & \FillIn{}\\
Configuration commit & \FillIn{} & \FillIn{}\\
Image digest & \texttt{sha256:ce91d055\ldots} & \FillIn{}\\
Jenkins build & \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/8/}{\#8} (staging) & \FillIn{}\\
Scan result & \FillIn{} & \FillIn{}\\
Staging result & Passed: health, v1, commit, total 30; rerun \texttt{changed=0} & \FillIn{}\\
Approver and time & \FillIn{} & \FillIn{}\\
Production result & \FillIn{} & \FillIn{}\\
\bottomrule
\end{tabularx}
\fussy