docky
docky copied to clipboard
[UPD] Update Docky for Docker Compose v2
Update Docky for Docker Compose v2
Docker Compose V1 is deprecated
https://github.com/docker/compose
Warning
The final Compose V1 release, version 1.29.2, was May 10, 2021. These packages haven't received any security updates since then. Use at your own risk.
https://docs.docker.com/compose/migrate/
From July 2023 Compose V1 stopped receiving updates. It’s also no longer available in new releases of Docker Desktop.
Compose V2, which was first released in 2020, is included with all currently supported versions of Docker Desktop. It offers an improved CLI experience, improved build performance with BuildKit, and continued new-feature development.
Some recently updates in the Python and PyYAML seems cause errors in Docky
$ docky build
Traceback (most recent call last):
File "/home/test/.local/bin/docky", line 8, in <module>
sys.exit(main())
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/docky/main.py", line 7, in main
Docky.run()
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/plumbum/cli/application.py", line 638, in run
inst, retcode = subapp.run(argv, exit=False)
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/plumbum/cli/application.py", line 633, in run
retcode = inst.main(*tailargs)
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/docky/cmd/base.py", line 53, in main
self._init_project()
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/docky/cmd/base.py", line 48, in _init_project
self.project = Project()
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/docky/common/project.py", line 19, in __init__
self.project = command.project_from_options('.', {})
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/compose/cli/command.py", line 60, in project_from_options
return get_project(
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/compose/cli/command.py", line 152, in get_project
client = get_client(
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/compose/cli/docker_client.py", line 41, in get_client
client = docker_client(
File "/home/test/.local/share/pipx/venvs/docky/lib64/python3.9/site-packages/compose/cli/docker_client.py", line 124, in docker_client
kwargs = kwargs_from_env(environment=environment, ssl_version=tls_version)
TypeError: kwargs_from_env() got an unexpected keyword argument 'ssl_version'
If you try to reinstall Docky
$ pipx install docky --force
pip seemed to fail to build package:
PyYAML<6,>=3.10
Some possibly relevant errors from pip install:
error: subprocess-exited-with-error
AttributeError: cython_sources
Collecting PyYAML<6,>=3.10 (from docker-compose>=1.23.1->docky)
Using cached PyYAML-5.4.1.tar.gz (175 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'error'
self.filelist.extend(build_ext.get_source_files())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 201, in get_source_files
File "/tmp/pip-build-env-5rd4lxrc/overlay/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 107, in __getattr__
raise AttributeError(attr)
AttributeError: cython_sources
[end of output]
PyYAML
- Error installing Pyyaml==5.4, Cython_sources Maybe related with the Issue 724 https://github.com/yaml/pyyaml/issues
To fix it's need to update from 'docker-compose' V1 in Python to 'docker compose' V2 in GO, by the change of the language is not more possible import docker compose direct by python, some projects try to reimplement:
-
Docker-Py https://github.com/docker/docker-py
-
Python on whales https://github.com/gabrieldemarmiesse/python-on-whales
-
Docker Composer V2 https://github.com/jensenkairos/docker-composer-v2
I'm choosed Python-on-whales
from python_on_whales import docker project_config = docker.compose.config() print(project_config.services["my_first_service"].image) "redis"
- 1 to 1 mapping between the CLI interface and the Python API. No need to look in the docs what is the name of the function/argument you need.
- Support for the latest Docker features: Docker buildx/buildkit, docker run --gpu=all ...
While Docker-py is a complete re-implementation of the Docker client binary (written in Go), Python on whales sits on top of the Docker client binary, which makes implementing new features much easier and safer. For example, it's unlikely that docker-py supports Buildx/buildkit anytime soon because rewriting a large Go codebase in Python is hard work.
Some considerations
Should I use Docker-py or Python on Whales?
Well, it's written in each project's description!
Docker-py: A Python library for the Docker Engine API Python on whales: An awesome Python wrapper for an awesome Docker CLI
If you need to talk to the Docker engine directly, you need to do low level operations, use docker-py. Some good example > would be writing the code to control docker from an IDE, or if the speed of Docker calls is very important. If you don't want to depend on the Docker CLI binary (~50MB), use docker-py.
If you wanted to call the docker command line from Python, do high level operations, use Python on Whales. For example if you want to write your CI logic in Python rather than in bash (a very good choice 😉). Some commands are only available in Python on whales too: docker.buildx.build(...), docker.stack.deploy(...)...
Here python-on-whales are just use for get Config files from project, it's possible use some of the commands like docker.compose.run() and others https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/ but I keep it as before by Plumbum run in bash '$ docker compose run ...'.
Included a new command 'docky system' to get some System Infos OS Type, Kernel, OS, Docker, Docker Compose, and Docky versions; just to make easy debug errors related to some OS or old or new libraries versions, it's just a resume of '$ docker info'. Tests was made with:
- Ubuntu 24.04 ( package docker-compose-v2 )
- Slackware 15.0 current
In the case you are testing with another OS check the versions of the main libraries, tests with other OSs are welcome, should be better extract this commit? For testing the change for v2 seems usefull for debug but if necessary I can extract.
The Docky commnands working are build run logs ps up down kill restart in both OS , command docky open return error, the problem seems related to file dcpatched.py ( I let this file commented in the __init to avoid error with import, need to check if still is necessary, any help are welcome ) and docky pull need to be test.
Integrated the PR https://github.com/akretion/docky/pull/151 , with this LOG show the command(s) execute, I'm add "$ " before to show as a command docker compose ps $ docker compose ps / Should be better keep without $ ?
It's been usefull see what the command will be execute for check errors but there are a debate in the PR about this change, if necessary I can extract this commit.
I'm also tried integrated the PR https://github.com/akretion/docky/pull/152 for use pyproject.toml, but return error when try to install $ pipx install path_of_file/ --force
File "/tmp/pip-build-env-xkrei3u2/overlay/lib/python3.11/site-packages/hatchling/metadata/core.py", line 248, in _get_version
version = self.hatch.version.cached
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-xkrei3u2/overlay/lib/python3.11/site-packages/hatchling/metadata/core.py", line 1466, in cached
raise type(e)(message) from None
ValueError: Error getting the version from source `regex`: unable to parse the version from the file: docky/__init__.py
[end of output]
Other simple changes was made to removed deprecated encoding, change in License Header from '2018' to '2018-TODAY', call method super() don't need parameters, change simple quotes ' for double quotes " in python files and in the message about missing compose_file.py change print for logger.error.
The tests was made with a generic project in v14 with Brazilian Localization, futher tests with complex compose.yml parameters are welcome and necessary for a better review.
There are a error with Traefik when you run 'docky build', the log message don't show the complete error as 'docker compose build'
Error response from daemon: network traefik not found
Docker Compose show the complete erro with the fix
ERROR: Network traefik declared as external, but could not be found. Please create the network manually using `docker network create traefik` and try again.
Should be better if Docky show the same message or included the suggestion to solve.
If necessary, as said before, some committs can be extract for others PRs for a better review.
cc @rvalyi @renatonlima