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

Add v3 support of Docker Compose #600

Merged
merged 2 commits into from
Jun 14, 2017
Merged

Conversation

cdrage
Copy link
Member

@cdrage cdrage commented May 12, 2017

This does a major refactor on the compose.go functions as well as brings
in a new era of v3 support to Kompose.

Similar to how we utilize libcompose, we utilize docker/cli's "stack
deploy" code which has a built-in v3 parser. We convert the parsed
structure to our own and then convert it to Kubernetes/OpenShift
artifacts.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 12, 2017
@cdrage cdrage changed the title Add v3 support of Docker Compose [WIP] Add v3 support of Docker Compose May 12, 2017
@cdrage
Copy link
Member Author

cdrage commented May 12, 2017

FYI, this is a work-in-progress.

@jritsema
Copy link

Hey @cdrage. Just curious, did you guys decide to not wait for libcompose to update to v3 and just start consuming code directly from docker? Have you found it to be robust enough to consume as a library so far?

@cdrage
Copy link
Member Author

cdrage commented May 15, 2017

@jritsema Yes, and no.

Ideally we would like to use libcompose. Essentially we only use libcompose in order to correctly parse the docker compose file into a proper Go struct, that's it. We could actually possibly integrate our own code in the future to parse the docker-compose file into a proper structure.

So essentially, it ends up being easy to simply use http://github.com/docker/cli instead of http://github.com/docker/libcompose because we don't need the "deployment" functionality of libcompose, only the parsing capability.

Funny enough, the code is very similar!

See: https://github.com/docker/cli/blob/master/cli/compose/types/types.go#L72 vs https://github.com/docker/libcompose/blob/56b0613aac7d6d524d29dacb6b4221b5e4618d45/config/types.go#L87

@cdrage cdrage force-pushed the add-v3-support branch 2 times, most recently from f09dabc to 274c229 Compare May 15, 2017 20:42
@jritsema
Copy link

Interesting, thanks @cdrage. So does it support all of the compose semantics like multiple compose files and extends, etc?

https://docs.docker.com/compose/extends/

@cdrage
Copy link
Member Author

cdrage commented May 16, 2017

@jritsema At the moment, no, but eventually...

@cdrage
Copy link
Member Author

cdrage commented May 16, 2017

So the POC works now! You're able to go ahead and convert your v3 Docker Compose file to Kubernetes / OpenShift artifacts.

Feel free to pull / build this PR and use it!

At the moment there are some missing parts (mem_limit, CPUQuota, etc.) that I need to figure out before it's 100% complete.

@cdrage cdrage force-pushed the add-v3-support branch 6 times, most recently from 170b203 to 97a06df Compare May 19, 2017 17:27
@cdrage
Copy link
Member Author

cdrage commented May 19, 2017

Unfortunately I have to also update the vendoring to a higher version of docker/docker due to the cli being split into docker/cli. Need to resolve conflicts!

@cdrage cdrage force-pushed the add-v3-support branch 12 times, most recently from 692720a to e6231ed Compare May 24, 2017 15:37
@cdrage
Copy link
Member Author

cdrage commented Jun 6, 2017

So I've gone ahead and abstracted everything to it's own folder so it's a tad more organized as per @surajssd 's comments!

It looks like he'll be away for a while however, @surajnarwade or @kadel wanna take a look at this?

@cdrage cdrage force-pushed the add-v3-support branch 2 times, most recently from 672837b to 989d909 Compare June 6, 2017 18:44
Copy link
Contributor

@concaf concaf left a comment

Choose a reason for hiding this comment

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

Except a couple of nits, LGTM :)

glide.yaml Outdated
- package: github.com/docker/cli
version: 1fc7eb5d644599f30d0c6cc350a4d84ff528c864


Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra \n?

Copy link
Member Author

Choose a reason for hiding this comment

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

Woops!

})
// Check that the previous file loaded matches.
if len(files) > 0 && version != "" && version != composeVersion {
return kobject.KomposeObject{}, errors.New("All files passed must be the same version")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "All Docker Compose files must be of the same version"

@cdrage cdrage force-pushed the add-v3-support branch 2 times, most recently from 7d3c4ac to bca4c0e Compare June 7, 2017 14:23
@cdrage
Copy link
Member Author

cdrage commented Jun 7, 2017

@containscafeine DONE! Everything's been separated into it's own file so it's easier to understand / place everything if it's either v1/v2 conversion or v3.

One LGTM 👍 down, @surajssd @kadel @surajnarwade Want to take a second look?

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

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

For some reason env values are not propagated to Kubernetes artifacts.

For

version: '3'
services:
  foo:
    image: quay.io/tomkral/sleeper
    environment:
      FOO: foo

I get env without value.

        - env:
          - name: FOO

If I change version to '2' everything is ok

        - env:
          - name: FOO
            value: foo

this should be caught by tests :-(

for _, vol := range volumes {

// There will *always* be Source when parsing
v := vol.Source
Copy link
Member

Choose a reason for hiding this comment

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

docker-compose allows '_' in Volume names but Kubernetes does not.
normalizeServiceNames should be used here.

// DockerCompose uses map[string]*string while we use []string
// So let's convert that using this hack
var envKeys []string
for key := range composeServiceConfig.Environment {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be enough to handle env for v3?

		for  name, value := range composeServiceConfig.Environment {
			env := kobject.EnvVar{Name: name, Value: *value}
			serviceConfig.Environment = append(serviceConfig.Environment, env)
		}

It should also fix the problem with values not beeing populated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. When I previously tested it environment variables were working. I'll fix this and add a test (which I thought worked correctly with my full example yaml file).

@cdrage cdrage force-pushed the add-v3-support branch 2 times, most recently from e939e29 to 08658d3 Compare June 8, 2017 15:23
@cdrage
Copy link
Member Author

cdrage commented Jun 8, 2017

@kadel @surajssd

For missing the env variables: they now appear in the script/test/fixtures/v3/output* as well as I have added an explicit test for them.

A full example for v3 support is located here: script/test/fixtures/v3/docker-compose-full-example.yaml.

I've also added the normalizeVolumeNames as well as another explicit test on volumes.

@cdrage
Copy link
Member Author

cdrage commented Jun 12, 2017

@kadel @surajnarwade @surajssd @containscafeine

For secondary review!

@bgruening
Copy link

This is great work! Thanks a bunch!

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

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

sorry, forgot to hit submit button yesterday :-(

v := normalizeServiceNames(vol.Source)

if vol.Target != "" {
v = v + ":" + normalizeServiceNames(vol.Target)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that target path should be normalized. Target is always path. This will break paths with '_'.

This does a major refactor on the compose.go functions as well as brings
in a new era of v3 support to Kompose.

Similar to how we utilize libcompose, we utilize docker/cli's "stack
deploy" code which has a built-in v3 parser. We convert the parsed
structure to our own and then convert it to Kubernetes/OpenShift
artifacts.
@cdrage
Copy link
Member Author

cdrage commented Jun 13, 2017

@kadel made the change for vol target! 👍

Copy link
Member

@surajssd surajssd left a comment

Choose a reason for hiding this comment

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

LGTM

@surajssd surajssd merged commit 3be76ff into kubernetes:master Jun 14, 2017
@cdrage cdrage deleted the add-v3-support branch June 15, 2017 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. review needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants