-
Notifications
You must be signed in to change notification settings - Fork 770
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
Conversation
FYI, this is a work-in-progress. |
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? |
@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 |
f09dabc
to
274c229
Compare
Interesting, thanks @cdrage. So does it support all of the compose semantics like multiple compose files and extends, etc? |
@jritsema At the moment, no, but eventually... |
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. |
170b203
to
97a06df
Compare
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! |
692720a
to
e6231ed
Compare
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? |
672837b
to
989d909
Compare
There was a problem hiding this 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 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra \n?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops!
pkg/loader/compose/compose.go
Outdated
}) | ||
// 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") |
There was a problem hiding this comment.
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"
7d3c4ac
to
bca4c0e
Compare
@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? |
There was a problem hiding this 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 :-(
pkg/loader/compose/v3.go
Outdated
for _, vol := range volumes { | ||
|
||
// There will *always* be Source when parsing | ||
v := vol.Source |
There was a problem hiding this comment.
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.
pkg/loader/compose/v3.go
Outdated
// 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
e939e29
to
08658d3
Compare
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: I've also added the normalizeVolumeNames as well as another explicit test on volumes. |
@kadel @surajnarwade @surajssd @containscafeine For secondary review! |
This is great work! Thanks a bunch! |
There was a problem hiding this 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 :-(
pkg/loader/compose/v3.go
Outdated
v := normalizeServiceNames(vol.Source) | ||
|
||
if vol.Target != "" { | ||
v = v + ":" + normalizeServiceNames(vol.Target) |
There was a problem hiding this comment.
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.
@kadel made the change for vol target! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.