-
-
Notifications
You must be signed in to change notification settings - Fork 511
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: support native docker compose api #476
feat: support native docker compose api #476
Conversation
@baez90 shall we change the PR to draft? We can start the review once you feel confortable with it And thanks for your time here, using the native Go libraries for compose is a great addition that none of the other languages can do! :kudos: |
We can do that if you prefer. I would actually appreciate a first review! To make the pipeline working I'd have to remove Go versions < 1.16. I could do that but wasn't sure if this is okay? |
Fine for me about the removal 🙋♂️ |
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.
Great PR @baez90!!!
I'm starting to like the functional approach for optional configurations, although I need to practice more. Thanks for sharing!
At this stage of the review, this PR is a +1. Great great great job with the tests!
b80f3c4
to
1d21f17
Compare
Codecov Report
@@ Coverage Diff @@
## main #476 +/- ##
===========================================
- Coverage 34.50% 13.54% -20.97%
===========================================
Files 13 15 +2
Lines 1759 2001 +242
===========================================
- Hits 607 271 -336
- Misses 1056 1684 +628
+ Partials 96 46 -50
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
44bd0b0
to
e3ab14a
Compare
Thanks for this PR! Looks super promising! It would be also awesome if we improve the docs about using compose with the new API design. |
Sure, I'm actually wondering if I should try to get a PR into I'll give it a shot tomorrow to see if the dependency update would make things easier and update the docs either way accordingly 😊 |
@baez90 no updates on this PR as I've been very busy with certain updates that will be public soon. I'll let you know once I'm 100% available to continue with this (hopefully soon) |
Don't you worry I'm a bit busy myself as well. As previously mentioned I tried if upgrading the Docker version would help to get rid of the replacement stuff but doesn't work. Probably when Docker 22.xx is released or so 😅 I'll try to update the docs probably tomorrow or begining of next week and I also have to rebase the branch once more. Do you mind if I add something about Podman support as well when I'm already on it or shall I create another PR for that? Until then good luck with whatever you're currently working on 😉 |
That would be perfect in a separate PR, faster to review and merge.
Thanks my friend!! |
e3ab14a
to
f880dcb
Compare
a2ec5a6
to
da7ee20
Compare
Alright @mdelapenya I prepared at least some docs, rebased everything once more and updated the dependencies. Let me know if I should update the description once more or if the docs need further adjustments or anything else 😊 till then I'll have a look at #496 |
I just wanted to add a reference to an issue I remembered from the Compose project where someone asked if So for future reference, this is the issue where they track the progress on this: I'd suggest only releasing stable support for this, once upstream provides stable support. However, since you already distinguish by API within |
Well I'll resolve the conflicts once more and afterwards we can discuss how to proceed with this PR? |
Maybe Most prominent is the container/service naming, using hyphens instead of underscores. Regarding:
while technically true, every breaking change will reflect on how users (and there are existing users of |
Funny that you mention the hyphens-vs-underscores problem as I took care of that a while ago 😄 (see here if you're interested) when I noticed that most of the test code was still running with compose V1 while I was running the tests locally with V2 but apart from that I haven't experienced any further problems with compose V1 vs. V2. I totally understand your concern that the API should be as stable as possible to ensure But as I said previously the new public API does not directly expose any compose details and also only includes some basic compose options so I'm pretty confident almost every breaking change can be hidden. The worst case I can think of is that some options aren't supported in the future and this can still be handled gracefully by deprecating the Do I miss something? |
da7ee20
to
ad322ed
Compare
just want to add that besides the hyphens/underscore change in compose v2 the compose file version supported in v2 starts with 2. There should be |
Is something missing here @mdelapenya ? |
ec4d113
to
eaa8999
Compare
I incorporated the docs changes we spoke of and added another section regarding the service name API. |
At the moment there is a force-push, I lose track of what I'd already reviewed and what I hadn't. I'd thank if we avoid pushing-force the PRs 🙏 We are squashing commits since the release of 0.14, so no worries about the story of the main branch: it will be now cleaner :) |
I added another commit regarding the docs yesterday and did not change any previous commit, I only rebased it onto If you prefer I'll merge |
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.
Minor comments or typos in docs
|
||
func TestSomething(t *testing.T) { | ||
compose, err := tc.NewDockerCompose("testresources/docker-compose.yml") | ||
assert.NoError(t, err, "NewDockerComposeAPI()") |
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.
assert.NoError(t, err, "NewDockerComposeAPI()") | |
assert.NoError(t, err, "NewDockerCompose()") |
func TestSomethingElse(t *testing.T) { | ||
identifier := tc.StackIdentifier("some_ident") | ||
compose, err := tc.NewDockerComposeWith(tc.WithStackFiles("./testresources/docker-compose-simple.yml"), identifier) | ||
assert.NoError(t, err, "NewDockerComposeAPIWith()") |
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.
assert.NoError(t, err, "NewDockerComposeAPIWith()") | |
assert.NoError(t, err, "NewDockerComposeWith()") |
|
||
### Interacting with compose services | ||
|
||
To interact with service containers after a stack was started it is possible to get an `*tc.DockerContainer` instance via the `ServiceContainer(...)` function. |
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.
To interact with service containers after a stack was started it is possible to get an `*tc.DockerContainer` instance via the `ServiceContainer(...)` function. | |
To interact with service containers after a stack was started it is possible to get a `*tc.DockerContainer` instance via the `ServiceContainer(...)` function. |
The function takes a **service name** (and a `context.Context`) and returns either a `*tc.DockerContainer` or an `error`. | ||
This is different to the previous `LocalDockerCompose` API where service containers were accessed via their **container name** e.g. `mysql_1` or `mysql-1` (depending on the version of `docker-compose`). | ||
|
||
Furthermore, there's the convenience function `Serices()` to get a list of all services **defined** by the current project. |
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.
Furthermore, there's the convenience function `Serices()` to get a list of all services **defined** by the current project. | |
Furthermore, there's the convenience function `Services()` to get a list of all services **defined** by the current project. |
|
||
## Usage of `docker-compose` binary | ||
|
||
_Node:_ this API is deprecated and superseded by `ComposeStack` which takes advantage of `docker-compose` v2 being |
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.
_Node:_ this API is deprecated and superseded by `ComposeStack` which takes advantage of `docker-compose` v2 being | |
_Node:_ this API is **deprecated** and superseded by `ComposeStack` which takes advantage of `docker-compose` v2 being |
Yes please 🙏 that would help! Apart from that, the CI builds are failing, seems related to |
@baez90 I found #574, which it's fixing the CI |
@baez90 I've noticed this error in the pipeline, related to a concurrent access to a map (compose_api.go:294):
Could you take a look? 🙏 |
@baez90 test are passing! I pushed 4111cdc and b231f60 with the sole goal of making this PR into main ASAP. Hope you understand. My plans are: release v0.15.0 this week(end) without this PR, and immediately merge this PR for a dedicated v0.16.0 to isolate the compose changes. Does it sound good to you? |
@baez90 I'm merging this PR now. Big big thanks for the huge refactor which simplifies a lot the maintenance of the compose module. We will eventually remove (and communicate) the local compose code after having the native implementation. |
Thanks for taking care! I just couldn't manage to get some time to work on this PR so thanks a lot! Also for all the support, time for reviews and your valuable input all the time! |
What does this PR do?
Deprecate shell-escape based
LocalDockerCompose
implementation and provide newdocker/compose
based one using the Docker API. Introduce a new API that takescontext.Context
into account. Furthermore it exposes more typed options.#425