-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add farm management support #88
Merged
Merged
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4076120
Add propagating verbose to external subcommands(#61)
chl178 4250d8f
Add propagating verbose to external subcommands(#61)
chl178 60b6d3c
Add propagating verbose to external subcommands(#61)
chl178 3acc92d
Merge branch 'CanastaWiki:main' into main
chl178 4d06c16
enhanced create and add for wiki farm
chl178 3427473
added add and remove wiki in the Canasta container feature
chl178 7d6dd39
updated farmsettings.go
chl178 406778a
cleaned the code
chl178 9ebf24d
structure 0.1
chl178 6e6b9ab
structure 0.2
chl178 8d5d731
midterm version
chl178 ecc33c8
Add documentation
chl178 e8de292
Add documentation
chl178 450867e
test version
chl178 11d3f30
Merge branch 'main' into farm
chl178 1a5c75c
Update with HTTPS
chl178 23b3f62
Canasta-CLI 2.0 adding wiki farm support
chl178 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*.dll | ||
*.so | ||
*.dylib | ||
*.yaml | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
// If not running MediaWiki, exit | ||
if ( !defined( 'MEDIAWIKI' ) ) { | ||
exit; | ||
} | ||
#$wgServer = "http://localhost"; | ||
#$wgSitename = ; | ||
#$wgMetaNamespace = ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package add | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/CanastaWiki/Canasta-CLI-Go/cmd/restart" | ||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/canasta" | ||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/config" | ||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/farmsettings" | ||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/mediawiki" | ||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/orchestrators" | ||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/prompt" | ||
) | ||
|
||
func NewCmdCreate() *cobra.Command { | ||
var instance config.Installation | ||
var wikiName string | ||
var domainName string | ||
var wikiPath string | ||
var siteName string | ||
var databasePath string | ||
var url string | ||
|
||
addCmd := &cobra.Command{ | ||
Use: "add", | ||
Short: "Add a new wiki to a Canasta instance", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var err error | ||
wikiName, domainName, wikiPath, instance.Id, siteName, err = prompt.PromptWiki(wikiName, url, instance.Id, siteName) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Adding wiki '%s' to Canasta instance '%s'...\n", wikiName, instance.Id) | ||
err = AddWiki(wikiName, domainName, wikiPath, siteName, databasePath, instance) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("Done.") | ||
return nil | ||
}, | ||
} | ||
|
||
pwd, err := os.Getwd() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
addCmd.Flags().StringVarP(&wikiName, "wiki", "w", "", "ID of the new wiki") | ||
addCmd.Flags().StringVarP(&url, "url", "u", "", "URL of the new wiki") | ||
addCmd.Flags().StringVarP(&siteName, "site-name", "s", "", "Name of the new wiki site") | ||
addCmd.Flags().StringVarP(&instance.Path, "path", "p", pwd, "Path to the new wiki") | ||
addCmd.Flags().StringVarP(&instance.Id, "id", "i", "", "Canasta instance ID") | ||
addCmd.Flags().StringVarP(&instance.Orchestrator, "orchestrator", "o", "docker-compose", "Orchestrator to use for installation") | ||
addCmd.Flags().StringVarP(&databasePath, "database", "d", "", "Path to the existing database dump") | ||
return addCmd | ||
} | ||
|
||
// addWiki accepts the Canasta instance ID, the name, domain and path of the new wiki, and the initial admin info, then creates a new wiki in the instance. | ||
func AddWiki(name, domain, wikipath, siteName, databasePath string, instance config.Installation) error { | ||
var err error | ||
|
||
//Checking Installation existence | ||
instance, err = canasta.CheckCanastaId(instance) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//Migrate to the new version Canasta | ||
err = canasta.MigrateToNewVersion(instance.Path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//Checking Running status | ||
err = orchestrators.CheckRunningStatus(instance.Path, instance.Id, instance.Orchestrator) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//Checking Wiki existence | ||
exists, pathComboExists, err := farmsettings.CheckWiki(instance.Path, name, domain, wikipath) | ||
if err != nil { | ||
return err | ||
} | ||
if exists { | ||
return fmt.Errorf("A wiki with the name '%s' exists", name) | ||
} | ||
if pathComboExists { | ||
return fmt.Errorf("A wiki with the same installation path '%s' in the Canasta '%s' exists", name+": "+domain+"/"+wikipath, instance.Id) | ||
} | ||
|
||
//Add the wiki in farmsettings | ||
err = farmsettings.AddWiki(name, instance.Path, domain, wikipath, siteName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Import the database if databasePath is specified | ||
if databasePath != "" { | ||
err = orchestrators.ImportDatabase(name, databasePath, instance) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
//Copy the Localsettings | ||
err = canasta.CopySetting(instance.Path, name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//Rewrite the Caddyfile | ||
err = canasta.RewriteCaddy(instance.Path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = mediawiki.InstallOne(instance.Path, name, domain, wikipath, instance.Orchestrator) | ||
if err != nil { | ||
return err | ||
} | ||
err = restart.Restart(instance) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("Successfully Added the Wiki '" + name + "in Canasta instance '" + instance.Id + "'...") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't there be a space between |
||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/canasta" | ||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/config" | ||
"github.com/CanastaWiki/Canasta-CLI-Go/internal/orchestrators" | ||
) | ||
|
||
var ( | ||
pwd string | ||
err error | ||
instance config.Installation | ||
wikiName string | ||
outputFilePath string | ||
) | ||
|
||
// NewCmdExport exports the database. | ||
func NewCmdCreate() *cobra.Command { | ||
var instance config.Installation | ||
var wikiName string | ||
var outputFilePath string | ||
|
||
pwd, err := os.Getwd() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
exportCmd := &cobra.Command{ | ||
Use: "export", | ||
Short: "Export a database from a Canasta instance", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
fmt.Printf("Exporting database for wiki '%s' from Canasta instance '%s'...\n", wikiName, instance.Id) | ||
err := ExportDatabase(wikiName, outputFilePath, instance) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("Done.") | ||
return nil | ||
}, | ||
} | ||
|
||
exportCmd.Flags().StringVarP(&wikiName, "wiki", "w", "", "ID of the wiki (database) to export") | ||
exportCmd.Flags().StringVarP(&instance.Id, "id", "i", "", "Canasta instance ID") | ||
exportCmd.Flags().StringVarP(&instance.Path, "path", "p", pwd, "Canasta installation directory") | ||
exportCmd.Flags().StringVarP(&outputFilePath, "output", "o", "", "Output file path for the exported database") | ||
|
||
return exportCmd | ||
} | ||
|
||
// ExportDatabase exports a database from a Canasta instance. | ||
func ExportDatabase(databaseName, outputFilePath string, instance config.Installation) error { | ||
|
||
//Checking Installation existence | ||
instance, err = canasta.CheckCanastaId(instance) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//Checking Running status | ||
err = orchestrators.CheckRunningStatus(instance.Path, instance.Id, instance.Orchestrator) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Exporting the database | ||
err = orchestrators.ExportDatabase(instance.Path, instance.Orchestrator, databaseName, outputFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for any of these params to be non-null but empty? If so, how is that handled?