Skip to content

Commit

Permalink
Sync with Mattermost binary changes introduced in v6 (#470)
Browse files Browse the repository at this point in the history
* use mmctl to create user

* sync with mattermost binary updates for v6
  • Loading branch information
isacikgoz authored Oct 21, 2021
1 parent 818e2ab commit 3cafccd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
7 changes: 4 additions & 3 deletions cmd/ltctl/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func RunResetCmdF(cmd *cobra.Command, args []string) error {
}

binaryPath := "/opt/mattermost/bin/mattermost"
mmctlPath := "/opt/mattermost/bin/mmctl"

cmds := []struct {
msg string
Expand All @@ -74,7 +75,7 @@ func RunResetCmdF(cmd *cobra.Command, args []string) error {
}{
{
msg: "Resetting database",
value: fmt.Sprintf("%s reset --confirm", binaryPath),
value: fmt.Sprintf("%s db reset --confirm", binaryPath),
clients: []*ssh.Client{appClients[0]},
},
{
Expand All @@ -84,8 +85,8 @@ func RunResetCmdF(cmd *cobra.Command, args []string) error {
},
{
msg: "Creating sysadmin",
value: fmt.Sprintf("%s user create --email %s --username %s --password '%s' --system_admin",
binaryPath, config.AdminEmail, config.AdminUsername, config.AdminPassword),
value: fmt.Sprintf("%s user create --email %s --username %s --password '%s' --system-admin --local",
mmctlPath, config.AdminEmail, config.AdminUsername, config.AdminPassword),
clients: []*ssh.Client{appClients[0]},
},
{
Expand Down
6 changes: 3 additions & 3 deletions comparison/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ func initLoadTest(t *terraform.Terraform, buildCfg BuildConfig, dumpFilename str
}

// do init process
binaryPath := "/opt/mattermost/bin/mattermost"
mmctlPath := "/opt/mattermost/bin/mmctl"
createAdminCmd := cmd{
msg: "Creating sysadmin",
value: fmt.Sprintf("%s user create --email %s --username %s --password '%s' --system_admin || true",
binaryPath, dpConfig.AdminEmail, dpConfig.AdminUsername, dpConfig.AdminPassword),
value: fmt.Sprintf("%s user create --email %s --username %s --password '%s' --system-admin --local || true",
mmctlPath, dpConfig.AdminEmail, dpConfig.AdminUsername, dpConfig.AdminPassword),
clients: []*ssh.Client{appClients[0]},
}
initDataCmd := cmd{
Expand Down
10 changes: 7 additions & 3 deletions deployment/terraform/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (t *Terraform) setupProxyServer(extAgent *ssh.ExtAgent) {
}

func (t *Terraform) createAdminUser(extAgent *ssh.ExtAgent) error {
cmd := fmt.Sprintf("/opt/mattermost/bin/mmctl user create --email %s --username %s --password %s --system_admin --local",
cmd := fmt.Sprintf("/opt/mattermost/bin/mmctl user create --email %s --username %s --password %s --system-admin --local",
t.config.AdminEmail,
t.config.AdminUsername,
t.config.AdminPassword,
Expand Down Expand Up @@ -353,15 +353,19 @@ func (t *Terraform) updateAppConfig(ip string, sshc *ssh.Client, jobServerEnable
driverName = t.config.ExternalDBSettings.DriverName

if t.output.HasDB() {
var err error
clusterDSN, err = t.getClusterDSN()
if err != nil {
return fmt.Errorf("could not update config: %w", err)
}

switch t.config.TerraformDBSettings.InstanceEngine {
case "aurora-postgresql":
clusterDSN = "postgres://" + t.config.TerraformDBSettings.UserName + ":" + t.config.TerraformDBSettings.Password + "@" + t.output.DBWriter() + "/" + t.config.DBName() + "?sslmode=disable"
for _, rd := range t.output.DBReaders() {
readerDSN = append(readerDSN, "postgres://"+t.config.TerraformDBSettings.UserName+":"+t.config.TerraformDBSettings.Password+"@"+rd+"/"+t.config.DBName()+"?sslmode=disable")
}
driverName = "postgres"
case "aurora-mysql":
clusterDSN = t.config.TerraformDBSettings.UserName + ":" + t.config.TerraformDBSettings.Password + "@tcp(" + t.output.DBWriter() + ")/" + t.config.DBName() + "?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s"
for _, rd := range t.output.DBReaders() {
readerDSN = append(readerDSN, t.config.TerraformDBSettings.UserName+":"+t.config.TerraformDBSettings.Password+"@tcp("+rd+")/"+t.config.DBName()+"?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s")
}
Expand Down
12 changes: 12 additions & 0 deletions deployment/terraform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,15 @@ func (t *Terraform) getParams() []string {
"-var", fmt.Sprintf("job_server_instance_type=%s", t.config.JobServerSettings.InstanceType),
}
}

func (t *Terraform) getClusterDSN() (string, error) {
switch t.config.TerraformDBSettings.InstanceEngine {
case "aurora-postgresql":
return "postgres://" + t.config.TerraformDBSettings.UserName + ":" + t.config.TerraformDBSettings.Password + "@" + t.output.DBWriter() + "/" + t.config.DBName() + "?sslmode=disable", nil

case "aurora-mysql":
return t.config.TerraformDBSettings.UserName + ":" + t.config.TerraformDBSettings.Password + "@tcp(" + t.output.DBWriter() + ")/" + t.config.DBName() + "?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s", nil
default:
return "", errors.New("unsupported database engine")
}
}

0 comments on commit 3cafccd

Please sign in to comment.