Skip to content

cbscore: support local registries and container reuse#29

Open
UweSchwaeke wants to merge 2 commits intoclyso:mainfrom
UweSchwaeke:wip-cbsbuild-handle-local-registry
Open

cbscore: support local registries and container reuse#29
UweSchwaeke wants to merge 2 commits intoclyso:mainfrom
UweSchwaeke:wip-cbsbuild-handle-local-registry

Conversation

@UweSchwaeke
Copy link
Collaborator

  • what:
    add flag to bypass tls certificate verification for skopeo. check
    skopeo return code when finding an image on the registry.
    ignore rpm install failure if the package is already installed.

  • why:
    local container registries don't need valid tls certificates or may
    use self-signed ones. skopeo verifies certificates by default unless
    --tls-verify=false is passed.

  • note:
    this also makes the container reusable for debugging. currently,
    rpm install fails with return code 2 if the package is already installed.
    in a production environment, containers are generated from scratch,
    so this issue does not arise.

@UweSchwaeke UweSchwaeke marked this pull request as ready for review February 11, 2026 11:24
@UweSchwaeke UweSchwaeke force-pushed the wip-cbsbuild-handle-local-registry branch from a1d3d68 to ccf7069 Compare February 23, 2026 19:37
@UweSchwaeke UweSchwaeke force-pushed the wip-cbsbuild-handle-local-registry branch 2 times, most recently from 2cd5da2 to 5b9f667 Compare March 11, 2026 14:40
)
if rc != 0:
logger.debug(stdout)
if rc == 2 and re.search("already installed", stderr):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic number here. Maybe use the 'errno module? according to errno, '2' will be "ENOENT":

1 = EPERM
2 = ENOENT

So, import errno and use errno.ENOENT here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestingly, I wouldn't expect rpm to return ENOENT in this case though. Are we absolutely sure it's a 2 being returned here instead of a 17 (i.e., EEXIST)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, turns out this is not an error code -- instead, this is "the number of failed operations". E.g.,

➜ joao@behemoth cbs.git git:(wip/ceph-debug-component) ✗ sudo rpm -Uvh $(seq 1 3); echo $?
error: open of 1 failed: No such file or directory
error: open of 2 failed: No such file or directory
error: open of 3 failed: No such file or directory
3

So we can't reliably rely on the return code. We must only rely on the error message and the fact that rc != 0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this behavior of rpm is awlward, still 2 might be the right retcode here becase we don't install 1\n2\n3.

nevertheless i removed made a precondition to only install it if rpm -q cosign doesn't return 0.

msg = f"error inspecting image '{img}': {err}"
logger.error(msg)
if re.match(r".*not\s+found.*", err):
if retcode == 2 or re.match(r".*not\s+found.*", err):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here as before, use errno.ENOENT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, here using errno.ENOENT makes sense, unlike the comment on the other patch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can change it, but skopeo uses 2 as a return value instead of the ENOENT. I know its bad to use magic numbers but if we give them a meaning than i would prefer to make a constant out of it, instead of ENOENT.
Replaced it with SKOPEO_IMAGE_NOT_FOUND_RETCODE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENOENT is 2 though, is it not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure but skopeo uses the magic number 2 not os.ErrNotExist. thats the reason why i thought its not good to rely on ENOENT but i will change it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to ENOENT

)
if rc != 0:
logger.debug(stdout)
if rc == 2 and re.search("already installed", stderr):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, turns out this is not an error code -- instead, this is "the number of failed operations". E.g.,

➜ joao@behemoth cbs.git git:(wip/ceph-debug-component) ✗ sudo rpm -Uvh $(seq 1 3); echo $?
error: open of 1 failed: No such file or directory
error: open of 2 failed: No such file or directory
error: open of 3 failed: No such file or directory
3

So we can't reliably rely on the return code. We must only rely on the error message and the fact that rc != 0.

msg = f"error inspecting image '{img}': {err}"
logger.error(msg)
if re.match(r".*not\s+found.*", err):
if retcode == 2 or re.match(r".*not\s+found.*", err):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, here using errno.ENOENT makes sense, unlike the comment on the other patch.

@UweSchwaeke UweSchwaeke force-pushed the wip-cbsbuild-handle-local-registry branch 4 times, most recently from 3902936 to 3e9ca43 Compare March 12, 2026 14:23
@UweSchwaeke UweSchwaeke requested a review from jecluis March 12, 2026 14:24
@UweSchwaeke UweSchwaeke force-pushed the wip-cbsbuild-handle-local-registry branch 2 times, most recently from e1a2f11 to 636cac6 Compare March 18, 2026 11:32
* what:
  if the return code of the rpm process is 2, check if the failure
  reason is that the package is already installed.

* why:
  when reusing a container, the package might already be present.
  this occurs when a build runner job must be debugged.

Signed-off-by: Uwe Schwaeke <uwe.schwaeke@clyso.com>
* what:
  add option --tls-verify to subcommands build and runner build.
  pass the tls-verify flag to skopeo when querying the registry.
  check if the return value from skopeo inspect equals
  "not found" (exit code 2).

* why:
  if the image is pushed to a local container registry with a
  self-signed certificate, skopeo must not verify the certificate
  to avoid errors. current versions of skopeo (1.20.0) return exit
  code 2 if an image is not found.

Signed-off-by: Uwe Schwaeke <uwe.schwaeke@clyso.com>
@UweSchwaeke UweSchwaeke force-pushed the wip-cbsbuild-handle-local-registry branch from 636cac6 to 98d78f8 Compare March 18, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants