Skip to content
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
55 changes: 33 additions & 22 deletions blueprint/pkg/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,19 @@ func TestBlueprintLoaderLoad(t *testing.T) {
files: map[string]string{
"/tmp/dir1/dir2/blueprint.cue": `
version: "1.0"
targets: {
test: {
privileged: true
ci: {
targets: {
test: {
privileged: true
}
}
}
`,
"/tmp/dir1/.git": "",
},
want: []fieldTest{
{
fieldPath: "targets.test.privileged",
fieldPath: "ci.targets.test.privileged",
fieldType: "bool",
fieldValue: true,
},
Expand All @@ -95,17 +97,21 @@ func TestBlueprintLoaderLoad(t *testing.T) {
files: map[string]string{
"/tmp/dir1/dir2/blueprint.cue": `
version: "1.0"
targets: {
test: {
privileged: true
ci: {
targets: {
test: {
privileged: true
}
}
}
`,
"/tmp/dir1/blueprint.cue": `
version: "1.1"
targets: {
test: {
retries: 3
ci: {
targets: {
test: {
retries: 3
}
}
}
`,
Expand All @@ -118,12 +124,12 @@ func TestBlueprintLoaderLoad(t *testing.T) {
fieldValue: "1.1.0",
},
{
fieldPath: "targets.test.privileged",
fieldPath: "ci.targets.test.privileged",
fieldType: "bool",
fieldValue: true,
},
{
fieldPath: "targets.test.retries",
fieldPath: "ci.targets.test.retries",
fieldType: "int",
fieldValue: int64(3),
},
Expand All @@ -135,28 +141,33 @@ func TestBlueprintLoaderLoad(t *testing.T) {
files: map[string]string{
"/tmp/dir1/dir2/blueprint.cue": `
version: "1.0"
targets: {
test: {
privileged: true
ci: {
targets: {
test: {
privileged: true
}
}
}
}
`,
"/tmp/dir1/blueprint.cue": `
targets: {
test: {
retries: 3
version: "1.0"
ci: {
targets: {
test: {
retries: 3
}
}
}
}
`,
},
want: []fieldTest{
{
fieldPath: "targets.test.privileged",
fieldPath: "ci.targets.test.privileged",
fieldType: "bool",
fieldValue: true,
},
{
fieldPath: "targets.test.retries",
fieldPath: "ci.targets.test.retries",
fieldType: "int",
fieldValue: int64(0),
},
Expand Down
25 changes: 16 additions & 9 deletions blueprint/schema/_embed/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@ package schema
// Blueprint contains the schema for blueprint files.
#Blueprint: {
version: =~"^\\d+\\.\\d+" @go(Version)
global: #Global @go(Global)
registry: (_ | *"") & {
string
} @go(Registry)
secrets: {
[string]: #Secret
ci: #CI @go(CI)
}
#CI: {
global: #Global @go(Global)
secrets: (_ | *{}) & {
{
[string]: #Secret
}
} @go(Secrets,map[string]Secret)
targets: {
[string]: #Target
targets: (_ | *{}) & {
{
[string]: #Target
}
} @go(Targets,map[string]Target)
}

// Global contains the global configuration.
#Global: {
registry: (_ | *"") & {
string
} @go(Registry)
satellite: (_ | *"") & {
string
} @go(Satellite)
Expand Down Expand Up @@ -45,5 +52,5 @@ version: "1.0"
retries: (_ | *0) & {
int
} @go(Retries)
secrets: [...#Secret] @go(Secrets,[]Secret)
secrets: [...#Secret] & (_ | *[]) @go(Secrets,[]Secret)
}
14 changes: 9 additions & 5 deletions blueprint/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ var RawSchemaFile []byte

// Blueprint contains the schema for blueprint files.
type Blueprint struct {
Version string `json:"version"`
Global Global `json:"global"`
Registry string `json:"registry"`
Secrets map[string]Secret `json:"secrets"`
Targets map[string]Target `json:"targets"`
Version string `json:"version"`
CI CI `json:"ci"`
}

type CI struct {
Global Global `json:"global"`
Secrets map[string]Secret `json:"secrets"`
Targets map[string]Target `json:"targets"`
}

// Global contains the global configuration.
type Global struct {
Registry string `json:"registry"`
Satellite string `json:"satellite"`
}

Expand Down
10 changes: 7 additions & 3 deletions blueprint/schema/schema_go_gen.cue
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ package schema

// Blueprint contains the schema for blueprint files.
#Blueprint: {
version: string @go(Version)
global: #Global @go(Global)
registry: string @go(Registry)
version: string @go(Version)
ci: #CI @go(CI)
}

#CI: {
global: #Global @go(Global)
secrets: {[string]: #Secret} @go(Secrets,map[string]Secret)
targets: {[string]: #Target} @go(Targets,map[string]Target)
}

// Global contains the global configuration.
#Global: {
registry: string @go(Registry)
satellite: string @go(Satellite)
}

Expand Down
10 changes: 8 additions & 2 deletions blueprint/schema/schema_overrides.cue
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package schema

#Blueprint: {
version: string & =~"^\\d+\\.\\d+"
registry: _ | *""
version: string & =~"^\\d+\\.\\d+"
}

#CI: {
secrets: _ | *{}
targets: _ | *{}
}

#Global: {
registry: _ | *""
satellite: _ | *""
}

#Target: {
args: _ | *{}
privileged: _ | *false
retries: _ | *0
secrets: _ | *[]
}
8 changes: 4 additions & 4 deletions forge/cli/cmd/cmds/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func generateOpts(target string, flags *RunCmd, config *schema.Blueprint) []eart
var opts []earthly.EarthlyExecutorOption

if config != nil {
if _, ok := config.Targets[target]; ok {
targetConfig := config.Targets[target]
if _, ok := config.CI.Targets[target]; ok {
targetConfig := config.CI.Targets[target]

if len(targetConfig.Args) > 0 {
var args []string
Expand All @@ -52,8 +52,8 @@ func generateOpts(target string, flags *RunCmd, config *schema.Blueprint) []eart
}
}

if config.Global.Satellite != "" && !flags.Local {
opts = append(opts, earthly.WithSatellite(config.Global.Satellite))
if config.CI.Global.Satellite != "" && !flags.Local {
opts = append(opts, earthly.WithSatellite(config.CI.Global.Satellite))
}
}

Expand Down
36 changes: 20 additions & 16 deletions forge/cli/cmd/testdata/config_dump/1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ cmp stdout golden.txt
-- golden.txt --
{
"version": "1.0.0",
"global": {
"satellite": ""
},
"registry": "",
"secrets": {},
"targets": {
"test": {
"args": {},
"privileged": true,
"retries": 0,
"secrets": []
"ci": {
"global": {
"registry": "",
"satellite": ""
},
"secrets": {},
"targets": {
"test": {
"args": {},
"privileged": true,
"retries": 0,
"secrets": []
}
}
}
}
-- blueprint.cue --
version: "1.0"
targets: {
test: {
privileged: true
}
}
ci: {
targets: {
test: {
privileged: true
}
}
}
50 changes: 30 additions & 20 deletions forge/cli/cmd/testdata/config_dump/2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,44 @@ cmpenv stdout golden.txt
-- golden.txt --
{
"version": "1.0.0",
"global": {
"satellite": ""
},
"registry": "test",
"secrets": {},
"targets": {
"test": {
"args": {},
"privileged": true,
"retries": 3,
"secrets": []
"ci": {
"global": {
"registry": "test",
"satellite": ""
},
"secrets": {},
"targets": {
"test": {
"args": {},
"privileged": true,
"retries": 3,
"secrets": []
}
}
}
}
-- dir1/dir2/blueprint.cue --
version: "1.0"
targets: {
test: {
privileged: true
}
ci: {
targets: {
test: {
privileged: true
}
}
}
-- dir1/blueprint.cue --
version: "1.0"
targets: {
test: {
retries: 3
}
ci: {
targets: {
test: {
retries: 3
}
}
}
-- blueprint.cue --
version: "1.0"
registry: "test"
ci: {
global: {
registry: "test"
}
}
Loading