diff --git a/blueprint/pkg/loader/loader_test.go b/blueprint/pkg/loader/loader_test.go index da1bf3a9..8352e928 100644 --- a/blueprint/pkg/loader/loader_test.go +++ b/blueprint/pkg/loader/loader_test.go @@ -73,9 +73,11 @@ 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 + } } } `, @@ -83,7 +85,7 @@ func TestBlueprintLoaderLoad(t *testing.T) { }, want: []fieldTest{ { - fieldPath: "targets.test.privileged", + fieldPath: "ci.targets.test.privileged", fieldType: "bool", fieldValue: true, }, @@ -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 + } } } `, @@ -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), }, @@ -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), }, diff --git a/blueprint/schema/_embed/schema.cue b/blueprint/schema/_embed/schema.cue index 40f7257d..fd96af33 100644 --- a/blueprint/schema/_embed/schema.cue +++ b/blueprint/schema/_embed/schema.cue @@ -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) @@ -45,5 +52,5 @@ version: "1.0" retries: (_ | *0) & { int } @go(Retries) - secrets: [...#Secret] @go(Secrets,[]Secret) + secrets: [...#Secret] & (_ | *[]) @go(Secrets,[]Secret) } diff --git a/blueprint/schema/schema.go b/blueprint/schema/schema.go index ad9e5c09..f3f766ba 100644 --- a/blueprint/schema/schema.go +++ b/blueprint/schema/schema.go @@ -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"` } diff --git a/blueprint/schema/schema_go_gen.cue b/blueprint/schema/schema_go_gen.cue index 369cba2d..fd396609 100644 --- a/blueprint/schema/schema_go_gen.cue +++ b/blueprint/schema/schema_go_gen.cue @@ -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) } diff --git a/blueprint/schema/schema_overrides.cue b/blueprint/schema/schema_overrides.cue index 83927357..f0cc2f21 100644 --- a/blueprint/schema/schema_overrides.cue +++ b/blueprint/schema/schema_overrides.cue @@ -1,11 +1,16 @@ package schema #Blueprint: { - version: string & =~"^\\d+\\.\\d+" - registry: _ | *"" + version: string & =~"^\\d+\\.\\d+" +} + +#CI: { + secrets: _ | *{} + targets: _ | *{} } #Global: { + registry: _ | *"" satellite: _ | *"" } @@ -13,4 +18,5 @@ package schema args: _ | *{} privileged: _ | *false retries: _ | *0 + secrets: _ | *[] } diff --git a/forge/cli/cmd/cmds/util.go b/forge/cli/cmd/cmds/util.go index 2b04841c..7a156383 100644 --- a/forge/cli/cmd/cmds/util.go +++ b/forge/cli/cmd/cmds/util.go @@ -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 @@ -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)) } } diff --git a/forge/cli/cmd/testdata/config_dump/1.txt b/forge/cli/cmd/testdata/config_dump/1.txt index ebd9a25a..b93ce707 100644 --- a/forge/cli/cmd/testdata/config_dump/1.txt +++ b/forge/cli/cmd/testdata/config_dump/1.txt @@ -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 + } + } +} \ No newline at end of file diff --git a/forge/cli/cmd/testdata/config_dump/2.txt b/forge/cli/cmd/testdata/config_dump/2.txt index 7a077634..ee23d039 100644 --- a/forge/cli/cmd/testdata/config_dump/2.txt +++ b/forge/cli/cmd/testdata/config_dump/2.txt @@ -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" + } +} diff --git a/forge/cli/cmd/testdata/config_dump/3.txt b/forge/cli/cmd/testdata/config_dump/3.txt index 6356f91a..8a96eb58 100644 --- a/forge/cli/cmd/testdata/config_dump/3.txt +++ b/forge/cli/cmd/testdata/config_dump/3.txt @@ -6,34 +6,44 @@ cmpenv stdout golden.txt -- golden.txt -- { "version": "1.2.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.2" -targets: { - test: { - retries: int @env(name=RETRIES,type=int) - } +ci: { + targets: { + test: { + retries: int @env(name=RETRIES,type=int) + } + } } -- blueprint.cue -- version: "1.1" -registry: "test" +ci: { + global: { + registry: "test" + } +} diff --git a/forge/cli/cmd/testdata/config_dump/4.txt b/forge/cli/cmd/testdata/config_dump/4.txt index 6356f91a..6ff801ea 100644 --- a/forge/cli/cmd/testdata/config_dump/4.txt +++ b/forge/cli/cmd/testdata/config_dump/4.txt @@ -6,34 +6,44 @@ cmpenv stdout golden.txt -- golden.txt -- { "version": "1.2.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.2" -targets: { - test: { - retries: int @env(name=RETRIES,type=int) - } +ci: { + targets: { + test: { + retries: int @env(name=RETRIES,type=int) + } + } } -- blueprint.cue -- version: "1.1" -registry: "test" +ci: { + global: { + registry: "test" + } +} \ No newline at end of file diff --git a/forge/cli/cmd/testdata/config_validate/1.txt b/forge/cli/cmd/testdata/config_validate/1.txt index 1afba624..7b49dae8 100644 --- a/forge/cli/cmd/testdata/config_validate/1.txt +++ b/forge/cli/cmd/testdata/config_validate/1.txt @@ -2,8 +2,10 @@ exec forge config validate ./blueprint.cue -- blueprint.cue -- version: "1.0" -targets: { - test: { - privileged: true +ci: { + targets: { + test: { + privileged: true + } } } \ No newline at end of file diff --git a/forge/cli/cmd/testdata/config_validate/2.txt b/forge/cli/cmd/testdata/config_validate/2.txt index 2113cf0f..5aeecbc8 100644 --- a/forge/cli/cmd/testdata/config_validate/2.txt +++ b/forge/cli/cmd/testdata/config_validate/2.txt @@ -4,8 +4,10 @@ forge: failed loading configuration: failed to validate configuration file: #Config.targets.test.privileged: conflicting values "true" and bool (mismatched types string and bool) -- blueprint.cue -- version: "1.0" -targets: { - test: { - privileged: "true" +ci: { + targets: { + test: { + privileged: "true" + } } } \ No newline at end of file diff --git a/forge/cli/cmd/testdata/run/3.txt b/forge/cli/cmd/testdata/run/3.txt index 3bcdd0b2..6249ab33 100644 --- a/forge/cli/cmd/testdata/run/3.txt +++ b/forge/cli/cmd/testdata/run/3.txt @@ -12,8 +12,10 @@ Image ./dir1+test output as test Image ./dir1+test output as test -- dir1/blueprint.cue -- version: "1.0" -targets: { - test: { - privileged: true +ci: { + targets: { + test: { + privileged: true + } } } \ No newline at end of file diff --git a/forge/cli/cmd/testdata/run/4.txt b/forge/cli/cmd/testdata/run/4.txt index a1353c26..5f914deb 100644 --- a/forge/cli/cmd/testdata/run/4.txt +++ b/forge/cli/cmd/testdata/run/4.txt @@ -15,20 +15,22 @@ Image ./dir1+test output as test Image ./dir1+test output as test -- dir1/blueprint.cue -- version: "1.0" -S=secrets: { - my_secret_1: { - path: "./dir1/Secretfile" - provider: "local" - maps: { - "secret_key": "secret_id" +ci: { + secrets: { + my_secret_1: { + path: "./dir1/Secretfile" + provider: "local" + maps: { + "secret_key": "secret_id" + } } } -} -targets: { - test: { - privileged: true - secrets: [ - S.my_secret_1 - ] - } -} + targets: { + test: { + privileged: true + secrets: [ + ci.secrets.my_secret_1 + ] + } + } +} \ No newline at end of file