forked from GoogleCloudPlatform/scion
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: replace scion-* heuristic with format-based image registry dete… #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
zeroasterisk
wants to merge
1
commit into
ptone:main
from
zeroasterisk:feat/format-based-image-rewrite
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3230,6 +3230,10 @@ telemetry: | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // --- RewriteImageRegistry tests --- | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // Format-based detection: if the first path component contains a "." or ":" | ||||||||||||||||||||||||||||||||||||||
| // it is treated as a registry domain → image kept as-is. | ||||||||||||||||||||||||||||||||||||||
| // Otherwise (bare name or relative path) → rewrite to newRegistry. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| func TestRewriteImageRegistry(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||
| tests := []struct { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -3238,35 +3242,104 @@ func TestRewriteImageRegistry(t *testing.T) { | |||||||||||||||||||||||||||||||||||||
| newRegistry string | ||||||||||||||||||||||||||||||||||||||
| want string | ||||||||||||||||||||||||||||||||||||||
| }{ | ||||||||||||||||||||||||||||||||||||||
| // --- Bare scion-* names → rewritten --- | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "rewrite scion image", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "us-central1-docker.pkg.dev/example-project/scion-images/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| name: "bare scion image with tag", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "rewrite with trailing slash", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "us-central1-docker.pkg.dev/example-project/scion-images/scion-gemini:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg/", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-gemini:latest", | ||||||||||||||||||||||||||||||||||||||
| name: "bare scion image no tag", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "scion-claude", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-claude", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "bare scion image with custom tag", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "scion-base:v2", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "docker.io/myuser", | ||||||||||||||||||||||||||||||||||||||
| want: "docker.io/myuser/scion-base:v2", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // --- Bare non-scion names → rewritten (new behavior) --- | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "bare non-scion image with tag", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "my-custom-agent:v2", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/my-custom-agent:v2", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "do not rewrite non-scion image", | ||||||||||||||||||||||||||||||||||||||
| name: "bare ubuntu image with tag", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "ubuntu:22.04", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "ubuntu:22.04", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/ubuntu:22.04", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "bare image no tag", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "my-agent", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/my-agent", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // --- Relative path (no domain) → rewritten --- | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "relative path library/scion-claude", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "library/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "relative path myorg/myimage", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "myorg/myimage:v1", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/other", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/other/myimage:v1", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // --- Fully qualified with registry domain → NOT rewritten --- | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "fully qualified ghcr.io", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "ghcr.io/myorg/scion-elixir:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "us-docker.pkg.dev/proj/repo", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-elixir:latest", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "fully qualified us-docker.pkg.dev", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "us-docker.pkg.dev/ptone-misc/scion-alt/scion-elixir:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "us-docker.pkg.dev/ptone-misc/scion-alt/scion-elixir:latest", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "fully qualified docker.io", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "docker.io/library/ubuntu:22.04", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "docker.io/library/ubuntu:22.04", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "fully qualified custom registry with port", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "localhost:5000/myimage:dev", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "localhost:5000/myimage:dev", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3318
to
+3323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test case to verify that
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "fully qualified custom.registry:5000", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "custom.registry:5000/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "custom.registry:5000/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "do not rewrite custom registry image", | ||||||||||||||||||||||||||||||||||||||
| name: "fully qualified myregistry.io", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "myregistry.io/custom-agent:v1", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "myregistry.io/custom-agent:v1", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // --- Edge cases --- | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "empty registry returns original", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "us-central1-docker.pkg.dev/example-project/scion-images/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "", | ||||||||||||||||||||||||||||||||||||||
| want: "us-central1-docker.pkg.dev/example-project/scion-images/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| want: "scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "empty image returns empty", | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -3275,28 +3348,28 @@ func TestRewriteImageRegistry(t *testing.T) { | |||||||||||||||||||||||||||||||||||||
| want: "", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "scion-base image is rewritten", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "us-central1-docker.pkg.dev/example-project/scion-images/scion-base:v2", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "docker.io/myuser", | ||||||||||||||||||||||||||||||||||||||
| want: "docker.io/myuser/scion-base:v2", | ||||||||||||||||||||||||||||||||||||||
| name: "trailing slash on newRegistry is stripped", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "scion-gemini:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg/", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-gemini:latest", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "preserves tag", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "us-central1-docker.pkg.dev/example-project/scion-images/scion-opencode:sha-abc123", | ||||||||||||||||||||||||||||||||||||||
| name: "sha256 digest bare name", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "scion-claude@sha256:abc123def456", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-opencode:sha-abc123", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-claude@sha256:abc123def456", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "bare image name (no registry prefix)", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "ghcr.io/myorg", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| name: "sha256 digest fully qualified", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "ghcr.io/myorg/scion-claude@sha256:abc123def456", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "docker.io/other", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-claude@sha256:abc123def456", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| name: "bare image name empty registry", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "scion-gemini:latest", | ||||||||||||||||||||||||||||||||||||||
| name: "fully qualified empty registry returns original", | ||||||||||||||||||||||||||||||||||||||
| fullImage: "ghcr.io/myorg/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| newRegistry: "", | ||||||||||||||||||||||||||||||||||||||
| want: "scion-gemini:latest", | ||||||||||||||||||||||||||||||||||||||
| want: "ghcr.io/myorg/scion-claude:latest", | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the Docker/OCI reference parsing convention,
localhostis explicitly recognized as a registry domain even if it does not contain a.or:. Currently, an image reference likelocalhost/myimage:latestwould not be recognized as fully qualified and would be incorrectly rewritten. Adding an explicit check forlocalhostensures full compliance with the Docker/OCI convention.