Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for multiple containers in the same workload #46

Merged
merged 3 commits into from
Feb 6, 2024

Conversation

astromechza
Copy link
Member

@astromechza astromechza commented Feb 1, 2024

Description

This PR improves score-compose by allowing it to support multiple containers in the workload and still support published ports and services.

For example, running an api server and a backend worker in the same workload:

apiVersion: score.dev/v1b1
metadata:
  name: my-project

service:
  ports:
    api:
      port: 80
      targetPort: 8080
containers:
  api:
    image: my-project/my-image:0.0.1
    args: ["api"]
  worker:
    image: my-project/my-image:0.0.1
    args: ["worker"]

This produces a compose file that looks like:

services:
  my-project-api:
    command:
      - api
    image: my-project/my-image:0.0.1
    ports:
      - target: 8080
        published: "80"
  my-project-worker:
    command:
      - worker
    image: my-project/my-image:0.0.1
    network_mode: service:my-project-api

Note that the services have a container name appended, the ports are only present on the first service, and the other services inherit the network from the first.

What does this PR do?

  1. Add all containers as services to the compose project
  2. Add the container name as a suffix to build the service names
  3. Share the first services network with the remaining services to ensure port resolution works as expected

Note, (3) emulates what Kubernetes and other "pod"-style runtimes do by placing all containers into the same network namespace, thus no two containers in the same workload can bind to the same port! The advantage though is that the published ports do not need to indicate a particular container.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • New chore (expected functionality to be implemented)

Checklist:

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I've signed off with an email address that matches the commit author.

@astromechza astromechza changed the title feat: added support for multiple containers in the same network feat: added support for multiple containers in the same workload Feb 2, 2024
@astromechza astromechza linked an issue Feb 2, 2024 that may be closed by this pull request
internal/compose/convert.go Outdated Show resolved Hide resolved
internal/compose/convert.go Outdated Show resolved Hide resolved
@astromechza astromechza force-pushed the support-multiple-containers branch 4 times, most recently from 0c9d73c to 64bf5a6 Compare February 5, 2024 14:30
Copy link

@chrishumanitec chrishumanitec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@astromechza astromechza merged commit 2af4cd0 into main Feb 6, 2024
3 checks passed
@johanneswuerbach johanneswuerbach deleted the support-multiple-containers branch March 4, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants