Skip to content
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

fix: Support images with digests #23

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,16 @@ func (b *Bridge) add(containerId string, quiet bool) {
}
}

func getServiceNameFromImage(image string) string {
return strings.Split(
strings.Split(path.Base(image), ":")[0],
"@",
)[0]
}

func (b *Bridge) newService(port ServicePort, isgroup bool) *Service {
container := port.container
defaultName := strings.Split(path.Base(container.Config.Image), ":")[0]
defaultName := getServiceNameFromImage(container.Config.Image)

// not sure about this logic. kind of want to remove it.
hostname := Hostname
Expand Down
29 changes: 29 additions & 0 deletions bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,32 @@ func TestNewValid(t *testing.T) {
assert.NotNil(t, bridge)
assert.NoError(t, err)
}

func Test_getServiceNameFromImage(t *testing.T) {
tests := []struct {
name string
image string
service string
}{
{
name: "with tag",
image: "123456789012.dkr.ecr.eu-west-1.amazonaws.com/foo/bar:v1.2.3",
service: "bar",
},
{
name: "with digest",
image: "123456789012.dkr.ecr.eu-west-1.amazonaws.com/foo/bar@sha256:abcc3e12da56ecf5756b48502baa2a98d09e69c5d033dc37ce93de77dc6cb123",
service: "bar",
},
{
name: "with both",
image: "123456789012.dkr.ecr.eu-west-1.amazonaws.com/foo/bar:v1.2.3@sha256:abcc3e12da56ecf5756b48502baa2a98d09e69c5d033dc37ce93de77dc6cb123",
service: "bar",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.service, getServiceNameFromImage(tt.image), "getServiceNameFromImage(%v)", tt.image)
})
}
}
Loading