score-spec / score-compose

Reference implementation for docker-compose target platform support
https://docs.score.dev/docs/score-implementation/score-compose/
Apache License 2.0
446 stars 42 forks source link

[feature request] Ability to expose service ports on the docker host #159

Closed astromechza closed 2 months ago

astromechza commented 3 months ago

Score currently supports the notion of a service port like:

...
services:
  port:
    web:
      port: 80
...

Now generally this is an indicator that this particular port should be exposed to other services within the same network, but crucially not to external routes outside the network. That's generally what the route and dns resource types are for.

However, when using score-compose, there's often a need to test a service which just exposes a service port. The current mechanism is to write a companion compose file which can be interpreted together with the compose.yaml that score-compose generates, and use this to override the published ports of the service.

However, it would be much more clean if we had an easier way to just indicate - expose this service port. This could be done through annotations like we use in certain provisioners, or as a CLI argument to score compose itself.

Eg 1:

metadata:
  name: workload-name
  annotations:
    compose.score.dev/publish-service-ports: 80,443

Eg 2:

score-compose generate score.yaml -p 80 -p 443

What are folks thoughts?

astromechza commented 3 months ago

I think the second example is far more compelling and generalisable. However my one concern is about how we publish resource service ports, such as mysql/postgres/etc if they have unique names associated with them.

astromechza commented 3 months ago

We probably want to use a resource output to indicate what we want to publish when executing generate. For example:

To publish a workload port that is normally intended to be internal and doesn't have a dns/route. We just indicate the workload-name. The port can either be an exact port or it can be the name of a Score service exposed by that workload.

--publish 8080:workload-name:80

To publish a resource port, eg a mysql or postgres DB port:

--publish 5432:TYPE.CLASS#ID.host:TYPE.CLASS#ID.port

Both of these options effectively convert into a HOST_PORT, COMPOSE_SERVICE, CONTAINER_PORT tuple which are injected into the final compose yaml as an override to services.COMPOSE_SERVICE.ports[]