Commit 1c277e3
authored
fix: resolve BASE_REPO variable scope issue (#17)
## Problem
The `BASE_REPO` variable was only defined inside the repository
allowlist validation block (step 3), but it was being used later in the
image existence check (step 5). This caused the variable to be empty
when `verify_image_existence` was enabled, leading to validation
failures.
## Root Cause
In the image validation loop:
- `BASE_REPO` extraction logic was inside the `if [ -n "$ALLOWED_REPOS"
]` block (lines 433-440)
- The image existence check at line 524 used
`CANONICAL_IMAGE="${BASE_REPO}:${TAG}"`
- When `ALLOWED_REPOS` was set, `BASE_REPO` was defined and everything
worked
- However, the variable was being used outside its scope, which is a
logic error
## Solution
- **Move BASE_REPO extraction logic** outside the conditional block
(before step 4)
- Now `BASE_REPO` is always available for both repository validation and
image existence check
- Update step numbering in comments: steps 4-7 instead of 3-5
- Add explicit logging of `BASE_REPO` value for debugging
## Changes
```diff
# 2. Extract repository and tag
REPO="${image%:*}"
TAG="${image##*:}"
+# 3. Extract base repository name (always, needed for multiple validations)
+BASE_REPO="$REPO"
+if [[ "$REPO" =~ / ]]; then
+ if [[ "$REPO" =~ ^[a-z0-9.-]+\.[a-z]{2,}/ ]] || [[ "$REPO" =~ ^gcr\.io/ ]] || [[ "$REPO" =~ ^.*\.gcr\.io/ ]]; then
+ BASE_REPO="${REPO#*/}"
+ fi
+fi
+echo " Base repository: $BASE_REPO"
+
-# 3. Check repository is in allowlist (if configured)
+# 4. Check repository is in allowlist (if configured)
if [ -n "$ALLOWED_REPOS" ]; then
- BASE_REPO="$REPO" # ← Was only defined here
- if [[ "$REPO" =~ / ]]; then
- ...
- fi
...
fi
```
## Testing
This fixes the validation failure in [PR
#362](dotCMS/deutschebank-infrastructure#362)
where the image existence check was failing due to empty `BASE_REPO`
variable.
After this fix is merged and v1.1.1 tag is recreated, PR #362 should
pass all validations.
## Related
- Fixes issue discovered in deutschebank-infrastructure PR #362
- Related to #15 (subshell fixes)
- Related to #16 (second subshell fix)1 parent 2338b52 commit 1c277e3
1 file changed
+20
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
421 | 437 | | |
422 | 438 | | |
423 | 439 | | |
424 | 440 | | |
425 | 441 | | |
426 | 442 | | |
427 | 443 | | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | 444 | | |
443 | 445 | | |
444 | 446 | | |
| |||
460 | 462 | | |
461 | 463 | | |
462 | 464 | | |
463 | | - | |
| 465 | + | |
464 | 466 | | |
465 | 467 | | |
466 | 468 | | |
| |||
472 | 474 | | |
473 | 475 | | |
474 | 476 | | |
475 | | - | |
| 477 | + | |
476 | 478 | | |
477 | 479 | | |
478 | 480 | | |
| |||
517 | 519 | | |
518 | 520 | | |
519 | 521 | | |
520 | | - | |
| 522 | + | |
521 | 523 | | |
522 | 524 | | |
523 | 525 | | |
| |||
0 commit comments