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

use docker compose v2 #163

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

fmcwalters-edited
Copy link
Contributor

@fmcwalters-edited fmcwalters-edited commented Feb 15, 2024

docker compose v2 is part of Docker nowadays. Rather than calling a separate Python lib that calls docker-compose, call docker compose and use v2.
Fix the - and _ difference between v1 and v2.
This will need THOROUGH testing

PFM-827

Purpose of PR

Upgrade to use Docker Compose V2

Parts of the app this will impact

docker compose

Todos

Test on Linux machines, different CI builds with different packages

Additional information

This will require Docker with Compose v2

Related links

docker compose v2 is part of Docker nowadays. Rather than calling
a separate Python lib that calls `docker-compose`, call `docker compose`
and use v2.
Fix the `-` and `_` difference between v1 and v2.
This will need THOROUGH testing

PFM-827
Copy link
Member

@gchazot gchazot left a comment

Choose a reason for hiding this comment

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

I doubt this is going to work as-is. It would be very lucky that all of the features of docker-compose that kubetools uses are fully backwards-compatible in docker compose.

CHANGELOG.md Outdated Show resolved Hide resolved
kubetools/dev/backends/docker_compose/docker_util.py Outdated Show resolved Hide resolved
@fmcwalters-edited
Copy link
Contributor Author

I doubt this is going to work as-is. It would be very lucky that all of the features of docker-compose that kubetools uses are fully backwards-compatible in docker compose.

This is why it's only in draft, it still needs a thorough test across all dev machine OSes, architectures and with as many packages/services as possible.

@fmcwalters-edited
Copy link
Contributor Author

I'm also seeing

WARN[0000] network default: network.external.name is deprecated. Please set network.name with external: true 

from running ktd destroy - whilst this does not break anything yet, I feel like at this stage it is worth fixing.

the old type, `network.external.name` is deprecated on v2. It still works
but it may be removed in future. Change to new format. See:
docker-archive/compose-cli#1856
this code will only ever be used in this version of the tool, and the
`__version__` only checks the version of the _tool_ anyways.

Also remove redundant print statements
if we create a container using compose v1 and we want to use or remove it
using compose v2, we will need to convert its name to use the new format
there are times where the container name consists of multiple names or
a name and then a number; for example, composename-container-name-1-1.
We want to keep only `container-name-1`. Ensure this is possible
@fmcwalters-edited
Copy link
Contributor Author

force push because the previous code was weird - it was just to deal with the cases where there was more than one middle name

@fmcwalters-edited
Copy link
Contributor Author

fmcwalters-edited commented Feb 16, 2024

we can test this locally using something like echo -n "cython <3" > /tmp/constraint.txt && PIP_CONSTRAINT=/tmp/constraint.txt pip install -e ~/apps/kubetools to build and install from this branch. Then ensure you're using v14.0.0 when you run ktd.

Use the most logical version number for the next major version of this.

This version of Kubetools introduces some unavoidable breaking changes
that we can work around. Document these in the README.
add incompatible version of Docker Desktop to CHANGELOG and add more detail
to README as to why we need to be careful with this update
@fmcwalters-edited fmcwalters-edited marked this pull request as ready for review February 27, 2024 11:34
@fmcwalters-edited
Copy link
Contributor Author

I have put this up for a dev release - it has been tested to work (with caveats - see README) on Mac Intel i5 and Mac M3.
However - we need to test this on Linux systems and in particular on build servers.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
kubetools/dev/backends/docker_compose/docker_util.py Outdated Show resolved Hide resolved
fmcwalters-edited and others added 2 commits February 28, 2024 10:51
suggest migrating to secure Docker registries, reword the suggestion to use the legacy builder

Co-authored-by: Germain Chazot <[email protected]>
make the code easier to test by moving the name conversion into its
own function and add test coverage

also add test coverage for `dockerise_label`
@fmcwalters-edited
Copy link
Contributor Author

force push only to clean up some mistakes I made with linting and syntax 🤦‍♂️

add `TROUBLESHOOTING` section to README to document the issue with
`insecure-registries` and link this to ticket which is open and relevant,
for `buildx`.

remove anything from the CHANGELOG which belongs here
setup.py Show resolved Hide resolved
Copy link
Member

@gchazot gchazot left a comment

Choose a reason for hiding this comment

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

Just realised I had all those comments pending from months ago.

'external': {
'name': 'dev',
},
'name': 'dev',
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should take this opportunity to rename this "default" network used by ktd.

default here in the config is from the point of view of the project/container. This declares the default network for the project to be "external" (i.e. pre-existing outside this compose project) and named dev.

I think we should replace dev by something that clearly identifies it as used by ktd. Maybe ktd_dev could be an option.

Also, from a few tests I've run, it seems like other "environments" as created with --env option (or test in the case of ktd test), end up with a "temporary" network name (i.e. it's not "external" and IS deleted by the destroy operation) which looks like <appname>_<env>_default. I think it would be cool if that network name ended up being similarly, something like ktd_<env>.
This aspect probably requires a lot of work to implement, However it could be the base for a feature allowing to create "multi-app" environments, in a similar way as we can today do with the "default" environment.

Comment on lines +147 to +148
If you try and run `ktd up` with reference to an unsecure registry, e.g. `http://docker-registry.example.net` and are affected by this bug, you will get an error message that is
similar to the following:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If you try and run `ktd up` with reference to an unsecure registry, e.g. `http://docker-registry.example.net` and are affected by this bug, you will get an error message that is
similar to the following:
If you try and run `ktd up` with reference to an unsecure registry, e.g. `http://docker-registry.example.net` and are affected by this bug, you will get an error message that is similar to the following:



class TestDockerComposeNameConversion(TestCase):
# we need to check this works for dashes and underscores
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# we need to check this works for dashes and underscores

from kubetools.dev.backends.docker_compose.docker_util import _get_container_name_from_full_name


def generate_long_names(number_of_separators, separator):
Copy link
Member

Choose a reason for hiding this comment

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

See comment below, this function probably will disappear. But if it had to stay, then it needs to be renamed because it's confusing::

  • It is generating ONE name, not (several) _names
  • Why do they have to be "long" ? Is it important for the tests? What would not be tested if the names were "short" ? Note that this aspect of making tests more understandable does not belong in this function's name only, but in how/why the result of it is used in tests.

for i in range(5):
long_name = generate_long_names(i, '-')
dockerised_name = dockerise_label(long_name)
self.assertEqual(dockerised_name, ascii_lowercase[:i+1])
Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite sure but I have a feeling that we're using ascii_lowercase here as a "long string", which "could look like an app name". If that the case, then in my opinion it's a bad idea. It's a case of "wrong abstraction". Instead here we want to use names that could really be what they stand for, so that it's obvious to the reader what we're talking about. Put them in a list and iterate over them. If you're worried about repeating that list too much, extract it in a constant and reuse it in each place.

Comment on lines +195 to +196
# if the container was made in v1, it will be composename_container_N
converted_name = full_name.replace('_', '-')
Copy link
Member

Choose a reason for hiding this comment

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

Just to check, are we trying to create logic that is backwards compatible with compose V2?

I think that, in line with the change to README and with the major version change, we don´t need to support any backwards compatible logic here.

dockerised_name = dockerise_label(long_name)
self.assertEqual(dockerised_name, ascii_lowercase[:i+1])

def test_container_name_from_full_name_dashes(self):
Copy link
Member

Choose a reason for hiding this comment

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

These test names don't explain the scenario that we're testing here.
What are the cases where this logic might be relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants