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

Allow modification to default composer installed extensions #94

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewCmdCreate() *cobra.Command {
keepConfig bool
canastaInfo canasta.CanastaVariables
override string
composer string
)
createCmd := &cobra.Command{
Use: "create",
Expand All @@ -33,7 +34,7 @@ func NewCmdCreate() *cobra.Command {
log.Fatal(err)
}
fmt.Println("Creating Canasta installation '" + canastaInfo.Id + "'...")
if err = createCanasta(canastaInfo, pwd, path, orchestrator, override); err != nil {
if err = createCanasta(canastaInfo, pwd, path, orchestrator, override, composer); err != nil {
fmt.Print(err.Error(), "\n")
if keepConfig {
log.Fatal(fmt.Errorf("Keeping all the containers and config files\nExiting"))
Expand Down Expand Up @@ -65,11 +66,12 @@ func NewCmdCreate() *cobra.Command {
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")
createCmd.Flags().StringVarP(&composer, "composer", "c", "", "Name of a file to copy to composer.local.json")
return createCmd
}

// importCanasta accepts all the keyword arguments and create a installation of the latest Canasta.
func createCanasta(canastaInfo canasta.CanastaVariables, pwd, path, orchestrator, override string) error {
func createCanasta(canastaInfo canasta.CanastaVariables, pwd, path, orchestrator, override, composer string) error {
if _, err := config.GetDetails(canastaInfo.Id); err == nil {
log.Fatal(fmt.Errorf("Canasta installation with the ID already exist!"))
}
Expand All @@ -82,6 +84,9 @@ func createCanasta(canastaInfo canasta.CanastaVariables, pwd, path, orchestrator
if err := orchestrators.CopyOverrideFile(path, orchestrator, override, pwd); err != nil {
return err
}
if err := orchestrators.CopyComposerFile(path, orchestrator, composer, pwd); err != nil {
return err
}
if err := orchestrators.Start(path, orchestrator); err != nil {
return err
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/import/importExisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func NewCmdCreate() *cobra.Command {
localSettingsPath string
envPath string
override string
composer string
canastaId string
domainName string
err error
Expand All @@ -36,7 +37,7 @@ func NewCmdCreate() *cobra.Command {
return err
}
fmt.Println("Importing Canasta")
if err := importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath, localSettingsPath, envPath, override); err != nil {
if err := importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath, localSettingsPath, envPath, override, composer); err != nil {
fmt.Print(err.Error(), "\n")
if keepConfig {
log.Fatal(fmt.Errorf("Keeping all the containers and config files\nExiting"))
Expand Down Expand Up @@ -67,13 +68,14 @@ func NewCmdCreate() *cobra.Command {
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().StringVarP(&composer, "composer", "c", "", "Name of a file to copy to composer.local.json")
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, override string) error {
func importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath, localSettingsPath, envPath, override, composer string) error {
if _, err := config.GetDetails(canastaId); err == nil {
log.Fatal(fmt.Errorf("Canasta installation with the ID already exist!"))
}
Expand All @@ -92,6 +94,9 @@ func importCanasta(pwd, canastaId, domainName, path, orchestrator, databasePath,
if err := orchestrators.CopyOverrideFile(path, orchestrator, override, pwd); err != nil {
return err
}
if err := orchestrators.CopyComposerFile(path, orchestrator, composer, pwd); err != nil {
return err
}
if err := orchestrators.Start(path, orchestrator); err != nil {
return err
}
Expand Down
28 changes: 28 additions & 0 deletions internal/orchestrators/orchestrators.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ func CopyOverrideFile(path, orchestrator, sourceFilename, pwd string) error {
return nil
}

func CopyComposerFile(path, orchestrator, sourceFilename, pwd string) error {
if sourceFilename != "" {
logging.Print("Copying composer.local.json file\n")
switch orchestrator {
case "docker-compose":
if !strings.HasPrefix(sourceFilename, "/") {
sourceFilename = pwd + "/" + sourceFilename
}
var composerFilename = path + "/config/composer.local.json"
var backupFilename = path + "/config/composer.local.default.json"
logging.Print(fmt.Sprintf("Moving %s to %s\n", composerFilename, backupFilename))
err, output := execute.Run("", "mv", composerFilename, backupFilename)
if err != nil {
logging.Fatal(fmt.Errorf(output))
} else {
logging.Print(fmt.Sprintf("Copying %s to %s\n", sourceFilename, composerFilename))
err, output := execute.Run("", "cp", sourceFilename, composerFilename)
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 {
Expand Down