Skip to content

Commit

Permalink
bt: simplify stack schema
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGamba committed Feb 2, 2024
1 parent bc0766f commit 7d09104
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bt/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ bt provides a separate config file for defining stacks: `bt-stacks.cue`
* Each component can be deployed to a different workspace but in general,
they should have a consistent naming convention so that the workspace name can be auto-resolved from the stack name.

* A stack can have multiple instance of the same component, that is, multiple workspaces of one component.
* A stack can have multiple instances of the same component, that is, multiple workspaces of one component.
For example, setting connectivity between AWS North America and AWS China requires different Terraform backend configurations because of the AWS China split.
The stack config file allows for this.

Expand Down
14 changes: 6 additions & 8 deletions bt/stack/config/schema.cue
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package stack

#ComponentID: string & =~"^[a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?$"
#ID: string & =~"^[a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?$"

#Variable: {
name: string
value: string
}

#Component: {
id: #ComponentID
id: #ID
path: string | *id
depends_on: [...#Component.id]
variables: [...#Variable]
workspaces: [...string]
}

#Stack: [ID=_]: {
id: ID
#Stack: {
id: #ID
components: [...#Component]
component_overrides: [ComponentID=_]: {
workspaces: [...string]
}
}

component: [ID=_]: #Component & {id: ID}

stack: #Stack
stack: [ID=_]: #Stack & {id: ID}
31 changes: 17 additions & 14 deletions bt/stack/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,41 @@ package config
import "fmt"

type Config struct {
Component map[ComponentID]Component `json:"component"`
Stack map[string]Stack `json:"stack"`
Component map[ID]Component `json:"component"`
Stack map[ID]Stack `json:"stack"`
}

type Component struct {
ID ComponentID `json:"id"`
Path string `json:"path"`
DependsOn []string `json:"depends_on"`
Variables []Variable `json:"variables"`
ID ID `json:"id"`
Path string `json:"path"`
DependsOn []string `json:"depends_on"`
Variables []Variable `json:"variables"`
Workspaces []string `json:"workspaces"`
}

type ComponentID string
type ID string

type Variable struct {
Name string `json:"name"`
Value string `json:"value"`
}

type Stack struct {
ID string `json:"id"`
Components []Component `json:"components"`
ComponentOverrides map[string]struct {
Workspaces []string
} `json:"component_overrides"`
ID ID `json:"id"`
Components []Component `json:"components"`
}

func (c Component) String() string {
return fmt.Sprintf("id: %s, path: %s, depends_on: %v, variables: %v", c.ID, c.Path, c.DependsOn, c.Variables)
return fmt.Sprintf("id: %s, path: %s, depends_on: %v, variables: %v, workspaces: %v", c.ID, c.Path, c.DependsOn, c.Variables, c.Workspaces)
}

func (s Stack) String() string {
return fmt.Sprintf("id: %s, components: %v, component_overrides: %v", s.ID, s.Components, s.ComponentOverrides)
componentIDs := make([]ID, len(s.Components))
for i, c := range s.Components {
componentIDs[i] = c.ID
}

return fmt.Sprintf("id: %s, components: %v", s.ID, componentIDs)
}

func (v Variable) String() string {
Expand Down
11 changes: 0 additions & 11 deletions bt/stack/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ func GraphRun(ctx context.Context, opt *getoptions.GetOpt, args []string) error
for _, c := range s.Components {
Logger.Printf("%s\n", c)
}
// fmt.Printf("\tlayers\n")
// for _, v := range v.Components {
// fmt.Printf("\t\t%s\n", v)
// }
// fmt.Printf("\tlayer_overrides\n")
// for k, v := range v.ComponentOverrides {
// fmt.Printf("\t\t%s\n", k)
// for _, v := range v.Workspaces {
// fmt.Printf("\t\t\t%s\n", v)
// }
// }
}

return nil
Expand Down

0 comments on commit 7d09104

Please sign in to comment.