Skip to content

Commit 65969e4

Browse files
ericsmallingclaude
andcommitted
jenkins: mkdir DOCKER_CONFIG in cgLogin Mode B, harden django smoke test
Two Copilot findings from the seventh pass on PR #330: - cgLogin Mode B: mkdir -p "$DOCKER_CONFIG" eagerly even though we don't write creds. cgSign/cgVerify always bind-mount it into a sibling cosign container with `docker run -v "$DOCKER_CONFIG":...`; if the dir doesn't exist the host docker daemon auto-creates it as root, and a later switch to Mode A would then fail when chainctl (uid 1000 inside the controller) tries to write a fresh config there. Mode A/C already mkdir, only Mode B was missing it. - python312-pip-django/app.py: add an explicit django.setup() and a real (in-memory sqlite) DATABASES default. contrib.auth and contrib.contenttypes declare models and can trigger AppRegistryNot Ready / DB-config errors during app loading. The smoke test happens to pass today because the hello view never touches the registry, but the configuration is invalid per Django's contract — verified the fixed app round-trips the Test-stage Client().get('/') call. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8b352b0 commit 65969e4

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

jenkins/apps/python312-pip-django/app.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import platform
77
import sys
8+
import django
89
from django.conf import settings
910
from django.core.management import execute_from_command_line
1011
from django.http import HttpResponse
@@ -17,10 +18,25 @@
1718
ALLOWED_HOSTS=["*"],
1819
INSTALLED_APPS=["django.contrib.contenttypes", "django.contrib.auth"],
1920
MIDDLEWARE=[],
20-
DATABASES={},
21+
# In-memory SQLite — contrib.contenttypes and contrib.auth declare models
22+
# and need a `default` DB or app loading bombs out. We never touch the DB
23+
# at request time (the hello view returns a constant), so :memory: is fine.
24+
DATABASES={
25+
"default": {
26+
"ENGINE": "django.db.backends.sqlite3",
27+
"NAME": ":memory:",
28+
},
29+
},
2130
USE_TZ=True,
2231
)
2332

33+
# Initialise the app registry. `execute_from_command_line` (runserver path)
34+
# calls this internally, but the Test stage imports this module directly and
35+
# invokes django.test.Client without going through that codepath — without an
36+
# explicit setup() call the app registry stays unpopulated and the test fails
37+
# with AppRegistryNotReady the moment contrib.auth's signals fire.
38+
django.setup()
39+
2440

2541
def hello(request):
2642
import django

jenkins/shared-libraries/cg-images/vars/cgLogin.groovy

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,25 @@ EOF
5858
echo "cgLogin: configured Harbor admin auth for localhost / localhost:80 (Mode C)."
5959
'''
6060
} else {
61-
// Mode B: anonymous everywhere, nothing to write. PUSH_REGISTRY is
62-
// typically ttl.sh/<prefix> but setup.sh accepts any non-localhost
63-
// value, so log the actual target rather than hardcoding ttl.sh.
64-
// Pass pushRegistry through the sh-step environment rather than
65-
// interpolating into the script body — defends against shell
61+
// Mode B: anonymous everywhere, no creds to write. We still mkdir
62+
// $DOCKER_CONFIG eagerly so it exists with uid-1000 ownership before
63+
// cgSign/cgVerify bind-mount it into a sibling cosign container — if
64+
// the dir doesn't exist when `docker run -v "$DOCKER_CONFIG":...` runs,
65+
// the host docker daemon auto-creates it as root, and a later switch
66+
// to Mode A would then fail when chainctl (uid 1000 inside the
67+
// controller) tries to write a fresh docker config there.
68+
//
69+
// PUSH_REGISTRY is typically ttl.sh/<prefix> but setup.sh accepts any
70+
// non-localhost value, so log the actual target rather than hardcoding
71+
// ttl.sh. Pass pushRegistry through the sh-step environment rather
72+
// than interpolating into the script body — defends against shell
6673
// metacharacters in a user-supplied PUSH_REGISTRY value.
6774
withEnv(["PUSH_DISPLAY=${pushRegistry ?: '(unset)'}"]) {
68-
sh 'echo "cgLogin: Harbor mode, anonymous pulls + pushes to $PUSH_DISPLAY (Mode B)."'
75+
sh '''
76+
set -eu
77+
mkdir -p "$DOCKER_CONFIG"
78+
echo "cgLogin: Harbor mode, anonymous pulls + pushes to $PUSH_DISPLAY (Mode B)."
79+
'''
6980
}
7081
}
7182
return

0 commit comments

Comments
 (0)