score-spec / score-compose

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

feat(generate): added --publish port CLI flag #172

Closed astromechza closed 1 month ago

astromechza commented 1 month ago

This removes the need for some of the weird workarounds used in local development to publish private ports from workloads or resources that are usually only exposed to services within the docker network.

Now to access a workload port that doesn't have a dns+route to expose it, you can now use --publish <host port>:<workload name>:<container port> to add a port publish to the output compose.yaml file. This does not require that the port is set as a Score service port, therefore this can be used for things like debugging ports. For example, --publish 8080:my-workload:80 would publish a HTTP port to port 8080.

Now to access a resource port like a postgres, rabbitmq, or other resource that wouldn't be published externally you can use --publish <host port>:<resource uid>.output:<container port>. The expression in the middle allows you to select a resource service that usually has a dynamic hostname. For example --publish 5432:postgres#my-workload.db.host:5432 would expose the database db from workload my-workload.

Note, that these publish calls must be on the LAST request to score-compose generate since they apply to the final compose manifest.

I think this is better than the existing workarounds for doing this like:

  1. Putting compose.score.dev/publish-port annotations in your score file
  2. Using jq to examine and modify the compose file in place
  3. Adding additional socat services to the compose.yaml