@@ -60,7 +60,7 @@ func isDCVersionLaterThan2(dcVersion string) bool {
60
60
func (dc DockerComposeDriver ) parseDCFileVersion (contents string ) (float64 , error ) {
61
61
firstLine := strings .Split (contents , "\n " )[0 ]
62
62
if ! strings .HasPrefix (firstLine , "version" ) {
63
- return 0 , fmt . Errorf ( "First line of docker-compose file did not start with: version" )
63
+ return - 1 , nil
64
64
}
65
65
versionQuoted := strings .Split (firstLine , ":" )[1 ]
66
66
versionQuoted = strings .Trim (versionQuoted , " " )
@@ -78,7 +78,7 @@ func (dc DockerComposeDriver) verifyDCFile(fileContents string, filePath string)
78
78
if err != nil {
79
79
return 0 , err
80
80
}
81
- if version < 2 || version >= 3 {
81
+ if version != - 1 && ( version < 2 || version >= 3 ) {
82
82
return 0 , fmt .Errorf ("docker-compose file: %s should contain version number >=2 and <3, current version: %v" , filePath , version )
83
83
}
84
84
requiredStr := "default:"
@@ -129,12 +129,18 @@ func (dc DockerComposeDriver) generateDCFileContentsWithEnv(expContainers []stri
129
129
}
130
130
131
131
func (dc DockerComposeDriver ) generateInitialDCFile (config Config , version float64 ) string {
132
- contents := fmt .Sprintf (
132
+ if version == - 1 {
133
+ // version was not set
134
+ return fmt .Sprintf (
135
+ `services:
136
+ default:
137
+ image: "%s"` , config .DockerImage )
138
+ }
139
+ return fmt .Sprintf (
133
140
`version: '%v'
134
141
services:
135
142
default:
136
- image: %s` , version , config .DockerImage )
137
- return contents
143
+ image: "%s"` , version , config .DockerImage )
138
144
}
139
145
140
146
func (dc DockerComposeDriver ) ConstructDockerComposeCommandPart1 (config Config , projectName string ) string {
@@ -701,24 +707,24 @@ func (dc DockerComposeDriver) getDCContainersNames(mergedConfig Config, projectN
701
707
}
702
708
703
709
type DC2PSOutput struct {
704
- Command string `json:"Command"`
705
- CreatedAt string `json:"CreatedAt"`
706
- ExitCode int `json:"ExitCode"`
707
- Health string `json:"Health"`
708
- ID string `json:"ID"`
709
- Image string `json:"Image"`
710
- Labels string `json:"Labels"`
711
- Name string `json:"Name"`
712
- Names string `json:"Names"`
713
- Networks string `json:"Networks"`
714
- Ports string `json:"Ports"`
715
- Project string `json:"Project"`
716
- Publishers string `json:"Publishers"`
717
- RunningFor string `json:"RunningFor"`
718
- Service string `json:"Service"`
719
- Size string `json:"Size"`
720
- State string `json:"State"`
721
- Status string `json:"Status"`
710
+ Command string `json:"Command"`
711
+ CreatedAt string `json:"CreatedAt"`
712
+ ExitCode int `json:"ExitCode"`
713
+ Health string `json:"Health"`
714
+ ID string `json:"ID"`
715
+ Image string `json:"Image"`
716
+ Labels string `json:"Labels"`
717
+ Name string `json:"Name"`
718
+ Names string `json:"Names"`
719
+ Networks string `json:"Networks"`
720
+ Ports string `json:"Ports"`
721
+ Project string `json:"Project"`
722
+ Publishers [] string `json:"Publishers"`
723
+ RunningFor string `json:"RunningFor"`
724
+ Service string `json:"Service"`
725
+ Size string `json:"Size"`
726
+ State string `json:"State"`
727
+ Status string `json:"Status"`
722
728
}
723
729
724
730
// Parses the output of the `docker-compose ps --format json --all` command, into json.
@@ -728,6 +734,9 @@ type DC2PSOutput struct {
728
734
// {"Command":"\"/bin/sh -c 'while t…\"","CreatedAt":"2024-02-03 21:03:46 +0000 UTC","ExitCode":0,"Health":"","ID":"2d5c5b0343d0","Image":"alpine:3.19","Labels":"com.docker.compose.depends_on=,com.docker.compose.image=sha256:05455a08881ea9cf0e752bc48e61bbd71a34c029bb13df01e40e3e70e0d007bd,com.docker.compose.version=2.24.5,com.docker.compose.service=abc,com.docker.compose.config-hash=270e27422cb1e6a4c1713ae22a3ffca0e8aa50ec0f06fe493fa4f83a17bd29e9,com.docker.compose.container-number=1,com.docker.compose.oneoff=False,com.docker.compose.project=testdojorunid,com.docker.compose.project.config_files=/dojo/work/test/test-files/itest-dc.yaml,/dojo/work/test/test-files/itest-dc.yaml.dojo,com.docker.compose.project.working_dir=/dojo/work/test/test-files","LocalVolumes":"0","Mounts":"/tmp/test-dojo…,/tmp/test-dojo…","Name":"testdojorunid-abc-1","Names":"testdojorunid-abc-1","Networks":"testdojorunid_default","Ports":"","Project":"testdojorunid","Publishers":null,"RunningFor":"3 seconds ago","Service":"abc","Size":"0B","State":"running","Status":"Up 2 seconds"}
729
735
// {"Command":"\"/bin/sh -c 'while t…\"","CreatedAt":"2024-02-03 21:03:46 +0000 UTC","ExitCode":0,"Health":"","ID":"b2ed210567c3","Image":"alpine:3.19","Labels":"com.docker.compose.project=testdojorunid,com.docker.compose.project.config_files=/dojo/work/test/test-files/itest-dc.yaml,/dojo/work/test/test-files/itest-dc.yaml.dojo,com.docker.compose.project.working_dir=/dojo/work/test/test-files,com.docker.compose.depends_on=,com.docker.compose.container-number=1,com.docker.compose.image=sha256:05455a08881ea9cf0e752bc48e61bbd71a34c029bb13df01e40e3e70e0d007bd,com.docker.compose.oneoff=False,com.docker.compose.service=def,com.docker.compose.version=2.24.5,com.docker.compose.config-hash=270e27422cb1e6a4c1713ae22a3ffca0e8aa50ec0f06fe493fa4f83a17bd29e9","LocalVolumes":"0","Mounts":"/tmp/test-dojo…,/tmp/test-dojo…","Name":"testdojorunid-def-1","Names":"testdojorunid-def-1","Networks":"testdojorunid_default","Ports":"","Project":"testdojorunid","Publishers":null,"RunningFor":"3 seconds ago","Service":"def","Size":"0B","State":"running","Status":"Up 2 seconds"}
730
736
// {"Command":"\"sh -c 'sleep 10'\"","CreatedAt":"2024-02-03 21:03:47 +0000 UTC","ExitCode":0,"Health":"","ID":"af4817fede41","Image":"alpine:3.15","Labels":"com.docker.compose.version=2.24.5,com.docker.compose.container-number=1,com.docker.compose.depends_on=abc:service_started:true,def:service_started:true,com.docker.compose.oneoff=True,com.docker.compose.project=testdojorunid,com.docker.compose.slug=742bcbb0e4bc05b21928a8d17be4ea9bb12a6775fd40692dd59c74a460279eb8,com.docker.compose.config-hash=462afacb4521d13580c2096c7b00b98970f07fe841e408c4c5a95a4a46839eaa,com.docker.compose.image=sha256:32b91e3161c8fc2e3baf2732a594305ca5093c82ff4e0c9f6ebbd2a879468e1d,com.docker.compose.project.config_files=/dojo/work/test/test-files/itest-dc.yaml,/dojo/work/test/test-files/itest-dc.yaml.dojo,com.docker.compose.project.working_dir=/dojo/work/test/test-files,com.docker.compose.service=default","LocalVolumes":"0","Mounts":"/home/dojo,/dojo/work,/tmp/test-dojo…,/tmp/test-dojo…,/tmp/.X11-unix,/tmp/dojo-ites…","Name":"testdojorunid-default-run-742bcbb0e4bc","Names":"testdojorunid-default-run-742bcbb0e4bc","Networks":"testdojorunid_default","Ports":"","Project":"testdojorunid","Publishers":null,"RunningFor":"2 seconds ago","Service":"default","Size":"0B","State":"running","Status":"Up 1 second"}
737
+ //
738
+ // when using docker-compose: 2.31m the field with Publishers is set to []:
739
+ // {"Command":"\"/bin/sh -c 'while t…\"","CreatedAt":"2024-12-20 15:58:00 +1300 NZDT","ExitCode":143,"Health":"","ID":"f543828473a7","Image":"alpine:3.19","Labels":"com.docker.compose.image=sha256:7a85bf5dc56c949be827f84f9185161265c58f589bb8b2a6b6bb6d3076c1be21,desktop.docker.io/binds/0/Source=/tmp/dojo-environment-multiline-dojo-test-files-2024-12-2015-58-00-6660523964295751458,desktop.docker.io/binds/0/SourceKind=hostFile,desktop.docker.io/binds/0/Target=/etc/dojo.d/variables/00-multiline-vars.sh,desktop.docker.io/binds/1/Target=/etc/dojo.d/variables/01-bash-functions.sh,com.docker.compose.oneoff=False,com.docker.compose.project.config_files=/Users/ava.czechowska/code/dojo/test/test-files/itest-dc.yaml,/Users/ava.czechowska/code/dojo/test/test-files/itest-dc.yaml.dojo,com.docker.compose.service=abc,desktop.docker.io/binds/1/SourceKind=hostFile,com.docker.compose.container-number=1,com.docker.compose.project.working_dir=/Users/ava.czechowska/code/dojo/test/test-files,com.docker.compose.config-hash=4439e404114c9d0f183d756084f3e0e80c56b731e1f1e14e6db1844134294969,com.docker.compose.depends_on=,com.docker.compose.project=dojo-test-files-2024-12-2015-58-00-6660523964295751458,com.docker.compose.version=2.31.0,desktop.docker.io/binds/1/Source=/tmp/dojo-environment-bash-functions-dojo-test-files-2024-12-2015-58-00-6660523964295751458","LocalVolumes":"0","Mounts":"/host_mnt/priv…,/host_mnt/priv…","Name":"dojo-test-files-2024-12-2015-58-00-6660523964295751458-abc-1","Names":"dojo-test-files-2024-12-2015-58-00-6660523964295751458-abc-1","Networks":"dojo-test-files-2024-12-2015-58-00-6660523964295751458_default","Ports":"","Project":"dojo-test-files-2024-12-2015-58-00-6660523964295751458","Publishers":[],"RunningFor":"36 seconds ago","Service":"abc","Size":"0B","State":"exited","Status":"Exited (143) 10 seconds ago"}
731
740
func ParseDCPSOutPut_DCVersion2 (output string ) ([]DC2PSOutput , string ) {
732
741
var output_as_jsons []DC2PSOutput
733
742
@@ -740,7 +749,7 @@ func ParseDCPSOutPut_DCVersion2(output string) ([]DC2PSOutput, string) {
740
749
err := json .Unmarshal ([]byte (line ), & one_output_as_json )
741
750
if err != nil {
742
751
return []DC2PSOutput {},
743
- fmt .Errorf ("Error when decoding the JSON response from docker-compose ps command: %s" , err ).Error ()
752
+ fmt .Errorf ("Error when decoding the JSON response from docker-compose ps command: %s; line %s " , err , line ).Error ()
744
753
}
745
754
if one_output_as_json .State == "" {
746
755
// This means that something went wrong, e.g. docker-compose ps output is now different
0 commit comments