https://github.com/ofek/hatch-containers
Hatch plugin for Docker containers
https://github.com/ofek/hatch-containers
containers docker hatch plugin python
Last synced: 2 months ago
JSON representation
Hatch plugin for Docker containers
- Host: GitHub
- URL: https://github.com/ofek/hatch-containers
- Owner: ofek
- License: mit
- Created: 2021-12-29T02:08:03.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-01T07:58:16.000Z (about 2 years ago)
- Last Synced: 2025-03-30T14:21:57.295Z (3 months ago)
- Topics: containers, docker, hatch, plugin, python
- Language: Python
- Homepage:
- Size: 72.3 KB
- Stars: 22
- Watchers: 2
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# hatch-containers
| | |
| --- | --- |
| CI/CD | [](https://github.com/ofek/hatch-containers/actions/workflows/test.yml) [](https://github.com/ofek/hatch/actions-containers/workflows/build.yml) |
| Package | [](https://pypi.org/project/hatch-containers/) [](https://pypi.org/project/hatch-containers/) |
| Meta | [](https://github.com/pypa/hatch) [](https://github.com/psf/black) [](https://github.com/ambv/black) [](https://spdx.org/licenses/) [](https://github.com/sponsors/ofek) |-----
This provides a plugin for [Hatch](https://github.com/pypa/hatch) that allows the use of containerized [environments](https://hatch.pypa.io/latest/environment/).
**Table of Contents**
- [Installation](#installation)
- [Configuration](#configuration)
- [Python](#python)
- [Image](#image)
- [Command](#command)
- [Startup](#startup)
- [Shell](#shell)
- [Notes](#notes)
- [Future](#future)
- [License](#license)## Installation
```console
pip install hatch-containers
```## Configuration
The [environment plugin](https://hatch.pypa.io/latest/plugins/environment/) name is `container`.
- ***pyproject.toml***
```toml
[tool.hatch.envs.]
type = "container"
```- ***hatch.toml***
```toml
[envs.]
type = "container"
```### Python
If the [Python version](https://hatch.pypa.io/latest/config/environment/#python-version) is set to a multi-character integer like `310` then it will be interpreted as its `.` form e.g. `3.10`.
If not set, then the `.` version of the first `python` found along your `PATH` will be used, defaulting to the Python executable Hatch is running on.
### Image
The `image` option specifies the container image to use e.g. `python:alpine`. It recognizes the placeholder value `{version}` which will be replaced by the value of the [Python option](#python).
Default:
```toml
[envs.]
image = "python:{version}"
```### Command
The `command` option specifies the command that the container will execute when [started](#startup).
Default:
```toml
[envs.]
command = ["/bin/sleep", "infinity"]
```### Startup
By default, containers will be started automatically when [entered](https://hatch.pypa.io/latest/environment/#entering-environments) or when [running commands](https://hatch.pypa.io/latest/environment/#command-execution) and will be stopped immediately after. If you want containers to start automatically upon [creation](https://hatch.pypa.io/latest/environment/#creation) and not be stopped until [removal](https://hatch.pypa.io/latest/environment/#removal), you can set `start-on-creation` to `true`.
Default:
```toml
[envs.]
start-on-creation = false
```### Shell
The `shell` option specifies the executable that will be used when [entering](https://hatch.pypa.io/latest/environment/#entering-environments) containers. By default, this is set to `/bin/bash` unless `alpine` is in the [image](#image) name, in which case `/bin/ash` will be used instead.
## Notes
- There must be a `docker` executable along your `PATH`.
- The `env-exclude` [environment variable filter](https://hatch.pypa.io/latest/config/environment/#filters) has no effect.## Future
- Support for Windows containers
- Support for building images## License
`hatch-containers` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.