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

Runtime: shorthands for configuring "dev" and "prod" envs #4279

Merged
merged 2 commits into from
Mar 11, 2024
Merged
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
18 changes: 18 additions & 0 deletions runtime/compilers/rillv1/parse_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ type commonYAML struct {
SQL string `yaml:"sql"`
// Environment-specific overrides
Env map[string]yaml.Node `yaml:"env"`
// Shorthand for setting "env:dev:"
Dev yaml.Node `yaml:"dev"`
// Shorthand for setting "env:prod:"
Prod yaml.Node `yaml:"prod"`
}

// parseStem parses a pair of YAML and SQL files with the same path stem (e.g. "/path/to/file.yaml" for "/path/to/file.sql").
Expand Down Expand Up @@ -110,6 +114,20 @@ func (p *Parser) parseStem(paths []string, ymlPath, yml, sqlPath, sql string) (*
res.SQL = cfg.SQL
res.SQLPath = ymlPath

// Handle "dev:" and "prod:" shorthands (copy to to cfg.Env)
if !cfg.Dev.IsZero() {
if cfg.Env == nil {
cfg.Env = make(map[string]yaml.Node)
}
cfg.Env["dev"] = cfg.Dev
}
if !cfg.Prod.IsZero() {
if cfg.Env == nil {
cfg.Env = make(map[string]yaml.Node)
}
cfg.Env["prod"] = cfg.Prod
}

// Set environment-specific override
if envOverride := cfg.Env[p.Environment]; !envOverride.IsZero() {
res.YAMLOverride = &envOverride
Expand Down
46 changes: 37 additions & 9 deletions runtime/compilers/rillv1/parse_rillyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,34 @@ type VariableDef struct {

// rillYAML is the raw YAML structure of rill.yaml
type rillYAML struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
// Title of the project
Title string `yaml:"title"`
// Description of the project
Description string `yaml:"description"`
// The project's default OLAP connector to use (can be overridden in the individual resources)
OLAPConnector string `yaml:"olap_connector"`
Connectors []struct {
// Connectors required by the project
Connectors []struct {
Type string `yaml:"type"`
Name string `yaml:"name"`
Defaults map[string]string `yaml:"defaults"`
} `yaml:"connectors"`
Vars map[string]string `yaml:"vars"`
Env map[string]yaml.Node `yaml:"env"`
Sources yaml.Node `yaml:"sources"`
Models yaml.Node `yaml:"models"`
Dashboards yaml.Node `yaml:"dashboards"`
Migrations yaml.Node `yaml:"migrations"`
// Variables required by the project and their default values
Vars map[string]string `yaml:"vars"`
// Environment-specific overrides for rill.yaml
Env map[string]yaml.Node `yaml:"env"`
// Shorthand for setting "env:dev:"
Dev yaml.Node `yaml:"dev"`
// Shorthand for setting "env:prod:"
Prod yaml.Node `yaml:"prod"`
// Default YAML values for sources
Sources yaml.Node `yaml:"sources"`
// Default YAML values for models
Models yaml.Node `yaml:"models"`
// Default YAML values for metric views
Dashboards yaml.Node `yaml:"dashboards"`
// Default YAML values for migrations
Migrations yaml.Node `yaml:"migrations"`
}

// parseRillYAML parses rill.yaml
Expand Down Expand Up @@ -75,6 +89,20 @@ func (p *Parser) parseRillYAML(ctx context.Context, path string) error {
}
}

// Handle "dev:" and "prod:" shorthands (copy to to tmp.Env)
if !tmp.Dev.IsZero() {
if tmp.Env == nil {
tmp.Env = make(map[string]yaml.Node)
}
tmp.Env["dev"] = tmp.Dev
}
if !tmp.Prod.IsZero() {
if tmp.Env == nil {
tmp.Env = make(map[string]yaml.Node)
}
tmp.Env["prod"] = tmp.Prod
}

// Apply environment-specific overrides
if envOverride := tmp.Env[p.Environment]; !envOverride.IsZero() {
if err := envOverride.Decode(tmp); err != nil {
Expand Down
Loading