Repository: score-spec/score-compose
Pull request #27 (2023-01-26 23:17:14)

Rename `workload` resource type into `service`
Signed-off-by: Eugene Yarshevich <yarshevich@gmail.com>

#### Description

The latest Score spec renamed previously introduced `workload` resource type into `service` to support a proper level of abstraction.

We also remove service dependencies enforcement (`depends_on` section) from the produced `compose.yaml` file, as this configuration is environment-specific.

#### Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] New chore (expected functionality to be implemented)

#### Checklist:
- [x] My change requires a change to the documentation.
  - [ ] I have updated the documentation accordingly.
- [x] I've signed off with an email address that matches the commit author.



Patch:
diff --git a/README.md b/README.md
index aa2a089..94ca7b1 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 6858675..22c22b1 100644
--- a/examples/03-dependencies/README.md
+++ b/examples/03-dependencies/README.md
@@ -2,7 +2,7 @@
 
 Score uses `resources` section to describe workload's dependencies. This mechanism can be used to spin-up multi-service setups with `docker-compose`.
 
-For example, `service-a.yaml` score file describes a service that has two dependencies: `service-b` (another workload) and a PostgreSQL database instance:
+For example, `service-a.yaml` score file describes a service that has two dependencies: `service-b` (another workload), and a PostgreSQL database instance:
 
 ```yaml
 apiVersion: score.dev/v1b1
@@ -40,10 +40,10 @@ resources:
       password:
         secret: true
   service-b:
-    type: workload
+    type: service
 ```
 
-The second workload is described in `service-b.yaml` file and has no any additional dependencies:
+The second workload is described in `service-b.yaml` file and does not have dependencies:
 
 ```yaml
 apiVersion: score.dev/v1b1
@@ -75,33 +75,17 @@ $ score-compose run -f ./service-b.yaml -o ./service-b.compose.yaml
 $ score-compose run -f ./service-a.yaml -o ./service-a.compose.yaml --env-file ./.env
 ```
 
-Resulting output file  `service-a.compose.yaml` would include two dependencies on compose services `db` and `service-b`.
-Both should be up and running before `service-a` could start:
+One last step is to create a `db` service definition and enforce `service-a` dependencies in our target test environment.
+Common place to store non-score defined configuration and resources is a root `compose.yaml` file:
 
 ```yaml
 services:
   service-a:
-    command:
-      - -c
-      - 'while true; do echo service-a: Hello $${FRIEND}! Connecting to $${CONNECTION_STRING}...; sleep 10; done'
     depends_on:
       db:
         condition: service_started
       service-b:
         condition: service_started
-    entrypoint:
-      - /bin/sh
-    environment:
-      CONNECTION_STRING: postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST-localhost}:${DB_PORT-5432}/${DB_NAME-postgres}
-      NAME: ${NAME-World}
-    image: busybox
-```
-
-One last step is to ensure there is a compose `db` service definition.
-Common place to store non-score defined configuration and resources is a root `compose.yaml` file:
-
-```yaml
-services:
   db:
     image: postgres:alpine
     restart: always
diff --git a/examples/03-dependencies/compose.yaml b/examples/03-dependencies/compose.yaml
index 1d440fd..3212971 100644
--- a/examples/03-dependencies/compose.yaml
+++ b/examples/03-dependencies/compose.yaml
@@ -1,4 +1,10 @@
 services:
+  service-a:
+    depends_on:
+      db:
+        condition: service_started
+      service-b:
+        condition: service_started
   db:
     image: postgres:alpine
     restart: always
diff --git a/examples/03-dependencies/service-a.yaml b/examples/03-dependencies/service-a.yaml
index f541379..bfef595 100644
--- a/examples/03-dependencies/service-a.yaml
+++ b/examples/03-dependencies/service-a.yaml
@@ -33,4 +33,4 @@ resources:
       password:
         secret: true
   service-b:
-    type: workload
+    type: service
diff --git a/internal/compose/convert.go b/internal/compose/convert.go
index 86e0bba..483fb78 100644
--- a/internal/compose/convert.go
+++ b/internal/compose/convert.go
@@ -31,13 +31,6 @@ func ConvertSpec(spec *score.WorkloadSpec) (*compose.Project, ExternalVariables,
 			env[key] = &envVarVal
 		}
 
-		var dependsOn = make(compose.DependsOnConfig, len(spec.Resources))
-		for name, res := range spec.Resources {
-			if res.Type != "environment" && res.Type != "volume" {
-				dependsOn[name] = compose.ServiceDependency{Condition: "service_started"}
-			}
-		}
-
 		var ports []compose.ServicePortConfig
 		if len(spec.Service.Ports) > 0 {
 			ports = []compose.ServicePortConfig{}
@@ -87,7 +80,6 @@ func ConvertSpec(spec *score.WorkloadSpec) (*compose.Project, ExternalVariables,
 			Entrypoint:  cSpec.Command,
 			Command:     cSpec.Args,
 			Environment: env,
-			DependsOn:   dependsOn,
 			Ports:       ports,
 			Volumes:     volumes,
 		}


Test patch:
diff --git a/e2e-tests/resources/outputs/example-03-dependencies-service-a-output.txt b/e2e-tests/resources/outputs/example-03-dependencies-service-a-output.txt
index 5fa3efa..1428683 100644
--- a/e2e-tests/resources/outputs/example-03-dependencies-service-a-output.txt
+++ b/e2e-tests/resources/outputs/example-03-dependencies-service-a-output.txt
@@ -3,11 +3,6 @@ services:
     command:
       - -c
       - 'while true; do echo service-a: Hello $${FRIEND}! Connecting to $${CONNECTION_STRING}...; sleep 10; done'
-    depends_on:
-      db:
-        condition: service_started
-      service-b:
-        condition: service_started
     entrypoint:
       - /bin/sh
     environment:
diff --git a/internal/compose/convert_test.go b/internal/compose/convert_test.go
index faa89fa..2d2ec2e 100644
--- a/internal/compose/convert_test.go
+++ b/internal/compose/convert_test.go
@@ -79,7 +79,6 @@ func TestScoreConvert(t *testing.T) {
 						Environment: compose.MappingWithEquals{
 							"CONNECTION_STRING": stringPtr("test connection string"),
 						},
-						DependsOn: make(compose.DependsOnConfig, 0),
 						Ports: []compose.ServicePortConfig{
 							{
 								Published: "80",
@@ -167,10 +166,6 @@ func TestScoreConvert(t *testing.T) {
 								ReadOnly: true,
 							},
 						},
-						DependsOn: compose.DependsOnConfig{
-							"app-db": compose.ServiceDependency{Condition: "service_started"},
-							"dns":    compose.ServiceDependency{Condition: "service_started"},
-						},
 					},
 				},
 			},