Skip to content

SNOW-3202214: add custom image register command#2869

Open
sfc-gh-ajiang wants to merge 6 commits intomainfrom
ajiang_SNOW-3202214_cre_register
Open

SNOW-3202214: add custom image register command#2869
sfc-gh-ajiang wants to merge 6 commits intomainfrom
ajiang_SNOW-3202214_cre_register

Conversation

@sfc-gh-ajiang
Copy link
Copy Markdown
Contributor

@sfc-gh-ajiang sfc-gh-ajiang commented Apr 9, 2026

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.
  • I've described my changes in the documentation.

Changes description

  1. create a new command to register the custom runtime environment
    snow custom-image register [local docker image name/hash] [spcs image registry url] [--skip-validarion] [--base-image-type] [--name]
  • --skip-validation: if users add this flag, we only push the local images to the spcs image repo; if not, after pushing the local images to the spcs image repo, we will have validation on that image
  • --base-image-type: this is required if users do not have the flag --skip-validation
  1. add metrics for the snow custom-images validate and require snowflake connection for snow custom-images validate

@sfc-gh-ajiang sfc-gh-ajiang requested a review from a team as a code owner April 9, 2026 18:45
@sfc-gh-ajiang sfc-gh-ajiang changed the title add custom image register command SNOW-3202214: add custom image register command Apr 9, 2026
@sfc-gh-ajiang sfc-gh-ajiang force-pushed the ajiang_SNOW-3202214_cre_register branch 2 times, most recently from a65a7a5 to 50a4128 Compare April 9, 2026 20:22
@sfc-gh-ajiang sfc-gh-ajiang force-pushed the ajiang_SNOW-3202214_cre_register branch from 50a4128 to 06adc06 Compare April 9, 2026 20:58
@sfc-gh-ajiang sfc-gh-ajiang force-pushed the ajiang_SNOW-3202214_cre_register branch from 4e49059 to 44fd8ac Compare April 9, 2026 21:44
@sfc-gh-ajiang sfc-gh-ajiang force-pushed the ajiang_SNOW-3202214_cre_register branch from 9e8ab9d to 887c0bc Compare April 10, 2026 01:16


@app.command(requires_connection=False)
def register(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be requires_connection=True? When --skip-validation is not set, register() ends up calling self.execute_query() to create the CRE, which needs an active Snowflake connection. As-is I think users will hit a runtime error on that path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Thanks!

return MessageResult(message)


@app.command(requires_connection=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was this change intentional? validate used to be requires_connection=False. The validate() method itself doesn't call execute_query() — if this is needed so the CLI framework can flush the new metrics back to Snowflake on teardown, that makes sense, but it's a behavioral change for anyone currently running snow custom-image validate without connection params. Might be worth calling out in the PR description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this change is intentional. I added it to ensure we can collect metrics. It looks like there haven’t been any recent releases, so snow custom-image validate has not been published yet.


image_path = self._parse_image_path(registry)
sql = (
f"CREATE CUSTOM RUNTIME ENVIRONMENT {cre_name} "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: cre_name comes straight from --name user input and gets interpolated directly into the SQL string. A name with spaces or special characters will produce malformed SQL. Might want to validate it against something like [a-zA-Z0-9_]+ or use identifier quoting.


# Push the tagged image to the registry
returncode, _, stderr = self._run_docker_command(
["docker", "push", registry], timeout=600
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does _run_docker_command actually accept a timeout kwarg? I don't see it forwarding to subprocess.run in the existing code — if it doesn't, this is either silently ignored or blows up with a TypeError.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

-> '/db/schema/repo/image:tag'
"""
slash_idx = registry.find("/")
if slash_idx == -1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the registry has no / (bare hostname or something malformed), this returns the whole string as the image path, which would produce bogus SQL downstream. Probably worth raising a ClickException here instead of silently returning garbage.

fix precommit errors
@sfc-gh-ajiang sfc-gh-ajiang force-pushed the ajiang_SNOW-3202214_cre_register branch from 88c6fe1 to b4220cb Compare April 10, 2026 20:44
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