From ad35197ee4905767b0c3d74159a8dfee29d5c37a Mon Sep 17 00:00:00 2001 From: Billye4 Date: Thu, 22 Oct 2026 18:55:59 -0400 Subject: [PATCH] Add Jenkins CI service, pricing app, tests and Jenkinsfile (refs #14) Deploy Jenkins LTS 2.580.1 beside Gitea on The-Ocean: - deploy/jenkins: official image pinned by digest plus python3 and a hashed 60-plugin lockfile (Pipeline + Gitea bundle tested by ci/jenkins-capacity, plus matrix-auth for named roles) - compose: jenkins service with persistent jenkins-home, no published ports, 512 MiB RAM / 768 MiB RAM+swap / 0.75 CPU, 256 MiB heap - Gitea webhooks restricted to the private jenkins host; Caddy alias keeps Jenkins->Gitea checkout and status traffic on the droplet - Caddy serves ci.yebilly.me only to Stevens 155.246.0.0/16 and team IPs from the untracked .env Add the instructor's pricing example, unit tests and Declarative Jenkinsfile (checkout, syntax check, unit tests). Co-Authored-By: Claude Opus 5.5 --- Jenkinsfile | 15 +++++++++ deploy/Caddyfile | 8 +++++ deploy/README.md | 36 +++++++++++++++++++++ deploy/docker-compose.yml | 31 +++++++++++++++++- deploy/jenkins/Dockerfile | 18 +++++++++++ deploy/jenkins/plugins.txt | 66 ++++++++++++++++++++++++++++++++++++++ pricing.py | 4 +++ tests/test_pricing.py | 11 +++++++ 8 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile create mode 100644 deploy/jenkins/Dockerfile create mode 100644 deploy/jenkins/plugins.txt create mode 100644 pricing.py create mode 100644 tests/test_pricing.py diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..979f6dc --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,15 @@ +pipeline { + agent any + options { skipDefaultCheckout() } + stages { + stage('Checkout') { + steps { checkout scm } + } + stage('Syntax check') { + steps { sh 'python3 -m py_compile pricing.py' } + } + stage('Test') { + steps { sh 'python3 -m unittest discover -s tests -v' } + } + } +} diff --git a/deploy/Caddyfile b/deploy/Caddyfile index 7355165..8c66576 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -6,3 +6,11 @@ git.yebilly.me { colors.yebilly.me { reverse_proxy color-buttons-app:3000 } + +# Jenkins: Stevens network (155.246.0.0/16, campus or Stevens VPN) plus team IPs +# from CI_TEAM_IPS in the untracked .env. Everyone else gets 403 before login. +ci.yebilly.me { + @denied not remote_ip 155.246.0.0/16 {$CI_TEAM_IPS} + respond @denied 403 + reverse_proxy jenkins:8080 +} diff --git a/deploy/README.md b/deploy/README.md index dcd1cdb..40a28c7 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -149,3 +149,39 @@ port; Caddy reaches it on the private `gitea_web` network. ``` Remove it with `docker rm -f color-buttons-app`, delete the block, and reload. + +## Jenkins CI (Assignment 6 / Instructor Manual Chapter 4) + +`jenkins/Dockerfile` extends the official `jenkins/jenkins:2.580.1-lts-jdk21` +image (digest pinned) with `python3` and the plugins in `jenkins/plugins.txt`. +Builds run on the controller's single executor. Jenkins publishes no port: +browsers reach it through Caddy at `https://ci.yebilly.me/login`, and the Gitea +webhook reaches `http://jenkins:8080/gitea-webhook/post` on the private network. + +1. DNS: `A` record `ci` -> droplet IPv4. +2. On the droplet, put team source IPs in the untracked `~/gitea/.env` + (space separated CIDRs; Stevens 155.246.0.0/16 is already in the Caddyfile): + ```bash + echo 'CI_TEAM_IPS=203.0.113.7/32' > ~/gitea/.env # example address + ``` +3. Copy `docker-compose.yml`, `Caddyfile` (with `cat >`, see above) and the + `jenkins/` folder, then: + ```bash + cd ~/gitea + docker compose build jenkins + docker compose up -d jenkins + docker compose up -d --force-recreate gitea caddy # webhook allowlist + CI_TEAM_IPS + alias + ``` +4. Unlock Jenkins with `docker compose exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword` + (read it yourself; never paste it anywhere), install **no** suggested + plugins, create one named administrator per teammate, and set the Jenkins + URL to `https://ci.yebilly.me/`. + +Operate: + +```bash +docker compose restart jenkins # settings and jobs live in the jenkins-home volume +docker compose logs --tail 100 jenkins # failed build or webhook: check here, then + # Gitea repo Settings -> Webhooks -> Recent Deliveries +docker stats --no-stream; free -m # memory pressure on the 512 MB droplet +``` diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index a8eddc4..1ba0a6b 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -12,6 +12,7 @@ services: - GITEA__server__ROOT_URL=https://git.yebilly.me/ - GITEA__server__HTTP_PORT=3000 - GITEA__server__DISABLE_SSH=true # Git over HTTPS only + - GITEA__webhook__ALLOWED_HOST_LIST=jenkins # only private webhook target allowed volumes: - gitea-data:/data networks: [web] @@ -27,13 +28,41 @@ services: - ./Caddyfile:/etc/caddy/Caddyfile:ro - caddy-data:/data # certificates + ACME account - caddy-config:/config - networks: [web] + environment: + - CI_TEAM_IPS=${CI_TEAM_IPS:-} # team source IPs for ci.yebilly.me, kept in untracked .env + networks: + web: + # Jenkins resolves git.yebilly.me to Caddy here, so checkout and status + # calls stay on the droplet instead of hairpinning through the public IP. + aliases: [git.yebilly.me] depends_on: [gitea] + # Jenkins LTS controller (Assignment 6). Builds run on its single executor. + # Bounded so Gitea keeps memory on the 512 MB droplet. + jenkins: + build: ./jenkins + image: ssw590-jenkins:2.580.1 + restart: unless-stopped + environment: + # The capacity test's 128 MiB heap ran builds, but the web UI hit "OutOfMemoryError: + # Java heap space" once the update-center catalog loaded (2026-10-22), so the + # persistent service gets twice the test bounds on the 1 GiB droplet. + - JAVA_OPTS=-Xms64m -Xmx256m -XX:+UseSerialGC -Djava.awt.headless=true + volumes: + - jenkins-home:/var/jenkins_home + networks: [web] + mem_limit: 512m + memswap_limit: 768m + cpus: 0.75 + pids_limit: 256 + # ponytail: no ports: on purpose -- Caddy and the Gitea webhook reach jenkins:8080 privately; + # agent port 50000 is never published. + volumes: gitea-data: caddy-data: caddy-config: + jenkins-home: networks: web: diff --git a/deploy/jenkins/Dockerfile b/deploy/jenkins/Dockerfile new file mode 100644 index 0000000..fd4ea52 --- /dev/null +++ b/deploy/jenkins/Dockerfile @@ -0,0 +1,18 @@ +# Official Jenkins LTS image plus what the controller executor needs to run the +# pipeline: python3 for the tests and the pinned plugin lockfile. +FROM jenkins/jenkins:2.580.1-lts-jdk21@sha256:a660310e39ade10631f774bacd5219de767dfd08947ea5c32a739b5e5bb382c1 + +USER root +RUN apt-get update \ + && apt-get install -y --no-install-recommends python3 \ + && rm -rf /var/lib/apt/lists/* +USER jenkins + +# ponytail: curl + sha256sum instead of jenkins-plugin-cli, which needs >128 MiB heap +# just to parse the update-center JSON on a 512 MB droplet. +COPY plugins.txt /tmp/plugins.txt +RUN mkdir -p /usr/share/jenkins/ref/plugins && cd /usr/share/jenkins/ref/plugins \ + && tr -d '\r' < /tmp/plugins.txt | grep -Ev '^(#|$)' | while IFS=: read -r name ver sha; do \ + curl -fsSL -o "$name.jpi" "https://updates.jenkins.io/download/plugins/$name/$ver/$name.hpi" \ + && echo "$sha $name.jpi" | sha256sum -c --quiet || exit 1; \ + done diff --git a/deploy/jenkins/plugins.txt b/deploy/jenkins/plugins.txt new file mode 100644 index 0000000..f223709 --- /dev/null +++ b/deploy/jenkins/plugins.txt @@ -0,0 +1,66 @@ +# Lockfile copied from the team's prepared plugin bundle (Vincent Sun, 2026-10-21): roots +# workflow-aggregator:608.v67378e9d3db_1 and gitea:286.v0740a_413c1eb_ plus every resolved +# dependency, the same set exercised by ci/jenkins-capacity. Format name:version:sha256. +# Regenerate the whole file from a new bundle manifest rather than hand-editing one line. +# Added 2026-10-22: matrix-auth:3.3 for named Jenkins roles (its only dependency, ionicons-api, +# was already in the bundle at the required version). +apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83:cea2f61cc72890b962fd4b767c31778c6cb30015b4a8758b4c26b62e51ca9533 +asm-api:9.11.1-226.vff833a_e4c58e:ba315fe727be0311cd5115205a09a2abb550b73287cc4ee07af5f7ef6502f1f8 +authentication-tokens:1.144.v5ff4a_5ec5c33:8069074af688b102703410045a11394fb8d2f52c2cc2d7abd3067e3adff5fc24 +bouncycastle-api:2.30.1.86.2-310.v4655f6742752:57cc5cf1585f9a8f29c5a1e3985f07dace5d5359545d788e72ecaa3636515a58 +branch-api:2.1303.v9f3b_95dc329d:6ecfc3d335cec791008a2d06ca933c6ccc97db1c14a4aee5030affebb97482e0 +caffeine-api:3.3.1-214.v18eb_56b_34920:768ed05774f12d85bf8ecff5d509f037810d1359de8b4fb1385624f6f547c90b +cloudbees-folder:6.1106.v3a_d9a_6d2465e:4ccfcfe145a1b36aef61f19187e8aa74eb3c90fdb9c9bfce865e09aa13c8a70a +commons-lang3-api:3.21.0-122.v6a_ea_4fd34049:4d6194f8d3b3f2b69264f0403fe5a51846236a41f4e363f6aae45f82f7761657 +commons-text-api:1.15.0-218.va_61573470393:ae2abdf957694f4aa39b9ba0b539edabc384f3da277551879e34ffb22fb13764 +credentials-binding:728.v902a_273b_8947:bd7d1a187e35c8e2b6619cd50f2f8c5d28aafc4ef8fd9de572fb2cfa464f466d +credentials:1514.vb_01eb_014e7d4:b6e0a05d107fe492bb57baea75fb585fb65dd90c2456a6432b90b87226997457 +display-url-api:2.217.va_6b_de84cc74b_:07eeaae738b451bade4756900b48561c6c493a42c7ba07a45b22a2dce71ac0ca +durable-task:686.v80ff80875b_82:1f5bb92ee5784ee01a4e4e0307e806fa1e260db8aceba56fe8d277e939278dfa +git-client:6.6.1:69ab80e3bd51e2e4e676a18722c02c7b163eb11a758b52ecf179d58e1ca1738f +git:5.11.0:bf4639abb65e6ca210bd0d7cb9b6570e93717894bdcd008b2e7e5a916dd818f6 +gitea:286.v0740a_413c1eb_:242e091be9cbbd289546c65a85cf948670de2b3020db573e162926a97c3b5837 +gson-api:2.14.0-201.v8eefe5515533:6940cd0f795f72371fd5644d885db9ec0a2077985ac55de85d19ab3b1fac2bb7 +handy-uri-templates-2-api:2.1.8-38.vcea_5d521d5f3:2e5881410b0bca648fb78c890bfd8b83c46e4ff4c778235cb58e28b45d89b10e +instance-identity:203.v15e81a_1b_7a_38:df2b3205a6177248f12b294650a60405f65ba2cd503ca9599b2dcb72c1de5018 +ionicons-api:94.vcc3065403257:95f3504375d628d887425ccdf32d5606a230261ee42dc683f13958d8e973ac3f +jackson-annotations2-api:2.22-19.v10a_a_582ea_26e:f13d0a17af6f8c8939a6edd30952006b77dca4760b1f40e0289c363918b7d17d +jackson2-api:2.22.3-447.v6a_93ce7d2c82:ce2cfb7a5ad6e66aea9a5b6c4a5ea0622bfc5c05db5db8918581ae7f1d10ff33 +jakarta-activation-api:2.1.4-1:e62298341742f14b374045387ba641ad8a19376793c76bdafebb4a05b5099712 +jakarta-mail-api:2.1.5-1:244735ea85a51332c079d235a5713e70d3810bea62332894002acc39914ce11b +jakarta-xml-bind-api:4.0.9-19.v2b_a_5b_44d9a_1c:2f59227936687ec00f7ea62b550e7a6e9c86cda3423f3567ffe66bbdf235ffb5 +javax-activation-api:1.2.0-8:e96e88c52edf07ba00fb45b26cc411a7a95fa3d4491aaa1a5d36637665880560 +jaxb:2.3.9-143.v5979df3304e6:38ddf4cf5db61a591044130c2f7ccb2b7aa9abebc8fcd8a6953f8da550d002ed +joda-time-api:2.15.0-208.v6b_084e7a_d9f0:427513635d122f62fcd8e52af08cc895913b9a70568e7665a3ce8fc1a4871ddf +json-api:20260814-226.v20f9685d642c:c5ac5ecfddd35c07087b3333ae05ec4167a70abae8bf0ebcb7338b6b54540889 +mailer:534.v1b_36f5864073:5426a66a3f879d25fcb4baff678a28422afbabff22cd6e4f0f998fc67a3dc3fa +matrix-auth:3.3:b8f7a916f1de0872d4c16264bcf9604fdb5b2da1827764745946c7ac5f613948 +mina-sshd-api-common:2.19.0-192.v2b_a_7b_2c1dc71:887ebd645e43919b6113201257821b990fc923f375382a5dada0c089e49b85bc +mina-sshd-api-core:2.19.0-192.v2b_a_7b_2c1dc71:5039ea17ea1aa9e349712ccc1e036c38ea9f20f722affc220c2c751369f32495 +pipeline-build-step:601.v6d4c6d1a_9dc7:1b61a1820844f3f72f9dfcd6d7eeab66fa0fbcee5e3923b912cd1ed10fbf63c5 +pipeline-groovy-lib:822.vc95f70dea_db_7:a633824da17e95fe2a9f03e8d951a771c70a729e987fc51874146723f3b6343b +pipeline-input-step:560.v56198a_642157:7c61bb745ecd1e4e5c7864dc7c8352148d9b2281bcca5a48fd3a7cca7290a135 +pipeline-milestone-step:152.v6e22b_8cfc66c:cb3187809e219f01b42068f277058a818033f3cfd14da7ec59c86f028fc38386 +pipeline-model-api:2.2293.v6e7193cec599:cdd72a69bf2863a1683b282febd0256d5d266111134c3803a8c4a051b6b4c133 +pipeline-model-definition:2.2293.v6e7193cec599:9f4f62e0a13fefc9c5736a20ad5124af2a324357294fd8ea8d8f848b7c497f92 +pipeline-model-extensions:2.2293.v6e7193cec599:00fbf0938ef13f6aedaa0900ec4cd03fcc986e34b1820bf13f761c2f29831861 +pipeline-stage-step:345.va_96187909426:2eba433b28f2dfc90519e233b14264890f97b93b78e25c664d56607141fcd94b +pipeline-stage-tags-metadata:2.2293.v6e7193cec599:032f011fc50cb273b300d44fb6c2800e3dbdf0d78548b15e0f192ba7cc95d178 +plain-credentials:199.v9f8e1f741799:b5e5e35cf93ad3b818a983916cbcdf3f7866699410a4df923e6a2968ecc3a448 +scm-api:728.vc30dcf7a_0df5:1336472987daa2fa912210aba00e1e37b739ce03f75c973a6794d1a0f55c0326 +script-security:1436.v1082791135e4:c2292e200c5796675c16d19325469aac4a5460c7ad23974952b9823f62066f6a +snakeyaml-api:2.7-152.vc672728cf536:bfa595a283634c8dd63aa8d1b039cf3d3f52e0952048058fc0b9a4826ca06508 +ssh-credentials:372.va_250881b_08cd:7b4d035b05b331038f3dfa99ddfef0cabbacede8f0ad2a6ca9611fb0844108a9 +structs:362.va_b_695ef4fdf9:a0a5db44f2cb082a9ec6572c088340521f033fff8c351fc7eba9ef7f07dbbf8d +variant:70.va_d9f17f859e0:12e214ea694469a4461b55881ecb4074ae5dfb04797dbc0dad390f6f4bc75aaf +woodstox-core-api:7.3.0-16.v017f30ed004c:fca0ce7cd19274833df226cd6746d71ce4025b784a81bd5b8512730f5d34a9df +workflow-aggregator:608.v67378e9d3db_1:7b94227c1afa01bb262c14919ad4a333412f1b51d947c0f21909ec2daff357dc +workflow-api:1413.v2ff1a_5e720fa_:f4adbd6b34a2a0b643a12b898110bd976350142eff6322efda21efacbccb6835 +workflow-basic-steps:1098.v808b_fd7f8cf4:93449eb494658d065d097e8c54f707c98c9ce3e54da2fb98281b0a0487154eaf +workflow-cps:4395.v738456a_5da_6b_:2af278f3012f294165db715bfa608045feaf781a6c7c85b5d7ab1ee5b707f021 +workflow-durable-task-step:1479.v56e587f413a_7:a0f0f1464ce3592f76d0f0079ce9fc2d4272594f995bf3d1a7ede4cd5031452e +workflow-job:1609.v8926e7962024:1f63a3dc4e9f8bfbde7b759530da4073e105a92fee3b647962d981de223ac8f5 +workflow-multibranch:842.v3a_b_59b_57b_e6e:af26afd93b5d730d203d8f58d1e104712ad1a7ddcf6837886d3272b1c0057e46 +workflow-scm-step:487.v41313a_96b_65d:532fc247cba83845df3c7fccaabfc3cb1f637729b145211728bcb974a3a67552 +workflow-step-api:724.v538c2362b_dfb_:887491de444174228471993b0b2db958db2e7fb577857c8516c58e9618049896 +workflow-support:1015.v785e5a_b_b_8b_22:914ee717ab8c1d60d0d3ea49a1af11e4ea65c1e74c0b44dc3522f9a2fe5b2a8e diff --git a/pricing.py b/pricing.py new file mode 100644 index 0000000..446eda4 --- /dev/null +++ b/pricing.py @@ -0,0 +1,4 @@ +def total_price(unit_price, quantity): + if quantity < 1: + raise ValueError("Quantity must be positive") + return unit_price * quantity diff --git a/tests/test_pricing.py b/tests/test_pricing.py new file mode 100644 index 0000000..573f010 --- /dev/null +++ b/tests/test_pricing.py @@ -0,0 +1,11 @@ +import unittest +from pricing import total_price + + +class PricingTests(unittest.TestCase): + def test_total(self): + self.assertEqual(total_price(10, 3), 30) + + def test_invalid_quantity(self): + with self.assertRaises(ValueError): + total_price(10, 0)