Skip to content

Commit

Permalink
removing version from docker-compose file (#80)
Browse files Browse the repository at this point in the history
* removing version from DC file
* fixing docker-compose parsing issue
* removing old test
* tweaking build perms
  • Loading branch information
awlawl authored May 12, 2023
1 parent 2a481b8 commit 5abb3c3
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ jobs:
- name: Push up a new pre-release
if: ${{ contains(github.ref,'pre')}}
env:
GITHUB_TOKEN: ${{ secrets.SECRET_GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: make prerelease

- name: Push up a new normal release
if: ${{ !contains(github.ref,'pre')}}
env:
GITHUB_TOKEN: ${{ secrets.SECRET_GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: make release
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
2 changes: 1 addition & 1 deletion dockercompose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (composeFile *ComposeFile) Read() error {
return fmt.Errorf("unmarshalling docker compose yaml: %w", err)
}
if len(compose.Services) == 0 {
return errors.New("unable to parse compose file")
return errors.New("unable to parse compose file, no services found")
}
composeFile.Data = compose
return nil
Expand Down
37 changes: 6 additions & 31 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,33 +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].Target != targetPort {
t.Error("expecting published port")
}
if svc.Labels[labelKey] != labelValue {
t.Error("expecting label")
}
if svc.Secrets[secretKey] != secretValue {
t.Error("expecting secret")
}
}

// 3.8
func TestComposeV38(t *testing.T) {
f, e := doTest(t, "v3.8.yml")
if e != nil {
t.Error(e)
return
}
svc := f.Data.Services["web"]
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
Loading

0 comments on commit 5abb3c3

Please sign in to comment.