diff --git a/README.md b/README.md index 191dfa1..ced983a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # ![Score](docs/images/logo.svg) Score overview -Score aims to improve developer producticity and experience by reducing the risk of configurtaion inconsistencies between local and remote environments. It provides developer-centric workload specification (`score.yaml`) which captures a workloads runtime requirements in a platform-agnostic manner. +Score aims to improve developer productivity and experience by reducing the risk of configuration inconsistencies between local and remote environments. It provides developer-centric workload specification (`score.yaml`) which captures a workloads runtime requirements in a platform-agnostic manner. The `score.yaml` specification file can be executed against a _Score Implementation CLI_, a conversion tool for application developers to generate environment specific configuration. In combination with environment specific parameters, the CLI tool can run your workload in the target environment by generating a platform-specific configuration file such as `docker-compose.yaml` or a Helm `values.yaml`. Learn more [here](https://github.com/score-spec/spec#-what-is-score). diff --git a/examples/03-dependencies/README.md b/examples/03-dependencies/README.md index 9d9005e..f5d11dc 100644 --- a/examples/03-dependencies/README.md +++ b/examples/03-dependencies/README.md @@ -38,9 +38,10 @@ resources: properties: domain: backend: - type: workload + type: service properties: name: + port: ``` This example also uses an extensions file, called `humanitec.yaml`, that contains additional hints for `score-humanitec` CLI tool. This information would help the CLI tool to resolve the resources properly. diff --git a/examples/03-dependencies/score.yaml b/examples/03-dependencies/score.yaml index ead37c7..adb3e66 100644 --- a/examples/03-dependencies/score.yaml +++ b/examples/03-dependencies/score.yaml @@ -31,6 +31,7 @@ resources: properties: domain: backend: - type: workload + type: service properties: name: + port: diff --git a/internal/humanitec/convert.go b/internal/humanitec/convert.go index b8917b3..b217dd9 100644 --- a/internal/humanitec/convert.go +++ b/internal/humanitec/convert.go @@ -160,7 +160,7 @@ func ConvertSpec(name, envID string, spec *score.WorkloadSpec, ext *extensions.H var externals = map[string]interface{}{} for name, res := range spec.Resources { if meta, exists := ext.Resources[name]; !exists || meta.Scope == "" || meta.Scope == "external" { - if res.Type != "workload" && res.Type != "environment" { + if res.Type != "service" && res.Type != "environment" { externals[name] = map[string]interface{}{ "type": res.Type, } diff --git a/internal/humanitec/convert_test.go b/internal/humanitec/convert_test.go index 8312e89..4d386d5 100644 --- a/internal/humanitec/convert_test.go +++ b/internal/humanitec/convert_test.go @@ -165,7 +165,7 @@ func TestScoreConvert(t *testing.T) { Variables: map[string]string{ "DEBUG": "${resources.env.DEBUG}", "LOGS_LEVEL": "${pod.debug.level}", - "ORDERS_SERVICE": "http://${resources.orders.service.name}:${resources.orders.service.port}/api", + "ORDERS_SERVICE": "http://${resources.orders.name}:${resources.orders.port}/api", "CONNECTION_STRING": "postgresql://${resources.db.host}:${resources.db.port}/${resources.db.name}", "DOMAIN_NAME": "${resources.dns.domain}", }, @@ -217,10 +217,10 @@ func TestScoreConvert(t *testing.T) { }, }, "orders": { - Type: "workload", + Type: "service", Properties: map[string]score.ResourcePropertySpec{ - "service.name": {Required: false}, - "service.port": {}, + "name": {Required: false}, + "port": {}, }, }, }, diff --git a/internal/humanitec/templates.go b/internal/humanitec/templates.go index 78f3ca1..9f8a0b3 100644 --- a/internal/humanitec/templates.go +++ b/internal/humanitec/templates.go @@ -47,7 +47,7 @@ func buildContext(metadata score.WorkloadMeta, resources score.ResourcesSpecs, e switch res.Type { case "environment": source = "values" - case "workload": + case "service": source = fmt.Sprintf("modules.%s", resName) default: if resExt, exists := ext[resName]; exists && resExt.Scope == "shared" { @@ -63,7 +63,14 @@ func buildContext(metadata score.WorkloadMeta, resources score.ResourcesSpecs, e if _, exists := ctx[ref]; exists { return nil, fmt.Errorf("ambiguous property reference '%s'", ref) } - ctx[ref] = fmt.Sprintf("${%s.%s}", source, propName) + var sourceProp string + switch res.Type { + case "service": + sourceProp = fmt.Sprintf("service.%s", propName) + default: + sourceProp = propName + } + ctx[ref] = fmt.Sprintf("${%s.%s}", source, sourceProp) } } diff --git a/internal/humanitec/templates_test.go b/internal/humanitec/templates_test.go index 6d5cf1a..0e10c23 100644 --- a/internal/humanitec/templates_test.go +++ b/internal/humanitec/templates_test.go @@ -43,9 +43,10 @@ func TestBuildContext(t *testing.T) { }, }, "service-a": score.ResourceSpec{ - Type: "workload", + Type: "service", Properties: map[string]score.ResourcePropertySpec{ - "service.name": {}, + "name": {}, + "port": {}, }, }, } @@ -71,8 +72,9 @@ func TestBuildContext(t *testing.T) { "resources.dns": "shared.dns", "resources.dns.domain": "${shared.dns.domain}", - "resources.service-a": "modules.service-a", - "resources.service-a.service.name": "${modules.service-a.service.name}", + "resources.service-a": "modules.service-a", + "resources.service-a.name": "${modules.service-a.service.name}", + "resources.service-a.port": "${modules.service-a.service.port}", }, context) } @@ -91,8 +93,9 @@ func TestMapVar(t *testing.T) { "resources.dns": "shared.dns", "resources.dns.domain": "${shared.dns.domain}", - "resources.service-a": "modules.service-a", - "resources.service-a.service.name": "${modules.service-a.service.name}", + "resources.service-a": "modules.service-a", + "resources.service-a.name": "${modules.service-a.service.name}", + "resources.service-a.port": "${modules.service-a.service.port}", } assert.Equal(t, "", context.mapVar("")) @@ -110,6 +113,8 @@ func TestMapVar(t *testing.T) { assert.Equal(t, "${externals.db.name}", context.mapVar("resources.db.name")) assert.Equal(t, "${resources.db.name.nil}", context.mapVar("resources.db.name.nil")) assert.Equal(t, "${resources.db.nil}", context.mapVar("resources.db.nil")) + assert.Equal(t, "${modules.service-a.service.name}", context.mapVar("resources.service-a.name")) + assert.Equal(t, "${modules.service-a.service.port}", context.mapVar("resources.service-a.port")) assert.Equal(t, "${resources.nil}", context.mapVar("resources.nil")) assert.Equal(t, "${nil.db.name}", context.mapVar("nil.db.name")) } @@ -129,8 +134,9 @@ func TestSubstitute(t *testing.T) { "resources.dns": "shared.dns", "resources.dns.domain": "${shared.dns.domain}", - "resources.service-a": "modules.service-a", - "resources.service-a.service.name": "${modules.service-a.service.name}", + "resources.service-a": "modules.service-a", + "resources.service-a.name": "${modules.service-a.service.name}", + "resources.service-a.port": "${modules.service-a.service.port}", } assert.Equal(t, "", context.Substitute("")) @@ -164,15 +170,17 @@ func TestSubstituteAll(t *testing.T) { "resources.dns": "shared.dns", "resources.dns.domain": "${shared.dns.domain}", - "resources.service-a": "modules.service-a", - "resources.service-a.service.name": "${modules.service-a.service.name}", + "resources.service-a": "modules.service-a", + "resources.service-a.name": "${modules.service-a.service.name}", + "resources.service-a.port": "${modules.service-a.service.port}", } var source = map[string]interface{}{ "api": map[string]interface{}{ - "${resources.service-a.service.name}": map[string]interface{}{ - "url": "http://${resources.dns.domain}", - "port": 80, + "${resources.service-a.name}": map[string]interface{}{ + "url": "http://${resources.dns.domain}", + "port": "${resources.service-a.port}", + "retry": 10, }, }, "DEBUG": "${resources.env.DEBUG}", @@ -181,8 +189,9 @@ func TestSubstituteAll(t *testing.T) { var expected = map[string]interface{}{ "api": map[string]interface{}{ "${modules.service-a.service.name}": map[string]interface{}{ - "url": "http://${shared.dns.domain}", - "port": 80, + "url": "http://${shared.dns.domain}", + "port": "${modules.service-a.service.port}", + "retry": 10, }, }, "DEBUG": "${values.DEBUG}",