Skip to content

Commit

Permalink
feat: rename workload resource dependency into service and move depen…
Browse files Browse the repository at this point in the history
…dencies configuration into environment specific config

Signed-off-by: Eugene Yarshevich <[email protected]>
  • Loading branch information
ghen committed Jan 26, 2023
1 parent 90d348d commit de1ec9c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 5 additions & 21 deletions examples/03-dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions examples/03-dependencies/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
services:
service-a:
depends_on:
db:
condition: service_started
service-b:
condition: service_started
db:
image: postgres:alpine
restart: always
Expand Down
2 changes: 1 addition & 1 deletion examples/03-dependencies/service-a.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ resources:
password:
secret: true
service-b:
type: workload
type: service
8 changes: 0 additions & 8 deletions internal/compose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
}
Expand Down
5 changes: 0 additions & 5 deletions internal/compose/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"},
},
},
},
},
Expand Down

0 comments on commit de1ec9c

Please sign in to comment.