Skip to content

Commit

Permalink
Merge pull request #23 from form3tech-oss/ab-fix-parsing-of-images-wi…
Browse files Browse the repository at this point in the history
…th-digests

fix: Support images with digests
  • Loading branch information
kevholditch-f3 authored Jul 3, 2024
2 parents af4b0fc + ea537a3 commit 06f7433
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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)
})
}
}

0 comments on commit 06f7433

Please # to comment.