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

Fix/command robustness #84

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 3 additions & 8 deletions .example-lagoon-sync
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@ lagoon-sync:
database: "drupal"
mongodb:
config:
hostname: "$MONGODB_HOST"
port: "$MONGODB_SERVICE_PORT"
database: "MONGODB_DATABASE"
local:
config:
hostname: "$MONGODB_HOST"
port: "27017"
database: "local"
hostname: "${MONGODB_HOST:-mongodb}"
port: "${MONGODB_SERVICE_PORT:-27017}"
database: "${MONGODB_DATABASE:-local}"
files:
config:
sync-directory: "/app/web/sites/default/files"
Expand Down
3 changes: 0 additions & 3 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ func syncCommandRun(cmd *cobra.Command, args []string) {
}

func getServiceName(SyncerType string) string {
if SyncerType == "mongodb" {
return SyncerType
}
return "cli"
}

Expand Down
12 changes: 10 additions & 2 deletions synchers/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"strconv"
"strings"
"time"

"github.com/spf13/viper"
Expand All @@ -14,13 +15,14 @@ type BaseMongoDbSync struct {
DbHostname string `yaml:"hostname"`
DbPort string `yaml:"port"`
DbDatabase string `yaml:"database"`
Authtls string `yaml:"authtls"`
OutputDirectory string
}

func (mongoConfig *BaseMongoDbSync) setDefaults() {
// If no values from config files, set some expected defaults
if mongoConfig.DbHostname == "" {
mongoConfig.DbHostname = "$HOSTNAME"
mongoConfig.DbHostname = "mongodb"
}
if mongoConfig.DbPort == "" {
mongoConfig.DbPort = "27017"
Expand Down Expand Up @@ -124,13 +126,19 @@ func (root MongoDbSyncRoot) GetRemoteCommand(sourceEnvironment Environment) []Sy
}

transferResource := root.GetTransferResource(sourceEnvironment)
ssl := ""
if strings.ToLower(m.Authtls) == "true" {
ssl = "--ssl"
}
return []SyncCommand{{
command: fmt.Sprintf("mongodump --host {{ .hostname }} --port {{ .port }} --db {{ .database }} --archive={{ .transferResource }}"),

command: fmt.Sprintf("mongodump --host {{ .hostname }} --port {{ .port }} --db {{ .database }} {{ .ssl }} --archive={{ .transferResource }}"),
substitutions: map[string]interface{}{
"hostname": m.DbHostname,
"port": m.DbPort,
"database": m.DbDatabase,
"transferResource": transferResource.Name,
"ssl": ssl,
},
},
}
Expand Down
5 changes: 4 additions & 1 deletion synchers/syncutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ func SyncRunSourceCommand(remoteEnvironment Environment, syncer Syncer, dryRun b
err, response, errstring := utils.Shellout(execString)
if err != nil && debug == false {
fmt.Println(errstring)
return err
}
if response != "" && debug == false {
fmt.Println(response)
}
return err
}
}

Expand Down Expand Up @@ -235,6 +235,7 @@ func SyncRunTransfer(sourceEnvironment Environment, targetEnvironment Environmen
if !dryRun {
if err, _, errstring := utils.Shellout(execString); err != nil {
utils.LogFatalError(errstring, nil)
return err
}
}

Expand Down Expand Up @@ -270,6 +271,7 @@ func SyncRunTargetCommand(targetEnvironment Environment, syncer Syncer, dryRun b
err, _, errstring := utils.Shellout(execString)
if err != nil {
utils.LogFatalError(errstring, nil)
return err
}
}
}
Expand Down Expand Up @@ -301,6 +303,7 @@ func SyncCleanUp(environment Environment, syncer Syncer, dryRun bool, sshOptions
err, _, errstring := utils.Shellout(execString)
if err != nil {
utils.LogFatalError(errstring, nil)
return err
}
}
}
Expand Down