Skip to content

Commit

Permalink
Merge pull request #15 from braheezy/10-load-vms-and-envs-determinist…
Browse files Browse the repository at this point in the history
…ically

fix: Load environments deterministically
  • Loading branch information
braheezy authored Sep 19, 2023
2 parents 5ed7b2d + 1467861 commit a0b56a3
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions internal/app/ecosystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,41 @@ func createEcosystem(client *vagrant.VagrantClient) (Ecosystem, error) {
machines = append(machines, machine)
}
// Create different envs by grouping machines based on machine-home
envGroups := make(map[string][]Machine)
type EnvironmentGroup struct {
Name string
Machines []Machine
}
var envGroups []EnvironmentGroup
for _, machine := range machines {
// TODO: Bug if two different paths have the same folder name e.g. /foo/env1 and /bar/env1 will incorrectly be treated the same
envGroups[path.Base(machine.home)] = append(envGroups[path.Base(machine.home)], machine)
found := false
for i, env := range envGroups {
// TODO: Bug if two different paths have the same folder name e.g. /foo/env1 and /bar/env1 will incorrectly be treated the same
if env.Name == path.Base(machine.home) {
envGroups[i].Machines = append(envGroups[i].Machines, machine)
found = true
break
}
}
if !found {
env := EnvironmentGroup{
Name: path.Base(machine.home),
Machines: []Machine{machine},
}
envGroups = append(envGroups, env)
}
}

var environments []Environment
for envName, machines := range envGroups {
env := Environment{
name: envName,
machines: machines,
home: envGroups[envName][0].home,
hasFocus: true,
for _, envGroup := range envGroups {
if len(envGroup.Machines) > 0 {
env := Environment{
name: envGroup.Name,
machines: envGroup.Machines,
home: envGroup.Machines[0].home,
hasFocus: true,
}
environments = append(environments, env)
}
environments = append(environments, env)
}
return Ecosystem{
environments: environments,
Expand Down

0 comments on commit a0b56a3

Please sign in to comment.