diff --git a/cmd/create/create.go b/cmd/create/create.go index 44fa460..ad3fa50 100644 --- a/cmd/create/create.go +++ b/cmd/create/create.go @@ -22,6 +22,7 @@ func NewCmdCreate() *cobra.Command { err error keepConfig bool canastaInfo canasta.CanastaVariables + override string ) createCmd := &cobra.Command{ Use: "create", @@ -32,7 +33,7 @@ func NewCmdCreate() *cobra.Command { log.Fatal(err) } fmt.Println("Creating Canasta installation '" + canastaInfo.Id + "'...") - if err = createCanasta(canastaInfo, pwd, path, orchestrator); err != nil { + if err = createCanasta(canastaInfo, pwd, path, orchestrator, override); err != nil { fmt.Print(err.Error(), "\n") if keepConfig { log.Fatal(fmt.Errorf("Keeping all the containers and config files\nExiting")) @@ -63,11 +64,12 @@ func NewCmdCreate() *cobra.Command { createCmd.Flags().StringVarP(&canastaInfo.AdminName, "WikiSysop", "a", "", "Initial wiki admin username") createCmd.Flags().StringVarP(&canastaInfo.AdminPassword, "password", "s", "", "Initial wiki admin password") createCmd.Flags().BoolVarP(&keepConfig, "keep-config", "k", false, "Keep the config files on installation failure") + createCmd.Flags().StringVarP(&override, "override", "r", "", "Name of a file to copy to docker-compose.override.yml") return createCmd } // importCanasta accepts all the keyword arguments and create a installation of the latest Canasta. -func createCanasta(canastaInfo canasta.CanastaVariables, pwd, path, orchestrator string) error { +func createCanasta(canastaInfo canasta.CanastaVariables, pwd, path, orchestrator, override string) error { if _, err := config.GetDetails(canastaInfo.Id); err == nil { log.Fatal(fmt.Errorf("Canasta installation with the ID already exist!")) } @@ -77,6 +79,9 @@ func createCanasta(canastaInfo canasta.CanastaVariables, pwd, path, orchestrator if err := canasta.CopyEnv("", canastaInfo.DomainName, path, pwd); err != nil { return err } + if err := orchestrators.CopyOverrideFile(path, orchestrator, override, pwd); err != nil { + return err + } if err := orchestrators.Start(path, orchestrator); err != nil { return err } diff --git a/cmd/import/importExisting.go b/cmd/import/importExisting.go index e4d88a8..92cc40c 100644 --- a/cmd/import/importExisting.go +++ b/cmd/import/importExisting.go @@ -20,6 +20,7 @@ func NewCmdCreate() *cobra.Command { databasePath string localSettingsPath string envPath string + override string canastaId string domainName string err error @@ -35,7 +36,7 @@ func NewCmdCreate() *cobra.Command { return err } fmt.Println("Importing Canasta") - if err := importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath, localSettingsPath, envPath); err != nil { + if err := importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath, localSettingsPath, envPath, override); err != nil { fmt.Print(err.Error(), "\n") if keepConfig { log.Fatal(fmt.Errorf("Keeping all the containers and config files\nExiting")) @@ -65,13 +66,14 @@ func NewCmdCreate() *cobra.Command { importCmd.Flags().StringVarP(&databasePath, "database", "d", "", "Path to the existing database dump") importCmd.Flags().StringVarP(&localSettingsPath, "localsettings", "l", "", "Path to the existing LocalSettings.php") importCmd.Flags().StringVarP(&envPath, "env", "e", "", "Path to the existing .env file") + importCmd.Flags().StringVarP(&override, "override", "r", "", "Name of a file to copy to docker-compose.override.yml") importCmd.Flags().BoolVarP(&keepConfig, "keep-config", "k", false, "Keep the config files on installation failure") return importCmd } // importCanasta copies LocalSettings.php and databasedump to create canasta from a previous mediawiki installation -func importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath, localSettingsPath, envPath string) error { +func importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath, localSettingsPath, envPath, override string) error { if _, err := config.GetDetails(canastaId); err == nil { log.Fatal(fmt.Errorf("Canasta installation with the ID already exist!")) } @@ -87,6 +89,9 @@ func importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath, if err := canasta.CopyLocalSettings(localSettingsPath, path, pwd); err != nil { return err } + if err := orchestrators.CopyOverrideFile(path, orchestrator, override, pwd); err != nil { + return err + } if err := orchestrators.Start(path, orchestrator); err != nil { return err } diff --git a/internal/orchestrators/orchestrators.go b/internal/orchestrators/orchestrators.go index 12b40d5..d40b0f9 100644 --- a/internal/orchestrators/orchestrators.go +++ b/internal/orchestrators/orchestrators.go @@ -37,6 +37,25 @@ func GetRepoLink(orchestrator string) string { return repo } +func CopyOverrideFile(path, orchestrator, sourceFilename, pwd string) error { + if sourceFilename != "" { + logging.Print("Copying override file\n") + switch orchestrator { + case "docker-compose": + sourceFilename = pwd + "/" + sourceFilename + var overrideFilename = path + "/docker-compose.override.yml" + logging.Print(fmt.Sprintf("Copying %s to %s\n", sourceFilename, overrideFilename)) + err, output := execute.Run("", "cp", sourceFilename, overrideFilename) + if err != nil { + logging.Fatal(fmt.Errorf(output)) + } + default: + logging.Fatal(fmt.Errorf("orchestrator: %s is not available", orchestrator)) + } + } + return nil +} + func Start(path, orchestrator string) error { logging.Print("Starting Canasta\n") switch orchestrator {