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

removing version from docker-compose file #80

Merged
merged 5 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixing docker-compose parsing issue
  • Loading branch information
awlawl committed May 12, 2023
commit 8b2422e2b9b3302215930632f1dc9f065c93aa28
4 changes: 2 additions & 2 deletions cmd/task_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func describe(cmd *cobra.Command, args []string) {
//ports
for _, p := range container.PortMappings {
service.Ports = append(service.Ports, dockercompose.Port{
Published: *p.ContainerPort,
Target: *p.ContainerPort,
PublishedAsInt: *p.ContainerPort,
Target: *p.ContainerPort,
})
}

Expand Down
12 changes: 6 additions & 6 deletions dockercompose/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestComposeV2(t *testing.T) {
if svc.Image != image {
t.Error("expecting image")
}
if svc.Ports[0].Published != publishedPort {
if svc.Ports[0].PublishedAsInt != publishedPort {
t.Error("expecting published port")
}
if svc.Ports[0].Target != targetPort {
Expand All @@ -63,7 +63,7 @@ func TestComposeV24(t *testing.T) {
if svc.Image != image {
t.Error("expecting image")
}
if svc.Ports[0].Published != publishedPort {
if svc.Ports[0].PublishedAsInt != publishedPort {
t.Error("expecting published port")
}
if svc.Ports[0].Target != targetPort {
Expand All @@ -89,7 +89,7 @@ func TestComposeV32Short(t *testing.T) {
if svc.Image != image {
t.Error("expecting image")
}
if svc.Ports[0].Published != publishedPort {
if svc.Ports[0].PublishedAsInt != publishedPort {
t.Error("expecting published port")
}
if svc.Ports[0].Target != targetPort {
Expand All @@ -111,7 +111,7 @@ func TestComposeV32Long(t *testing.T) {
if svc.Image != image {
t.Error("expecting image")
}
if svc.Ports[0].Published != publishedPort {
if svc.Ports[0].PublishedAsInt != publishedPort {
t.Error("expecting published port")
}
if svc.Ports[0].Target != targetPort {
Expand All @@ -133,8 +133,8 @@ func TestComposeV37(t *testing.T) {
if svc.Image != image {
t.Error("expecting image")
}
if svc.Ports[0].Published != publishedPort {
t.Error("expecting published port")
if svc.Ports[0].PublishedAsInt != publishedPort {
t.Errorf("expecting published port to be %d, was %d", publishedPort, svc.Ports[0].PublishedAsInt)
}
if svc.Ports[0].Target != targetPort {
t.Error("expecting published port")
Expand Down
19 changes: 14 additions & 5 deletions dockercompose/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ type Service struct {

// Port represents a port
type Port struct {
Published int64 `yaml:"published"`
Target int64 `yaml:"target"`
PublishedAsString string `yaml:"published"`
PublishedAsInt int64
Target int64 `yaml:"target"`
}

// used to parse the short syntax
Expand Down Expand Up @@ -73,8 +74,9 @@ func UnmarshalComposeYAML(yamlBytes []byte) (DockerCompose, error) {
return result, err
}
ports = append(ports, Port{
Published: published,
Target: target,
PublishedAsInt: published,
PublishedAsString: portString[0],
Target: target,
})
}

Expand All @@ -87,12 +89,19 @@ func UnmarshalComposeYAML(yamlBytes []byte) (DockerCompose, error) {
}
}
} else { //error unmarshaling short syntax

//try long syntax
err := yaml.Unmarshal(yamlBytes, &result)
if err != nil {
return result, nil
}

for _, svc := range result.Services {
//convert ports
for i, _ := range svc.Ports {
svc.Ports[i].PublishedAsInt, _ = strconv.ParseInt(svc.Ports[i].PublishedAsString, 10, 64)
}
}

}

return result, nil
Expand Down