SNOW-3202214: add custom image register command#2869
SNOW-3202214: add custom image register command#2869sfc-gh-ajiang wants to merge 6 commits intomainfrom
Conversation
a65a7a5 to
50a4128
Compare
50a4128 to
06adc06
Compare
4e49059 to
44fd8ac
Compare
9e8ab9d to
887c0bc
Compare
|
|
||
|
|
||
| @app.command(requires_connection=False) | ||
| def register( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good catch. Thanks!
| return MessageResult(message) | ||
|
|
||
|
|
||
| @app.command(requires_connection=True) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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} " |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I think we have forwarded it
https://github.com/snowflakedb/snowflake-cli/blob/main/src/snowflake/cli/_plugins/custom_images/manager.py#L143
| -> '/db/schema/repo/image:tag' | ||
| """ | ||
| slash_idx = registry.find("/") | ||
| if slash_idx == -1: |
There was a problem hiding this comment.
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
88c6fe1 to
b4220cb
Compare
Pre-review checklist
Changes description
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-validationsnow custom-images validateand require snowflake connection forsnow custom-images validate