Skip to content

Commit

Permalink
Re add deployment to support service sharding. (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-rieke committed Jan 29, 2024
1 parent d447304 commit 38247d8
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions atrium/vestibulum/trcshbase/trcsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func CommonMain(envPtr *string, addrPtr *string, envCtxPtr *string,
//Open deploy script and parse it.
ProcessDeploy(nil, config, *regionPtr, "", "", *trcPathPtr, secretIDPtr, appRoleIDPtr, true)
} else {
deploymentsShard := os.Getenv("DEPLOYMENTS")
agentToken := os.Getenv("AGENT_TOKEN")
agentEnv := os.Getenv("AGENT_ENV")
address := os.Getenv("VAULT_ADDR")
Expand All @@ -276,6 +277,11 @@ func CommonMain(envPtr *string, addrPtr *string, envCtxPtr *string,
trcPathPtr = flagset.String("c", "", "Optional script to execute.") //If this is blank -> use context otherwise override context.
flagset.Parse(argLines[1:])

if len(deploymentsShard) == 0 {
fmt.Println("trcsh on windows requires a DEPLOYMENTS.")
os.Exit(-1)
}

if len(agentToken) == 0 {
fmt.Println("trcsh on windows requires AGENT_TOKEN.")
os.Exit(-1)
Expand Down Expand Up @@ -315,15 +321,34 @@ func CommonMain(envPtr *string, addrPtr *string, envCtxPtr *string,

// Initialize deployers.
config, err := TrcshInitConfig(*gAgentConfig.Env, *regionPtr, true)
if err != nil {
fmt.Println("trcsh agent bootstrap failure.")
os.Exit(-1)
}
config.AppRoleConfig = *trcshConfig.ConfigRole
config.VaultAddress = *trcshConfig.VaultAddress
deployments, err := deployutil.GetDeployers(config)
serviceDeployments, err := deployutil.GetDeployers(config)
if err != nil {
fmt.Println("trcsh agent bootstrap failure.")
os.Exit(-1)
}
Deployments := strings.Join(deployments, ",")
gAgentConfig.Deployments = &Deployments
deploymentShards := strings.Split(deploymentsShard, ",")
deployments := []string{}

// This is a tad more complex but will scale more nicely.
deploymentShardsSet := map[string]struct{}{}
for _, str := range deploymentShards {
deploymentShardsSet[str] = struct{}{}
}

for _, serviceDeployment := range serviceDeployments {
if _, ok := deploymentShardsSet[serviceDeployment]; ok {
deployments = append(deployments, serviceDeployment)
}
}
deploymentsCDL := strings.Join(deployments, ",")
gAgentConfig.Deployments = &deploymentsCDL

deployopts.BuildOptions.InitSupportedDeployers(deployments)

for _, deployment := range deployments {
Expand Down

0 comments on commit 38247d8

Please sign in to comment.