Skip to content

Commit ac8bd37

Browse files
authored
Merge pull request #395 from oasisprotocol/matevz/feature/detect-compose-file
rofl: Detect compose-like file on init, if it exists
2 parents 225989e + 05e9aad commit ac8bd37

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

cmd/rofl/mgmt.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,8 @@ var (
9797
artifacts := buildRofl.LatestBasicArtifacts // Copy.
9898
manifest.Artifacts = &artifacts
9999
case buildRofl.AppKindContainer:
100-
// For container app kind also create an en empty compose.yaml file if it doesn't exist.
101-
var f *os.File
102-
f, err = os.OpenFile("compose.yaml", os.O_RDONLY|os.O_CREATE, 0o644)
103-
if err == nil {
104-
f.Close()
105-
}
106-
107100
artifacts := buildRofl.LatestContainerArtifacts // Copy.
101+
artifacts.Container.Compose = detectOrCreateComposeFile()
108102
manifest.Artifacts = &artifacts
109103
default:
110104
}
@@ -642,6 +636,24 @@ var (
642636
}
643637
)
644638

639+
// detectAndCreateComposeFile detects the existing compose.yaml-like file and returns its filename. Otherwise, creates an empty default compose.yaml.
640+
func detectOrCreateComposeFile() string {
641+
for _, filename := range []string{"docker-compose.yaml", "docker-compose.yml", "compose.yml"} {
642+
if _, err := os.Stat(filename); err == nil {
643+
return filename
644+
}
645+
}
646+
647+
filename := "compose.yaml"
648+
f, err := os.OpenFile(filename, os.O_RDONLY|os.O_CREATE, 0o644)
649+
if err != nil {
650+
return ""
651+
}
652+
653+
f.Close()
654+
return filename
655+
}
656+
645657
func init() {
646658
deploymentFlags := flag.NewFlagSet("", flag.ContinueOnError)
647659
deploymentFlags.StringVar(&deploymentName, "deployment", buildRofl.DefaultDeploymentName, "deployment name")

0 commit comments

Comments
 (0)