diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..45e8b58 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{html,js,json,py,yaml,yml}] +indent_style = space + +[*.py] +indent_size = 4 +continuation_indent_size = 8 +max_line_length = 120 + +[*.{html,js,json,yaml,yml}] +indent_size = 2 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..717d732 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 120 +ignore = E402,W503,W504 diff --git a/LICENSE b/LICENSE.txt similarity index 93% rename from LICENSE rename to LICENSE.txt index 2071b23..de75122 100644 --- a/LICENSE +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) +Copyright (c) 2022-present Raoul Snyman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md deleted file mode 100644 index ca4a68e..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# pyinfra-docker-compose - -A pyinfra module to install the Docker Compose plugin. \ No newline at end of file diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..d289e10 --- /dev/null +++ b/README.rst @@ -0,0 +1,27 @@ +pyinfra-docker-compose +====================== + +.. image:: https://img.shields.io/pypi/v/pyinfra + :alt: PyPI - Version + +----- + +A pyinfra module to install the Docker Compose plugin. + +.. contents:: Table of Contents + :depth: 1 + +Installation +------------ + +.. code-block:: shell + + pip install pyinfra-docker-compose + +License +------- + +``pyinfra-docker-compose`` is distributed under the terms of the `MIT`_ license. + + +.. MIT:: https://spdx.org/licenses/MIT.html diff --git a/pyinfra_docker_compose/__init__.py b/pyinfra_docker_compose/__init__.py new file mode 100644 index 0000000..e4d1c06 --- /dev/null +++ b/pyinfra_docker_compose/__init__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2022-present Raoul Snyman +# +# SPDX-License-Identifier: MIT +from pyinfra_docker_compose.docker_compose import deploy_docker_compose # noqa diff --git a/pyinfra_docker_compose/docker_compose.py b/pyinfra_docker_compose/docker_compose.py new file mode 100644 index 0000000..52055e3 --- /dev/null +++ b/pyinfra_docker_compose/docker_compose.py @@ -0,0 +1,40 @@ +# SPDX-FileCopyrightText: 2022-present Raoul Snyman +# +# SPDX-License-Identifier: MIT + +from pyinfra import host +from pyinfra.api.deploy import deploy +from pyinfra.api.exceptions import DeployError +from pyinfra.facts.deb import DebPackages +from pyinfra.facts.rpm import RpmPackages +from pyinfra.facts.server import Which +from pyinfra.operations import apt, dnf, yum + + +def _apt_install(): + apt.packages( + name='Install Docker Compose plugin via apt', + packages='docker-compose-plugin', + update=True + ) + + +def _yum_or_dnf_install(yum_or_dnf): + yum_or_dnf.packages( + name='Install Docker Compose plugin via yum', + packages=['docker-compose-plugin'] + ) + + +@deploy('Deploy Docker Compose') +def deploy_docker_compose(): + """ + Install the Docker Compose plugin on the target machine. + """ + + if host.get_fact(DebPackages): + _apt_install() + elif host.get_fact(RpmPackages): + _yum_or_dnf_install(dnf if host.get_fact(Which, command='dnf') else yum) + else: + raise DeployError('Neither apt or yum were found, pyinfra-docker-compose cannot provision this machine!') diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..94e2905 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,58 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[project] +name = "pyinfra-docker-compose" +description = '' +readme = "README.md" +requires-python = ">=3.7" +license = "MIT" +keywords = [] +authors = [ + { name = "Raoul Snyman", email = "raoul@libertytechforce.com" }, +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +dependencies = ["pyinfra-docker"] +dynamic = ["version"] + +[project.urls] +Documentation = "https://git.libertytechforce.com/libertytechforce/pyinfra-docker-compose#readme" +Issues = "https://git.libertytechforce.com/libertytechforce/pyinfra-docker-compose/issues" +Source = "https://git.libertytechforce.com/libertytechforce/pyinfra-docker-compose" + +[tool.hatch.version] +source = "vcs" + +[tool.hatch.envs.default] +dependencies = [ + "pytest", + "pytest-cov", +] +[tool.hatch.envs.default.scripts] +cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=pyinfra_docker_compose --cov=tests" +no-cov = "cov --no-cov" + +[[tool.hatch.envs.test.matrix]] +python = ["37", "38", "39", "310", "311"] + +[tool.coverage.run] +branch = true +parallel = true + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..0b33ac4 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022-present Raoul Snyman +# +# SPDX-License-Identifier: MIT