Skip to content

Commit

Permalink
Fix Python packaging for Python 3.12 (#79)
Browse files Browse the repository at this point in the history
* Translate setup.py to pyproject.toml

* Introduce PEP518 by using Poetry as package manager
* Introduce PEP402-ish package structure
* Remove requirements.txt and setup.py
* Update Dockerfile and Docs for new packaging method

* Bump dependencies, remove six

six is no longer necessary as of docker-py 5.0.1 (see docker/docker-py#2863)
  • Loading branch information
Galaxy102 authored Nov 13, 2024
1 parent 9ac4048 commit 6c70d7c
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 34 deletions.
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM python:3-alpine
LABEL org.opencontainers.image.source https://github.com/Red5d/docker-autocompose

FROM python:3.12-alpine
LABEL org.opencontainers.image.source=https://github.com/Red5d/docker-autocompose
WORKDIR /usr/src/app
ENTRYPOINT [ "poetry", "run", "autocompose" ]

COPY . .
RUN apk add --no-cache poetry

RUN python ./setup.py install
COPY poetry.lock pyproject.toml README.md ./
COPY src ./src

ENTRYPOINT [ "python", "./autocompose.py" ]
RUN poetry install
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ Generates a docker-compose yaml definition from a docker container.
Required Modules:
* [pyaml](https://pypi.python.org/project/pyaml/)
* [docker](https://pypi.python.org/project/docker)
* [six](https://pypi.python.org/project/six)

For building this project [poetry](https://python-poetry.org/) is required. Install it with the package manager of your OS or if that's impossible with `pip`.

Install them:

poetry install

Example Usage:

sudo python autocompose.py <container-name-or-id>
poetry run autocompose <container ids>


Generate a compose file for multiple containers together:

sudo python autocompose.py apache-test mysql-test
poetry run autocompose apache-test mysql-test


The script defaults to outputting to compose file version 3, but use "-v 1" to output to version 1:

sudo python autocompose.py -v 1 apache-test
poetry run autocompose -v 1 apache-test


Outputs a docker-compose compatible yaml structure:
Expand All @@ -33,9 +38,7 @@ With this tool, I can easily generate docker-compose files for managing the cont

## Native installation

You can install it system-wide from the project directory with a command:

```python setup.py install --optimize=1```
System-wide installation is discouraged. If you really need to, you can run `pip install --user --break-system-packages .` (use at your own discretion).

There are unofficial packages available in the Arch User Repository:
* [Stable](https://aur.archlinux.org/packages/docker-autocompose)
Expand Down
311 changes: 311 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[tool.poetry]
name = "docker-autocompose"
version = "1.3.0"
description = "Generate a docker-compose yaml definition from a running container"
authors = ["Red5d"]
keywords = ["docker", "yaml", "container"]
license = "GPLv2"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Utilities"
]
homepage = "https://github.com/Red5d/docker-autocompose"
documentation = "https://github.com/Red5d/docker-autocompose/blob/master/README.md"
repository = "https://github.com/Red5d/docker-autocompose.git"
readme = "README.md"
packages = [
{ include = "src" }
]

[tool.poetry.dependencies]
# see https://python-poetry.org/docs/dependency-specification/ for version specifiers
python = ">=3.8"
pyaml = "~24.9.0"
docker = "~7.1.0"

[tool.poetry.scripts]
autocompose = "src.autocompose:main"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

18 changes: 0 additions & 18 deletions setup.py

This file was deleted.

Empty file added src/__init__.py
Empty file.
File renamed without changes.

0 comments on commit 6c70d7c

Please sign in to comment.