mirror of
https://github.com/containers/podman-compose.git
synced 2024-11-25 17:33:50 +01:00
Merge branch 'devel' into fix-build-url-context
This commit is contained in:
commit
98715b4a49
1
.codespellignore
Normal file
1
.codespellignore
Normal file
@ -0,0 +1 @@
|
||||
assertIn
|
4
.codespellrc
Normal file
4
.codespellrc
Normal file
@ -0,0 +1,4 @@
|
||||
[codespell]
|
||||
skip = .git,*.pdf,*.svg,requirements.txt,test-requirements.txt
|
||||
# poped - loved variable name
|
||||
ignore-words-list = poped
|
2
.coveragerc
Normal file
2
.coveragerc
Normal file
@ -0,0 +1,2 @@
|
||||
[run]
|
||||
parallel=True
|
19
.editorconfig
Normal file
19
.editorconfig
Normal file
@ -0,0 +1,19 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = tab
|
||||
tab_width = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 100
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.py]
|
||||
indent_style = space
|
||||
|
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -13,8 +13,6 @@ A clear and concise description of what the bug is.
|
||||
Please make sure it's not a bug in podman (in that case report it to podman)
|
||||
or your understanding of docker-compose or how rootless containers work (for example, it's normal for rootless container not to be able to listen for port less than 1024 like 80)
|
||||
|
||||
please try to reproduce the bug in latest devel branch
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. what is the content of the current working directory (ex. `docker-compose.yml`, `.env`, `Dockerfile`, ...etc.)
|
||||
|
10
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
10
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
## Contributor Checklist:
|
||||
|
||||
If this PR adds a new feature that improves compatibility with docker-compose, please add a link
|
||||
to the exact part of compose spec that the PR touches.
|
||||
|
||||
For any user-visible change please add a release note to newsfragments directory, e.g.
|
||||
newsfragments/my_feature.feature. See newsfragments/README.md for more details.
|
||||
|
||||
All changes require additional unit tests.
|
22
.github/workflows/codespell.yml
vendored
Normal file
22
.github/workflows/codespell.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
name: Codespell
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
codespell:
|
||||
name: Check for spelling errors
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Codespell
|
||||
uses: codespell-project/actions-codespell@v2
|
||||
with:
|
||||
ignore_words_file: .codespellignore
|
41
.github/workflows/pylint.yml
vendored
41
.github/workflows/pylint.yml
vendored
@ -1,41 +0,0 @@
|
||||
name: Pylint
|
||||
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
lint-black:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install psf/black requirements
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y python3 python3-venv
|
||||
- uses: psf/black@stable
|
||||
with:
|
||||
options: "--check --verbose"
|
||||
version: "~= 23.3"
|
||||
|
||||
lint-pylint:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
pip install pylint
|
||||
- name: Analysing the code with pylint
|
||||
run: |
|
||||
python -m compileall podman_compose.py
|
||||
pylint podman_compose.py
|
||||
# pylint $(git ls-files '*.py')
|
36
.github/workflows/pytest.yml
vendored
36
.github/workflows/pytest.yml
vendored
@ -1,36 +0,0 @@
|
||||
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
|
||||
|
||||
name: PyTest
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ devel ]
|
||||
pull_request:
|
||||
branches: [ devel ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python 3.10
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install flake8 pytest
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
python -m pytest ./pytests
|
||||
|
25
.github/workflows/static-checks.yml
vendored
Normal file
25
.github/workflows/static-checks.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
name: Static checks
|
||||
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
static-checks:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: docker.io/library/python:3.11-bookworm
|
||||
# cgroupns needed to address the following error:
|
||||
# write /sys/fs/cgroup/cgroup.subtree_control: operation not supported
|
||||
options: --privileged --cgroupns=host
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Analysing the code with ruff
|
||||
run: |
|
||||
set -e
|
||||
pip install -r test-requirements.txt
|
||||
ruff format --check
|
||||
ruff check
|
||||
- name: Analysing the code with pylint
|
||||
run: |
|
||||
pylint podman_compose.py
|
40
.github/workflows/test.yml
vendored
Normal file
40
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
name: Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: "docker.io/library/python:${{ matrix.python-version }}-bookworm"
|
||||
# cgroupns needed to address the following error:
|
||||
# write /sys/fs/cgroup/cgroup.subtree_control: operation not supported
|
||||
options: --privileged --cgroupns=host
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
set -e
|
||||
apt update && apt install -y podman
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
pip install -r test-requirements.txt
|
||||
- name: Run integration tests
|
||||
run: |
|
||||
python -m unittest discover -v tests/integration
|
||||
env:
|
||||
TESTS_DEBUG: 1
|
||||
- name: Run unit tests
|
||||
run: |
|
||||
coverage run --source podman_compose -m unittest discover tests/unit
|
||||
- name: Report coverage
|
||||
run: |
|
||||
coverage combine
|
||||
coverage report --format=markdown | tee -a $GITHUB_STEP_SUMMARY
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -47,6 +47,8 @@ coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
test-compose.yaml
|
||||
test-compose-?.yaml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
@ -103,3 +105,6 @@ venv.bak/
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
|
||||
.vscode
|
||||
|
@ -30,3 +30,7 @@ repos:
|
||||
"-sn", # Don't display the score
|
||||
"--rcfile=.pylintrc", # Link to your config file
|
||||
]
|
||||
- repo: https://github.com/codespell-project/codespell
|
||||
rev: v2.2.5
|
||||
hooks:
|
||||
- id: codespell
|
||||
|
161
CONTRIBUTING.md
161
CONTRIBUTING.md
@ -2,113 +2,134 @@
|
||||
|
||||
## Who can contribute?
|
||||
|
||||
- Users that found a bug
|
||||
- Users that wants to propose new functionalities or enhancements
|
||||
- Users that want to help other users to troubleshoot their environments
|
||||
- Developers that want to fix bugs
|
||||
- Developers that want to implement new functionalities or enhancements
|
||||
|
||||
## Branches
|
||||
|
||||
Please request your PR to be merged into the `devel` branch.
|
||||
Changes to the `stable` branch are managed by the repository maintainers.
|
||||
- Users that found a bug,
|
||||
- Users that want to propose new functionalities or enhancements,
|
||||
- Users that want to help other users to troubleshoot their environments,
|
||||
- Developers that want to fix bugs,
|
||||
- Developers that want to implement new functionalities or enhancements.
|
||||
|
||||
## Development environment setup
|
||||
|
||||
Note: Some steps are OPTIONAL but all are RECOMMENDED.
|
||||
|
||||
1. Fork the project repo and clone it
|
||||
```shell
|
||||
$ git clone https://github.com/USERNAME/podman-compose.git
|
||||
$ cd podman-compose
|
||||
```
|
||||
1. (OPTIONAL) Create a python virtual environment. Example using [virtualenv wrapper](https://virtualenvwrapper.readthedocs.io/en/latest/):
|
||||
```shell
|
||||
mkvirtualenv podman-compose
|
||||
```
|
||||
2. Install the project runtime and development requirements
|
||||
```shell
|
||||
$ pip install '.[devel]'
|
||||
```
|
||||
3. (OPTIONAL) Install `pre-commit` git hook scripts (https://pre-commit.com/#3-install-the-git-hook-scripts)
|
||||
```shell
|
||||
$ pre-commit install
|
||||
```
|
||||
4. Create a new branch, develop and add tests when possible
|
||||
5. Run linting & testing before commiting code. Ensure all the hooks are passing.
|
||||
```shell
|
||||
$ pre-commit run --all-files
|
||||
```
|
||||
6. Commit your code to your fork's branch.
|
||||
- Make sure you include a `Signed-off-by` message in your commits. Read [this guide](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) to learn how to sign your commits
|
||||
- In the commit message reference the Issue ID that your code fixes and a brief description of the changes. Example: `Fixes #516: allow empty network`
|
||||
7. Open a PR to `containers/podman-compose:devel` and wait for a maintainer to review your work.
|
||||
1. Fork the project repository and clone it:
|
||||
|
||||
```shell
|
||||
$ git clone https://github.com/USERNAME/podman-compose.git
|
||||
$ cd podman-compose
|
||||
```
|
||||
|
||||
2. (OPTIONAL) Create a Python virtual environment. Example using
|
||||
[virtualenv wrapper](https://virtualenvwrapper.readthedocs.io/en/latest/):
|
||||
|
||||
```shell
|
||||
$ mkvirtualenv podman-compose
|
||||
```
|
||||
|
||||
3. Install the project runtime and development requirements:
|
||||
|
||||
```shell
|
||||
$ pip install '.[devel]'
|
||||
```
|
||||
|
||||
4. (OPTIONAL) Install `pre-commit` git hook scripts
|
||||
(https://pre-commit.com/#3-install-the-git-hook-scripts):
|
||||
|
||||
```shell
|
||||
$ pre-commit install
|
||||
```
|
||||
|
||||
5. Create a new branch, develop and add tests when possible.
|
||||
6. Run linting and testing before committing code. Ensure all the hooks are passing.
|
||||
|
||||
```shell
|
||||
$ pre-commit run --all-files
|
||||
```
|
||||
|
||||
7. Run code coverage:
|
||||
|
||||
```shell
|
||||
$ coverage run --source podman_compose -m unittest discover tests/unit
|
||||
$ python3 -m unittest discover tests/integration
|
||||
$ coverage combine
|
||||
$ coverage report
|
||||
$ coverage html
|
||||
```
|
||||
|
||||
8. Commit your code to your fork's branch.
|
||||
- Make sure you include a `Signed-off-by` message in your commits.
|
||||
Read [this guide](https://github.com/containers/common/blob/main/CONTRIBUTING.md#sign-your-prs)
|
||||
to learn how to sign your commits.
|
||||
- In the commit message, reference the Issue ID that your code fixes and a brief description of
|
||||
the changes.
|
||||
Example: `Fixes #516: Allow empty network`
|
||||
9. Open a pull request to `containers/podman-compose` and wait for a maintainer to review your work.
|
||||
|
||||
## Adding new commands
|
||||
|
||||
To add a command you need to add a function that is decorated
|
||||
with `@cmd_run` passing the compose instance, command name and
|
||||
description. the wrapped function should accept two arguments
|
||||
the compose instance and the command-specific arguments (resulted
|
||||
from python's `argparse` package) inside that command you can
|
||||
run PodMan like this `compose.podman.run(['inspect', 'something'])`
|
||||
and inside that function you can access `compose.pods`
|
||||
and `compose.containers` ...etc.
|
||||
Here is an example
|
||||
To add a command, you need to add a function that is decorated with `@cmd_run`.
|
||||
|
||||
```
|
||||
The decorated function must be declared `async` and should accept two arguments: The compose
|
||||
instance and the command-specific arguments (resulted from the Python's `argparse` package).
|
||||
|
||||
In this function, you can run Podman (e.g. `await compose.podman.run(['inspect', 'something'])`),
|
||||
access `compose.pods`, `compose.containers` etc.
|
||||
|
||||
Here is an example:
|
||||
|
||||
```python
|
||||
@cmd_run(podman_compose, 'build', 'build images defined in the stack')
|
||||
def compose_build(compose, args):
|
||||
compose.podman.run(['build', 'something'])
|
||||
async def compose_build(compose, args):
|
||||
await compose.podman.run(['build', 'something'])
|
||||
```
|
||||
|
||||
## Command arguments parsing
|
||||
|
||||
Add a function that accept `parser` which is an instance from `argparse`.
|
||||
In side that function you can call `parser.add_argument()`.
|
||||
The function decorated with `@cmd_parse` accepting the compose instance,
|
||||
and command names (as a list or as a string).
|
||||
You can do this multiple times.
|
||||
To add arguments to be parsed by a command, you need to add a function that is decorated with
|
||||
`@cmd_parse` which accepts the compose instance and the command's name (as a string list or as a
|
||||
single string).
|
||||
|
||||
Here is an example
|
||||
The decorated function should accept a single argument: An instance of `argparse`.
|
||||
|
||||
```
|
||||
In this function, you can call `parser.add_argument()` to add a new argument to the command.
|
||||
|
||||
Note you can add such a function multiple times.
|
||||
|
||||
Here is an example:
|
||||
|
||||
```python
|
||||
@cmd_parse(podman_compose, 'build')
|
||||
def compose_build_parse(parser):
|
||||
parser.add_argument("--pull",
|
||||
help="attempt to pull a newer version of the image", action='store_true')
|
||||
parser.add_argument("--pull-always",
|
||||
help="attempt to pull a newer version of the image, Raise an error even if the image is present locally.", action='store_true')
|
||||
help="Attempt to pull a newer version of the image, "
|
||||
"raise an error even if the image is present locally.",
|
||||
action='store_true')
|
||||
```
|
||||
|
||||
NOTE: `@cmd_parse` should be after `@cmd_run`
|
||||
NOTE: `@cmd_parse` should be after `@cmd_run`.
|
||||
|
||||
## Calling a command from inside another
|
||||
## Calling a command from another one
|
||||
|
||||
If you need to call `podman-compose down` from inside `podman-compose up`
|
||||
do something like:
|
||||
If you need to call `podman-compose down` from `podman-compose up`, do something like:
|
||||
|
||||
```
|
||||
```python
|
||||
@cmd_run(podman_compose, 'up', 'up desc')
|
||||
def compose_up(compose, args):
|
||||
compose.commands['down'](compose, args)
|
||||
async def compose_up(compose, args):
|
||||
await compose.commands['down'](compose, args)
|
||||
# or
|
||||
compose.commands['down'](argparse.Namespace(foo=123))
|
||||
await compose.commands['down'](argparse.Namespace(foo=123))
|
||||
```
|
||||
|
||||
|
||||
## Missing Commands (help needed)
|
||||
|
||||
```
|
||||
bundle Generate a Docker bundle from the Compose file
|
||||
config Validate and view the Compose file
|
||||
create Create services
|
||||
events Receive real time events from containers
|
||||
images List images
|
||||
logs View output from containers
|
||||
port Print the public port for a port binding
|
||||
ps List containers
|
||||
rm Remove stopped containers
|
||||
run Run a one-off command
|
||||
scale Set number of containers for a service
|
||||
top Display the running processes
|
||||
```
|
||||
|
47
README.md
47
README.md
@ -1,6 +1,5 @@
|
||||
# Podman Compose
|
||||
## [![Pylint Test: ](https://github.com/containers/podman-compose/actions/workflows/pylint.yml/badge.svg)](https://github.com/containers/podman-compose/actions/workflows/pylint.yml) [![Unit tests PyTest](https://github.com/containers/podman-compose/actions/workflows/pytest.yml/badge.svg)](https://github.com/containers/podman-compose/actions/workflows/pytest.yml)
|
||||
|
||||
## [![Tests](https://github.com/containers/podman-compose/actions/workflows/test.yml/badge.svg)](https://github.com/containers/podman-compose/actions/workflows/test.yml)
|
||||
|
||||
An implementation of [Compose Spec](https://compose-spec.io/) with [Podman](https://podman.io/) backend.
|
||||
This project focuses on:
|
||||
@ -11,7 +10,11 @@ This project focuses on:
|
||||
This project only depends on:
|
||||
|
||||
* `podman`
|
||||
* [podman dnsname plugin](https://github.com/containers/dnsname): It is usually found in the `podman-plugins` or `podman-dnsname` distro packages, those packages are not pulled by default and you need to install them. This allows containers to be able to resolve each other if they are on the same CNI network.
|
||||
* [podman dnsname plugin](https://github.com/containers/dnsname): It is usually found in
|
||||
the `podman-plugins` or `podman-dnsname` distro packages, those packages are not pulled
|
||||
by default and you need to install them. This allows containers to be able to resolve
|
||||
each other if they are on the same CNI network. This is not necessary when podman is using
|
||||
netavark as a network backend.
|
||||
* Python3
|
||||
* [PyYAML](https://pyyaml.org/)
|
||||
* [python-dotenv](https://pypi.org/project/python-dotenv/)
|
||||
@ -49,9 +52,11 @@ like `hostnet`. If you desire that behavior, pass it the standard way like `netw
|
||||
|
||||
## Installation
|
||||
|
||||
### Pip
|
||||
|
||||
Install the latest stable version from PyPI:
|
||||
|
||||
```
|
||||
```bash
|
||||
pip3 install podman-compose
|
||||
```
|
||||
|
||||
@ -59,14 +64,33 @@ pass `--user` to install inside regular user home without being root.
|
||||
|
||||
Or latest development version from GitHub:
|
||||
|
||||
```
|
||||
pip3 install https://github.com/containers/podman-compose/archive/devel.tar.gz
|
||||
```bash
|
||||
pip3 install https://github.com/containers/podman-compose/archive/main.tar.gz
|
||||
```
|
||||
|
||||
### Homebrew
|
||||
|
||||
```bash
|
||||
brew install podman-compose
|
||||
```
|
||||
|
||||
### Manual
|
||||
|
||||
```bash
|
||||
curl -o /usr/local/bin/podman-compose https://raw.githubusercontent.com/containers/podman-compose/main/podman_compose.py
|
||||
chmod +x /usr/local/bin/podman-compose
|
||||
```
|
||||
|
||||
or inside your home
|
||||
|
||||
```bash
|
||||
curl -o ~/.local/bin/podman-compose https://raw.githubusercontent.com/containers/podman-compose/main/podman_compose.py
|
||||
chmod +x ~/.local/bin/podman-compose
|
||||
```
|
||||
|
||||
or install from Fedora (starting from f31) repositories:
|
||||
|
||||
```
|
||||
```bash
|
||||
sudo dnf install podman-compose
|
||||
```
|
||||
|
||||
@ -75,10 +99,9 @@ sudo dnf install podman-compose
|
||||
We have included fully functional sample stacks inside `examples/` directory.
|
||||
You can get more examples from [awesome-compose](https://github.com/docker/awesome-compose).
|
||||
|
||||
|
||||
A quick example would be
|
||||
|
||||
```
|
||||
```bash
|
||||
cd examples/busybox
|
||||
podman-compose --help
|
||||
podman-compose up --help
|
||||
@ -103,11 +126,11 @@ There is also AWX 17.1.0
|
||||
Inside `tests/` directory we have many useless docker-compose stacks
|
||||
that are meant to test as many cases as we can to make sure we are compatible
|
||||
|
||||
### Unit tests with pytest
|
||||
run a pytest with following command
|
||||
### Unit tests with unittest
|
||||
run a unittest with following command
|
||||
|
||||
```shell
|
||||
python -m pytest pytests
|
||||
python3 -m unittest discover tests/unit
|
||||
```
|
||||
|
||||
# Contributing guide
|
||||
|
33
docs/Changelog-1.1.0.md
Normal file
33
docs/Changelog-1.1.0.md
Normal file
@ -0,0 +1,33 @@
|
||||
Version v1.1.0 (2024-04-17)
|
||||
===========================
|
||||
|
||||
Bug fixes
|
||||
---------
|
||||
|
||||
- Fixed support for values with equals sign in `-e` argument of `run` and `exec` commands.
|
||||
- Fixed duplicate arguments being emitted in `stop` and `restart` commands.
|
||||
- Removed extraneous debug output. `--verbose` flag has been added to preserve verbose output.
|
||||
- Links aliases are now added to service aliases.
|
||||
- Fixed image build process to use defined environmental variables.
|
||||
- Empty list is now allowed to be `COMMAND` and `ENTRYPOINT`.
|
||||
- Environment files are now resolved relative to current working directory.
|
||||
- Exit code of container build is now preserved as return code of `build` command.
|
||||
|
||||
New features
|
||||
------------
|
||||
|
||||
- Added support for `uidmap`, `gidmap`, `http_proxy` and `runtime` service configuration keys.
|
||||
- Added support for `enable_ipv6` network configuration key.
|
||||
- Added `--parallel` option to support parallel pulling and building of images.
|
||||
- Implemented support for maps in `sysctls` container configuration key.
|
||||
- Implemented `stats` command.
|
||||
- Added `--no-normalize` flag to `config` command.
|
||||
- Added support for `include` global configuration key.
|
||||
- Added support for `build` command.
|
||||
- Added support to start containers with multiple networks.
|
||||
- Added support for `profile` argument.
|
||||
- Added support for starting podman in existing network namespace.
|
||||
- Added IPAM driver support.
|
||||
- Added support for file secrets being passed to `podman build` via `--secret` argument.
|
||||
- Added support for multiple networks with separately specified IP and MAC address.
|
||||
- Added support for `service.build.ulimits` when building image.
|
40
docs/Changelog-1.2.0.md
Normal file
40
docs/Changelog-1.2.0.md
Normal file
@ -0,0 +1,40 @@
|
||||
Version v1.2.0 (2024-06-26)
|
||||
===========================
|
||||
|
||||
Bug fixes
|
||||
---------
|
||||
|
||||
- Fixed handling of `--in-pod` argument. Previously it was hard to provide false value to it.
|
||||
- podman-compose no longer creates pods when registering systemd unit.
|
||||
- Fixed warning `RuntimeWarning: coroutine 'create_pods' was never awaited`
|
||||
- Fixed error when setting up IPAM network with default driver.
|
||||
- Fixed support for having list and dictionary `depends_on` sections in related compose files.
|
||||
- Fixed logging of failed build message.
|
||||
- Fixed support for multiple entries in `include` section.
|
||||
- Fixed environment variable precedence order.
|
||||
|
||||
Changes
|
||||
-------
|
||||
|
||||
- `x-podman` dictionary in container root has been migrated to `x-podman.*` fields in container root.
|
||||
|
||||
New features
|
||||
------------
|
||||
|
||||
- Added support for `--publish` in `podman-compose run`.
|
||||
- Added support for Podman external root filesystem management (`--rootfs` option).
|
||||
- Added support for `podman-compose images` command.
|
||||
- Added support for `env_file` being configured via dictionaries.
|
||||
- Added support for enabling GPU access.
|
||||
- Added support for selinux in verbose mount specification.
|
||||
- Added support for `additional_contexts` section.
|
||||
- Added support for multi-line environment files.
|
||||
- Added support for passing contents of `podman-compose.yml` via stdin.
|
||||
- Added support for specifying the value for `--in-pod` setting in `podman-compose.yml` file.
|
||||
- Added support for environmental secrets.
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
- Added instructions on how to install podman-compose on Homebrew.
|
||||
- Added explanation that netavark is an alternative to dnsname plugin
|
128
docs/Extensions.md
Normal file
128
docs/Extensions.md
Normal file
@ -0,0 +1,128 @@
|
||||
# Podman specific extensions to the docker-compose format
|
||||
|
||||
Podman-compose supports the following extension to the docker-compose format. These extensions
|
||||
are generally specified under fields with "x-podman" prefix in the compose file.
|
||||
|
||||
## Container management
|
||||
|
||||
The following extension keys are available under container configuration:
|
||||
|
||||
* `x-podman.uidmaps` - Run the container in a new user namespace using the supplied UID mapping.
|
||||
|
||||
* `x-podman.gidmaps` - Run the container in a new user namespace using the supplied GID mapping.
|
||||
|
||||
* `x-podman.rootfs` - Run the container without requiring any image management; the rootfs of the
|
||||
container is assumed to be managed externally.
|
||||
|
||||
For example, the following docker-compose.yml allows running a podman container with externally managed rootfs.
|
||||
```yml
|
||||
version: "3"
|
||||
services:
|
||||
my_service:
|
||||
command: ["/bin/busybox"]
|
||||
x-podman.rootfs: "/path/to/rootfs"
|
||||
```
|
||||
|
||||
For explanations of these extensions, please refer to the [Podman Documentation](https://docs.podman.io/).
|
||||
|
||||
|
||||
## Per-network MAC-addresses
|
||||
|
||||
Generic docker-compose files support specification of the MAC address on the container level. If the
|
||||
container has multiple network interfaces, the specified MAC address is applied to the first
|
||||
specified network.
|
||||
|
||||
Podman-compose in addition supports the specification of MAC addresses on a per-network basis. This
|
||||
is done by adding a `x-podman.mac_address` key to the network configuration in the container. The
|
||||
value of the `x-podman.mac_address` key is the MAC address to be used for the network interface.
|
||||
|
||||
Specifying a MAC address for the container and for individual networks at the same time is not
|
||||
supported.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
---
|
||||
version: "3"
|
||||
|
||||
networks:
|
||||
net0:
|
||||
driver: "bridge"
|
||||
ipam:
|
||||
config:
|
||||
- subnet: "192.168.0.0/24"
|
||||
net1:
|
||||
driver: "bridge"
|
||||
ipam:
|
||||
config:
|
||||
- subnet: "192.168.1.0/24"
|
||||
|
||||
services:
|
||||
webserver
|
||||
image: "busybox"
|
||||
command: ["/bin/busybox", "httpd", "-f", "-h", "/etc", "-p", "8001"]
|
||||
networks:
|
||||
net0:
|
||||
ipv4_address: "192.168.0.10"
|
||||
x-podman.mac_address: "02:aa:aa:aa:aa:aa"
|
||||
net1:
|
||||
ipv4_address: "192.168.1.10"
|
||||
x-podman.mac_address: "02:bb:bb:bb:bb:bb"
|
||||
```
|
||||
|
||||
## Podman-specific network modes
|
||||
|
||||
Generic docker-compose supports the following values for `network-mode` for a container:
|
||||
|
||||
- `bridge`
|
||||
- `host`
|
||||
- `none`
|
||||
- `service`
|
||||
- `container`
|
||||
|
||||
In addition, podman-compose supports the following podman-specific values for `network-mode`:
|
||||
|
||||
- `slirp4netns[:<options>,...]`
|
||||
- `ns:<options>`
|
||||
- `pasta[:<options>,...]`
|
||||
- `private`
|
||||
|
||||
The options to the network modes are passed to the `--network` option of the `podman create` command
|
||||
as-is.
|
||||
|
||||
|
||||
## Compatibility of default network names between docker-compose and podman-compose
|
||||
|
||||
Current versions of podman-compose may produce different default external network names than
|
||||
docker-compose under certain conditions. Specifically, docker-compose removes dashes (`-` character)
|
||||
from project name.
|
||||
|
||||
To enable compatibility between docker-compose and podman-compose, specify
|
||||
`default_net_name_compat: true` under global `x-podman` key:
|
||||
|
||||
```
|
||||
x-podman:
|
||||
default_net_name_compat: true
|
||||
```
|
||||
|
||||
By default `default_net_name_compat` is `false`. This will change to `true` at some point and the
|
||||
setting will be removed.
|
||||
|
||||
## Custom pods management
|
||||
|
||||
Podman-compose can have containers in pods. This can be controlled by extension key x-podman in_pod.
|
||||
It allows providing custom value for --in-pod and is especially relevant when --userns has to be set.
|
||||
|
||||
For example, the following docker-compose.yml allows using userns_mode by overriding the default
|
||||
value of --in-pod (unless it was specifically provided by "--in-pod=True" in command line interface).
|
||||
```yml
|
||||
version: "3"
|
||||
services:
|
||||
cont:
|
||||
image: nopush/podman-compose-test
|
||||
userns_mode: keep-id:uid=1000
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-p", "8080"]
|
||||
|
||||
x-podman:
|
||||
in_pod: false
|
||||
```
|
@ -1,7 +1,7 @@
|
||||
# pylint: disable=import-error
|
||||
# pylint: disable=unused-import
|
||||
import os
|
||||
import asyncio # noqa: F401
|
||||
import os
|
||||
|
||||
import aioredis
|
||||
from aiohttp import web
|
||||
|
11
examples/nvidia-smi/docker-compose.yaml
Normal file
11
examples/nvidia-smi/docker-compose.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
services:
|
||||
test:
|
||||
image: nvidia/cuda:12.3.1-base-ubuntu20.04
|
||||
command: nvidia-smi
|
||||
deploy:
|
||||
resources:
|
||||
reservations:
|
||||
devices:
|
||||
- driver: nvidia
|
||||
count: 1
|
||||
capabilities: [gpu]
|
1
newsfragments/978.bugfix
Normal file
1
newsfragments/978.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fixed support for de-facto alternative `Dockerfile` names (e.g. `Containerfile`)
|
13
newsfragments/README.txt
Normal file
13
newsfragments/README.txt
Normal file
@ -0,0 +1,13 @@
|
||||
This is the directory for news fragments used by towncrier: https://github.com/hawkowl/towncrier
|
||||
|
||||
You create a news fragment in this directory when you make a change, and the file gets removed from
|
||||
this directory when the news is published.
|
||||
|
||||
towncrier has a few standard types of news fragments, signified by the file extension. These are:
|
||||
|
||||
.feature: Signifying a new feature.
|
||||
.bugfix: Signifying a bug fix.
|
||||
.doc: Signifying a documentation improvement.
|
||||
.removal: Signifying a deprecation or removal of public API.
|
||||
.change: Signifying a change of behavior
|
||||
.misc: Miscellaneous change
|
1
newsfragments/build-labels.feature
Normal file
1
newsfragments/build-labels.feature
Normal file
@ -0,0 +1 @@
|
||||
Added support for build labels.
|
1
newsfragments/check-if-pod-exists.bugfix
Normal file
1
newsfragments/check-if-pod-exists.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fixed a bug that caused attempts to create already existing pods multiple times.
|
1
newsfragments/default_net_name_compat.feature
Normal file
1
newsfragments/default_net_name_compat.feature
Normal file
@ -0,0 +1 @@
|
||||
Added a way to get compatibility of default network names with docker compose. This is selected by setting `default_net_name_compat: true` on `x-podman` global dictionary.
|
1
newsfragments/dont-resolve-links-to-compose-file.bugfix
Normal file
1
newsfragments/dont-resolve-links-to-compose-file.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fix compatibility with docker-compose in how symlinks to docker-compose.yml are handled.
|
1
newsfragments/network-mode-none.bugfix
Normal file
1
newsfragments/network-mode-none.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fix support for `network_mode: none`.
|
1627
podman_compose.py
1627
podman_compose.py
File diff suppressed because it is too large
Load Diff
15
pyproject.toml
Normal file
15
pyproject.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[tool.ruff]
|
||||
line-length = 100
|
||||
target-version = "py38"
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = ["W", "E", "F", "I"]
|
||||
ignore = [
|
||||
]
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
force-single-line = true
|
||||
|
||||
[tool.ruff.format]
|
||||
preview = true # needed for quote-style
|
||||
quote-style = "preserve"
|
@ -1,168 +0,0 @@
|
||||
import copy
|
||||
import os
|
||||
import argparse
|
||||
import yaml
|
||||
from podman_compose import normalize_service, PodmanCompose
|
||||
|
||||
|
||||
test_cases_simple = [
|
||||
({"test": "test"}, {"test": "test"}),
|
||||
({"build": "."}, {"build": {"context": "."}}),
|
||||
({"build": "./dir-1"}, {"build": {"context": "./dir-1"}}),
|
||||
({"build": {"context": "./dir-1"}}, {"build": {"context": "./dir-1"}}),
|
||||
(
|
||||
{"build": {"dockerfile": "dockerfile-1"}},
|
||||
{"build": {"dockerfile": "dockerfile-1"}},
|
||||
),
|
||||
(
|
||||
{"build": {"context": "./dir-1", "dockerfile": "dockerfile-1"}},
|
||||
{"build": {"context": "./dir-1", "dockerfile": "dockerfile-1"}},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def test_normalize_service_simple():
|
||||
for test_case, expected in copy.deepcopy(test_cases_simple):
|
||||
test_original = copy.deepcopy(test_case)
|
||||
test_case = normalize_service(test_case)
|
||||
test_result = expected == test_case
|
||||
if not test_result:
|
||||
print("test: ", test_original)
|
||||
print("expected: ", expected)
|
||||
print("actual: ", test_case)
|
||||
assert test_result
|
||||
|
||||
|
||||
test_cases_sub_dir = [
|
||||
({"test": "test"}, {"test": "test"}),
|
||||
({"build": "."}, {"build": {"context": "./sub_dir/."}}),
|
||||
({"build": "./dir-1"}, {"build": {"context": "./sub_dir/dir-1"}}),
|
||||
({"build": {"context": "./dir-1"}}, {"build": {"context": "./sub_dir/dir-1"}}),
|
||||
(
|
||||
{"build": {"dockerfile": "dockerfile-1"}},
|
||||
{"build": {"context": "./sub_dir", "dockerfile": "dockerfile-1"}},
|
||||
),
|
||||
(
|
||||
{"build": {"context": "./dir-1", "dockerfile": "dockerfile-1"}},
|
||||
{"build": {"context": "./sub_dir/dir-1", "dockerfile": "dockerfile-1"}},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def test_normalize_service_with_sub_dir():
|
||||
for test_case, expected in copy.deepcopy(test_cases_sub_dir):
|
||||
test_original = copy.deepcopy(test_case)
|
||||
test_case = normalize_service(test_case, sub_dir="./sub_dir")
|
||||
test_result = expected == test_case
|
||||
if not test_result:
|
||||
print("test: ", test_original)
|
||||
print("expected: ", expected)
|
||||
print("actual: ", test_case)
|
||||
assert test_result
|
||||
|
||||
|
||||
test_cases_merges = [
|
||||
({}, {}, {}),
|
||||
({}, {"test": "test"}, {"test": "test"}),
|
||||
({"test": "test"}, {}, {"test": "test"}),
|
||||
({"test": "test-1"}, {"test": "test-2"}, {"test": "test-2"}),
|
||||
({}, {"build": "."}, {"build": {"context": "."}}),
|
||||
({"build": "."}, {}, {"build": {"context": "."}}),
|
||||
({"build": "./dir-1"}, {"build": "./dir-2"}, {"build": {"context": "./dir-2"}}),
|
||||
({}, {"build": {"context": "./dir-1"}}, {"build": {"context": "./dir-1"}}),
|
||||
({"build": {"context": "./dir-1"}}, {}, {"build": {"context": "./dir-1"}}),
|
||||
(
|
||||
{"build": {"context": "./dir-1"}},
|
||||
{"build": {"context": "./dir-2"}},
|
||||
{"build": {"context": "./dir-2"}},
|
||||
),
|
||||
(
|
||||
{},
|
||||
{"build": {"dockerfile": "dockerfile-1"}},
|
||||
{"build": {"dockerfile": "dockerfile-1"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "dockerfile-1"}},
|
||||
{},
|
||||
{"build": {"dockerfile": "dockerfile-1"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./dockerfile-1"}},
|
||||
{"build": {"dockerfile": "./dockerfile-2"}},
|
||||
{"build": {"dockerfile": "./dockerfile-2"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./dockerfile-1"}},
|
||||
{"build": {"context": "./dir-2"}},
|
||||
{"build": {"dockerfile": "./dockerfile-1", "context": "./dir-2"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./dockerfile-1", "context": "./dir-1"}},
|
||||
{"build": {"dockerfile": "./dockerfile-2", "context": "./dir-2"}},
|
||||
{"build": {"dockerfile": "./dockerfile-2", "context": "./dir-2"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./dockerfile-1"}},
|
||||
{"build": {"dockerfile": "./dockerfile-2", "args": ["ENV1=1"]}},
|
||||
{"build": {"dockerfile": "./dockerfile-2", "args": ["ENV1=1"]}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./dockerfile-2", "args": ["ENV1=1"]}},
|
||||
{"build": {"dockerfile": "./dockerfile-1"}},
|
||||
{"build": {"dockerfile": "./dockerfile-1", "args": ["ENV1=1"]}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./dockerfile-2", "args": ["ENV1=1"]}},
|
||||
{"build": {"dockerfile": "./dockerfile-1", "args": ["ENV2=2"]}},
|
||||
{"build": {"dockerfile": "./dockerfile-1", "args": ["ENV1=1", "ENV2=2"]}},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def test__parse_compose_file_when_multiple_composes() -> None:
|
||||
for test_input, test_override, expected_result in copy.deepcopy(test_cases_merges):
|
||||
compose_test_1 = {"services": {"test-service": test_input}}
|
||||
compose_test_2 = {"services": {"test-service": test_override}}
|
||||
dump_yaml(compose_test_1, "test-compose-1.yaml")
|
||||
dump_yaml(compose_test_2, "test-compose-2.yaml")
|
||||
|
||||
podman_compose = PodmanCompose()
|
||||
set_args(podman_compose, ["test-compose-1.yaml", "test-compose-2.yaml"])
|
||||
|
||||
podman_compose._parse_compose_file() # pylint: disable=protected-access
|
||||
|
||||
actual_compose = {}
|
||||
if podman_compose.services:
|
||||
podman_compose.services["test-service"].pop("_deps")
|
||||
actual_compose = podman_compose.services["test-service"]
|
||||
if actual_compose != expected_result:
|
||||
print("compose: ", test_input)
|
||||
print("override: ", test_override)
|
||||
print("expected: ", expected_result)
|
||||
print("actual: ", actual_compose)
|
||||
|
||||
compose_expected = expected_result
|
||||
|
||||
assert compose_expected == actual_compose
|
||||
|
||||
|
||||
def set_args(podman_compose: PodmanCompose, file_names: list[str]) -> None:
|
||||
podman_compose.global_args = argparse.Namespace()
|
||||
podman_compose.global_args.file = file_names
|
||||
podman_compose.global_args.project_name = None
|
||||
podman_compose.global_args.env_file = None
|
||||
podman_compose.global_args.profile = []
|
||||
podman_compose.global_args.in_pod = True
|
||||
podman_compose.global_args.no_normalize = True
|
||||
|
||||
|
||||
def dump_yaml(compose: dict, name: str) -> None:
|
||||
with open(name, "w", encoding="utf-8") as outfile:
|
||||
yaml.safe_dump(compose, outfile, default_flow_style=False)
|
||||
|
||||
|
||||
def test_clean_test_yamls() -> None:
|
||||
test_files = ["test-compose-1.yaml", "test-compose-2.yaml"]
|
||||
for file in test_files:
|
||||
if os.path.exists(file):
|
||||
os.remove(file)
|
@ -1,122 +0,0 @@
|
||||
import copy
|
||||
import os
|
||||
import argparse
|
||||
import yaml
|
||||
from podman_compose import normalize_service, PodmanCompose
|
||||
|
||||
test_keys = ["command", "entrypoint"]
|
||||
|
||||
test_cases_normalise_pre_merge = [
|
||||
({"$$$": []}, {"$$$": []}),
|
||||
({"$$$": ["sh"]}, {"$$$": ["sh"]}),
|
||||
({"$$$": ["sh", "-c", "date"]}, {"$$$": ["sh", "-c", "date"]}),
|
||||
({"$$$": "sh"}, {"$$$": ["sh"]}),
|
||||
({"$$$": "sleep infinity"}, {"$$$": ["sleep", "infinity"]}),
|
||||
(
|
||||
{"$$$": "bash -c 'sleep infinity'"},
|
||||
{"$$$": ["bash", "-c", "sleep infinity"]},
|
||||
),
|
||||
]
|
||||
|
||||
test_cases_merges = [
|
||||
({}, {"$$$": []}, {"$$$": []}),
|
||||
({"$$$": []}, {}, {"$$$": []}),
|
||||
({"$$$": []}, {"$$$": "sh-2"}, {"$$$": ["sh-2"]}),
|
||||
({"$$$": "sh-2"}, {"$$$": []}, {"$$$": []}),
|
||||
({}, {"$$$": "sh"}, {"$$$": ["sh"]}),
|
||||
({"$$$": "sh"}, {}, {"$$$": ["sh"]}),
|
||||
({"$$$": "sh-1"}, {"$$$": "sh-2"}, {"$$$": ["sh-2"]}),
|
||||
({"$$$": ["sh-1"]}, {"$$$": "sh-2"}, {"$$$": ["sh-2"]}),
|
||||
({"$$$": "sh-1"}, {"$$$": ["sh-2"]}, {"$$$": ["sh-2"]}),
|
||||
({"$$$": "sh-1"}, {"$$$": ["sh-2", "sh-3"]}, {"$$$": ["sh-2", "sh-3"]}),
|
||||
({"$$$": ["sh-1"]}, {"$$$": ["sh-2", "sh-3"]}, {"$$$": ["sh-2", "sh-3"]}),
|
||||
({"$$$": ["sh-1", "sh-2"]}, {"$$$": ["sh-3", "sh-4"]}, {"$$$": ["sh-3", "sh-4"]}),
|
||||
({}, {"$$$": ["sh-3", "sh 4"]}, {"$$$": ["sh-3", "sh 4"]}),
|
||||
({"$$$": "sleep infinity"}, {"$$$": "sh"}, {"$$$": ["sh"]}),
|
||||
({"$$$": "sh"}, {"$$$": "sleep infinity"}, {"$$$": ["sleep", "infinity"]}),
|
||||
(
|
||||
{},
|
||||
{"$$$": "bash -c 'sleep infinity'"},
|
||||
{"$$$": ["bash", "-c", "sleep infinity"]},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def template_to_expression(base, override, expected, key):
|
||||
base_copy = copy.deepcopy(base)
|
||||
override_copy = copy.deepcopy(override)
|
||||
expected_copy = copy.deepcopy(expected)
|
||||
|
||||
expected_copy[key] = expected_copy.pop("$$$")
|
||||
if "$$$" in base:
|
||||
base_copy[key] = base_copy.pop("$$$")
|
||||
if "$$$" in override:
|
||||
override_copy[key] = override_copy.pop("$$$")
|
||||
return base_copy, override_copy, expected_copy
|
||||
|
||||
|
||||
def test_normalize_service():
|
||||
for test_input_template, expected_template in test_cases_normalise_pre_merge:
|
||||
for key in test_keys:
|
||||
test_input, _, expected = template_to_expression(
|
||||
test_input_template, {}, expected_template, key
|
||||
)
|
||||
test_input = normalize_service(test_input)
|
||||
test_result = expected == test_input
|
||||
if not test_result:
|
||||
print("base_template: ", test_input_template)
|
||||
print("expected: ", expected)
|
||||
print("actual: ", test_input)
|
||||
assert test_result
|
||||
|
||||
|
||||
def test__parse_compose_file_when_multiple_composes() -> None:
|
||||
for base_template, override_template, expected_template in copy.deepcopy(
|
||||
test_cases_merges
|
||||
):
|
||||
for key in test_keys:
|
||||
base, override, expected = template_to_expression(
|
||||
base_template, override_template, expected_template, key
|
||||
)
|
||||
compose_test_1 = {"services": {"test-service": base}}
|
||||
compose_test_2 = {"services": {"test-service": override}}
|
||||
dump_yaml(compose_test_1, "test-compose-1.yaml")
|
||||
dump_yaml(compose_test_2, "test-compose-2.yaml")
|
||||
|
||||
podman_compose = PodmanCompose()
|
||||
set_args(podman_compose, ["test-compose-1.yaml", "test-compose-2.yaml"])
|
||||
|
||||
podman_compose._parse_compose_file() # pylint: disable=protected-access
|
||||
|
||||
actual = {}
|
||||
if podman_compose.services:
|
||||
podman_compose.services["test-service"].pop("_deps")
|
||||
actual = podman_compose.services["test-service"]
|
||||
if actual != expected:
|
||||
print("compose: ", base)
|
||||
print("override: ", override)
|
||||
print("result: ", expected)
|
||||
|
||||
assert expected == actual
|
||||
|
||||
|
||||
def set_args(podman_compose: PodmanCompose, file_names: list[str]) -> None:
|
||||
podman_compose.global_args = argparse.Namespace()
|
||||
podman_compose.global_args.file = file_names
|
||||
podman_compose.global_args.project_name = None
|
||||
podman_compose.global_args.env_file = None
|
||||
podman_compose.global_args.profile = []
|
||||
podman_compose.global_args.in_pod = True
|
||||
podman_compose.global_args.no_normalize = None
|
||||
|
||||
|
||||
def dump_yaml(compose: dict, name: str) -> None:
|
||||
with open(name, "w", encoding="utf-8") as outfile:
|
||||
yaml.safe_dump(compose, outfile, default_flow_style=False)
|
||||
|
||||
|
||||
def test_clean_test_yamls() -> None:
|
||||
test_files = ["test-compose-1.yaml", "test-compose-2.yaml"]
|
||||
for file in test_files:
|
||||
if os.path.exists(file):
|
||||
os.remove(file)
|
@ -1,298 +0,0 @@
|
||||
# pylint: disable=protected-access
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import os
|
||||
import yaml
|
||||
from podman_compose import (
|
||||
normalize_service,
|
||||
normalize,
|
||||
normalize_final,
|
||||
normalize_service_final,
|
||||
PodmanCompose,
|
||||
)
|
||||
|
||||
cwd = os.path.abspath(".")
|
||||
test_cases_simple_normalization = [
|
||||
({"image": "test-image"}, {"image": "test-image"}),
|
||||
(
|
||||
{"build": "."},
|
||||
{
|
||||
"build": {"context": cwd, "dockerfile": "Dockerfile"},
|
||||
},
|
||||
),
|
||||
(
|
||||
{"build": "../relative"},
|
||||
{
|
||||
"build": {
|
||||
"context": os.path.normpath(os.path.join(cwd, "../relative")),
|
||||
"dockerfile": "Dockerfile",
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
{"build": "./relative"},
|
||||
{
|
||||
"build": {
|
||||
"context": os.path.normpath(os.path.join(cwd, "./relative")),
|
||||
"dockerfile": "Dockerfile",
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
{"build": "/workspace/absolute"},
|
||||
{
|
||||
"build": {
|
||||
"context": "/workspace/absolute",
|
||||
"dockerfile": "Dockerfile",
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
},
|
||||
},
|
||||
{
|
||||
"build": {
|
||||
"context": cwd,
|
||||
"dockerfile": "Dockerfile",
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"build": {
|
||||
"context": ".",
|
||||
},
|
||||
},
|
||||
{
|
||||
"build": {
|
||||
"context": cwd,
|
||||
"dockerfile": "Dockerfile",
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"build": {"context": "../", "dockerfile": "test-dockerfile"},
|
||||
},
|
||||
{
|
||||
"build": {
|
||||
"context": os.path.normpath(os.path.join(cwd, "../")),
|
||||
"dockerfile": "test-dockerfile",
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"build": {"context": ".", "dockerfile": "./dev/test-dockerfile"},
|
||||
},
|
||||
{
|
||||
"build": {
|
||||
"context": cwd,
|
||||
"dockerfile": "./dev/test-dockerfile",
|
||||
},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
#
|
||||
# [service.build] is normalised after merges
|
||||
#
|
||||
def test_normalize_service_final_returns_absolute_path_in_context() -> None:
|
||||
project_dir = cwd
|
||||
for test_input, expected_service in copy.deepcopy(test_cases_simple_normalization):
|
||||
actual_service = normalize_service_final(test_input, project_dir)
|
||||
assert expected_service == actual_service
|
||||
|
||||
|
||||
def test_normalize_returns_absolute_path_in_context() -> None:
|
||||
project_dir = cwd
|
||||
for test_input, expected_result in copy.deepcopy(test_cases_simple_normalization):
|
||||
compose_test = {"services": {"test-service": test_input}}
|
||||
compose_expected = {"services": {"test-service": expected_result}}
|
||||
actual_compose = normalize_final(compose_test, project_dir)
|
||||
assert compose_expected == actual_compose
|
||||
|
||||
|
||||
#
|
||||
# running full parse over single compose files
|
||||
#
|
||||
def test__parse_compose_file_when_single_compose() -> None:
|
||||
for test_input, expected_result in copy.deepcopy(test_cases_simple_normalization):
|
||||
compose_test = {"services": {"test-service": test_input}}
|
||||
dump_yaml(compose_test, "test-compose.yaml")
|
||||
|
||||
podman_compose = PodmanCompose()
|
||||
set_args(podman_compose, ["test-compose.yaml"], no_normalize=None)
|
||||
|
||||
podman_compose._parse_compose_file()
|
||||
|
||||
actual_compose = {}
|
||||
if podman_compose.services:
|
||||
podman_compose.services["test-service"].pop("_deps")
|
||||
actual_compose = podman_compose.services["test-service"]
|
||||
if actual_compose != expected_result:
|
||||
print("compose: ", test_input)
|
||||
print("result: ", expected_result)
|
||||
|
||||
assert expected_result == actual_compose
|
||||
|
||||
|
||||
test_cases_with_merges = [
|
||||
(
|
||||
{},
|
||||
{"build": "."},
|
||||
{"build": {"context": cwd, "dockerfile": "Dockerfile"}},
|
||||
),
|
||||
(
|
||||
{"build": "."},
|
||||
{},
|
||||
{"build": {"context": cwd, "dockerfile": "Dockerfile"}},
|
||||
),
|
||||
(
|
||||
{"build": "/workspace/absolute"},
|
||||
{"build": "./relative"},
|
||||
{
|
||||
"build": {
|
||||
"context": os.path.normpath(os.path.join(cwd, "./relative")),
|
||||
"dockerfile": "Dockerfile",
|
||||
}
|
||||
},
|
||||
),
|
||||
(
|
||||
{"build": "./relative"},
|
||||
{"build": "/workspace/absolute"},
|
||||
{"build": {"context": "/workspace/absolute", "dockerfile": "Dockerfile"}},
|
||||
),
|
||||
(
|
||||
{"build": "./relative"},
|
||||
{"build": "/workspace/absolute"},
|
||||
{"build": {"context": "/workspace/absolute", "dockerfile": "Dockerfile"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "test-dockerfile"}},
|
||||
{},
|
||||
{"build": {"context": cwd, "dockerfile": "test-dockerfile"}},
|
||||
),
|
||||
(
|
||||
{},
|
||||
{"build": {"dockerfile": "test-dockerfile"}},
|
||||
{"build": {"context": cwd, "dockerfile": "test-dockerfile"}},
|
||||
),
|
||||
(
|
||||
{},
|
||||
{"build": {"dockerfile": "test-dockerfile"}},
|
||||
{"build": {"context": cwd, "dockerfile": "test-dockerfile"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "test-dockerfile-1"}},
|
||||
{"build": {"dockerfile": "test-dockerfile-2"}},
|
||||
{"build": {"context": cwd, "dockerfile": "test-dockerfile-2"}},
|
||||
),
|
||||
(
|
||||
{"build": "/workspace/absolute"},
|
||||
{"build": {"dockerfile": "test-dockerfile"}},
|
||||
{"build": {"context": "/workspace/absolute", "dockerfile": "test-dockerfile"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "test-dockerfile"}},
|
||||
{"build": "/workspace/absolute"},
|
||||
{"build": {"context": "/workspace/absolute", "dockerfile": "test-dockerfile"}},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./test-dockerfile-1"}},
|
||||
{"build": {"dockerfile": "./test-dockerfile-2", "args": ["ENV1=1"]}},
|
||||
{
|
||||
"build": {
|
||||
"context": cwd,
|
||||
"dockerfile": "./test-dockerfile-2",
|
||||
"args": ["ENV1=1"],
|
||||
}
|
||||
},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./test-dockerfile-1", "args": ["ENV1=1"]}},
|
||||
{"build": {"dockerfile": "./test-dockerfile-2"}},
|
||||
{
|
||||
"build": {
|
||||
"context": cwd,
|
||||
"dockerfile": "./test-dockerfile-2",
|
||||
"args": ["ENV1=1"],
|
||||
}
|
||||
},
|
||||
),
|
||||
(
|
||||
{"build": {"dockerfile": "./test-dockerfile-1", "args": ["ENV1=1"]}},
|
||||
{"build": {"dockerfile": "./test-dockerfile-2", "args": ["ENV2=2"]}},
|
||||
{
|
||||
"build": {
|
||||
"context": cwd,
|
||||
"dockerfile": "./test-dockerfile-2",
|
||||
"args": ["ENV1=1", "ENV2=2"],
|
||||
}
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
#
|
||||
# running full parse over merged
|
||||
#
|
||||
def test__parse_compose_file_when_multiple_composes() -> None:
|
||||
for test_input, test_override, expected_result in copy.deepcopy(
|
||||
test_cases_with_merges
|
||||
):
|
||||
compose_test_1 = {"services": {"test-service": test_input}}
|
||||
compose_test_2 = {"services": {"test-service": test_override}}
|
||||
dump_yaml(compose_test_1, "test-compose-1.yaml")
|
||||
dump_yaml(compose_test_2, "test-compose-2.yaml")
|
||||
|
||||
podman_compose = PodmanCompose()
|
||||
set_args(
|
||||
podman_compose,
|
||||
["test-compose-1.yaml", "test-compose-2.yaml"],
|
||||
no_normalize=None,
|
||||
)
|
||||
|
||||
podman_compose._parse_compose_file()
|
||||
|
||||
actual_compose = {}
|
||||
if podman_compose.services:
|
||||
podman_compose.services["test-service"].pop("_deps")
|
||||
actual_compose = podman_compose.services["test-service"]
|
||||
if actual_compose != expected_result:
|
||||
print("compose: ", test_input)
|
||||
print("override: ", test_override)
|
||||
print("result: ", expected_result)
|
||||
compose_expected = expected_result
|
||||
|
||||
assert compose_expected == actual_compose
|
||||
|
||||
|
||||
def set_args(
|
||||
podman_compose: PodmanCompose, file_names: list[str], no_normalize: bool
|
||||
) -> None:
|
||||
podman_compose.global_args = argparse.Namespace()
|
||||
podman_compose.global_args.file = file_names
|
||||
podman_compose.global_args.project_name = None
|
||||
podman_compose.global_args.env_file = None
|
||||
podman_compose.global_args.profile = []
|
||||
podman_compose.global_args.in_pod = True
|
||||
podman_compose.global_args.no_normalize = no_normalize
|
||||
|
||||
|
||||
def dump_yaml(compose: dict, name: str) -> None:
|
||||
# Path(Path.cwd()/"subdirectory").mkdir(parents=True, exist_ok=True)
|
||||
with open(name, "w", encoding="utf-8") as outfile:
|
||||
yaml.safe_dump(compose, outfile, default_flow_style=False)
|
||||
|
||||
|
||||
def test_clean_test_yamls() -> None:
|
||||
test_files = ["test-compose-1.yaml", "test-compose-2.yaml", "test-compose.yaml"]
|
||||
for file in test_files:
|
||||
if os.path.exists(file):
|
||||
os.remove(file)
|
@ -1,21 +0,0 @@
|
||||
# pylint: disable=redefined-outer-name
|
||||
import pytest
|
||||
|
||||
from podman_compose import parse_short_mount
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def multi_propagation_mount_str():
|
||||
return "/foo/bar:/baz:U,Z"
|
||||
|
||||
|
||||
def test_parse_short_mount_multi_propagation(multi_propagation_mount_str):
|
||||
expected = {
|
||||
"type": "bind",
|
||||
"source": "/foo/bar",
|
||||
"target": "/baz",
|
||||
"bind": {
|
||||
"propagation": "U,Z",
|
||||
},
|
||||
}
|
||||
assert parse_short_mount(multi_propagation_mount_str, "/") == expected
|
18
setup.py
18
setup.py
@ -1,10 +1,11 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
import os
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
try:
|
||||
README = open(
|
||||
os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf-8"
|
||||
).read()
|
||||
README = open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf-8").read()
|
||||
except: # noqa: E722 # pylint: disable=bare-except
|
||||
README = ""
|
||||
|
||||
@ -39,19 +40,10 @@ setup(
|
||||
"pyyaml",
|
||||
"python-dotenv",
|
||||
],
|
||||
extras_require={
|
||||
"devel": [
|
||||
"flake8",
|
||||
"black",
|
||||
"pylint",
|
||||
"pre-commit",
|
||||
]
|
||||
}
|
||||
extras_require={"devel": ["ruff", "pre-commit", "coverage", "parameterized"]},
|
||||
# test_suite='tests',
|
||||
# tests_require=[
|
||||
# 'coverage',
|
||||
# 'pytest-cov',
|
||||
# 'pytest',
|
||||
# 'tox',
|
||||
# ]
|
||||
)
|
||||
|
@ -1,9 +1,34 @@
|
||||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
-e .
|
||||
coverage==7.4.3
|
||||
parameterized==0.9.0
|
||||
pytest==8.0.2
|
||||
tox==4.13.0
|
||||
ruff==0.3.1
|
||||
pylint==3.1.0
|
||||
|
||||
coverage
|
||||
pytest-cov
|
||||
pytest
|
||||
tox
|
||||
black
|
||||
# The packages below are transitive dependencies of the packages above and are included here
|
||||
# to make testing reproducible.
|
||||
# To refresh, create a new virtualenv and do:
|
||||
# pip install -r requirements.txt -r test-requirements.txt
|
||||
# pip freeze > test-requirements.txt
|
||||
# and edit test-requirements.txt to add this comment
|
||||
|
||||
astroid==3.1.0
|
||||
cachetools==5.3.3
|
||||
chardet==5.2.0
|
||||
colorama==0.4.6
|
||||
dill==0.3.8
|
||||
distlib==0.3.8
|
||||
filelock==3.13.1
|
||||
iniconfig==2.0.0
|
||||
isort==5.13.2
|
||||
mccabe==0.7.0
|
||||
packaging==23.2
|
||||
platformdirs==4.2.0
|
||||
pluggy==1.4.0
|
||||
pyproject-api==1.6.1
|
||||
python-dotenv==1.0.1
|
||||
PyYAML==6.0.1
|
||||
requests
|
||||
tomlkit==0.12.4
|
||||
virtualenv==20.25.1
|
||||
|
@ -1,25 +0,0 @@
|
||||
# Test podman-compose with build
|
||||
|
||||
```
|
||||
podman-compose build
|
||||
podman-compose up -d
|
||||
curl http://localhost:8080/index.txt
|
||||
curl http://localhost:8000/index.txt
|
||||
podman inspect my-busybox-httpd2
|
||||
podman-compose down
|
||||
```
|
||||
|
||||
expected output would be something like
|
||||
|
||||
```
|
||||
2019-09-03T15:16:38+0000
|
||||
ALT buildno=2 port 8000 2019-09-03T15:16:38+0000
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
as you can see we were able to override buildno to be 2 instead of 1,
|
||||
and httpd_port to 8000.
|
||||
|
||||
NOTE: build labels are not passed to `podman build`
|
@ -1,22 +0,0 @@
|
||||
# Test podman-compose with build (fail scenario)
|
||||
|
||||
```shell
|
||||
podman-compose build || echo $?
|
||||
```
|
||||
|
||||
expected output would be something like
|
||||
|
||||
```
|
||||
STEP 1/3: FROM busybox
|
||||
STEP 2/3: RUN this_command_does_not_exist
|
||||
/bin/sh: this_command_does_not_exist: not found
|
||||
Error: building at STEP "RUN this_command_does_not_exist": while running runtime: exit status 127
|
||||
|
||||
exit code: 127
|
||||
```
|
||||
|
||||
Expected `podman-compose` exit code:
|
||||
```shell
|
||||
echo $?
|
||||
127
|
||||
```
|
@ -1,26 +0,0 @@
|
||||
"""conftest.py
|
||||
|
||||
Defines global pytest fixtures available to all tests.
|
||||
"""
|
||||
# pylint: disable=redefined-outer-name
|
||||
from pathlib import Path
|
||||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def base_path():
|
||||
"""Returns the base path for the project"""
|
||||
return Path(__file__).parent.parent
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_path(base_path):
|
||||
"""Returns the path to the tests directory"""
|
||||
return os.path.join(base_path, "tests")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def podman_compose_path(base_path):
|
||||
"""Returns the path to the podman compose script"""
|
||||
return os.path.join(base_path, "podman_compose.py")
|
@ -1,4 +0,0 @@
|
||||
|
||||
```
|
||||
podman-compose run --rm sleep /bin/sh -c 'wget -O - http://localhost:8000/hosts'
|
||||
```
|
@ -1,24 +0,0 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
web:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
sleep:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "sleep 3600"]
|
||||
depends_on: "web"
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
sleep2:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "sleep 3600"]
|
||||
depends_on:
|
||||
- sleep
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
|
@ -1,9 +0,0 @@
|
||||
running the following commands should always give podman-rocks-123
|
||||
|
||||
```
|
||||
podman-compose -f project/container-compose.yaml --env-file env-files/project-1.env up
|
||||
```
|
||||
|
||||
```
|
||||
podman-compose -f $(pwd)/project/container-compose.yaml --env-file $(pwd)/env-files/project-1.env up
|
||||
```
|
@ -1 +0,0 @@
|
||||
ZZVAR1=podman-rocks-123
|
@ -1,21 +0,0 @@
|
||||
version: "3"
|
||||
services:
|
||||
too_long:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "sleep 3600; exit 0"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
sh1:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "sleep 5; exit 1"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
sh2:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "sleep 5; exit 2"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
|
@ -1 +0,0 @@
|
||||
FROM busybox as base
|
@ -1,7 +0,0 @@
|
||||
version: '3.6'
|
||||
|
||||
services:
|
||||
web:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "httpd", "-f", "-h", ".", "-p", "8003"]
|
||||
|
12
tests/integration/__init__.py
Normal file
12
tests/integration/__init__.py
Normal file
@ -0,0 +1,12 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def create_base_test_image():
|
||||
subprocess.check_call(
|
||||
['podman', 'build', '-t', 'nopush/podman-compose-test', '.'],
|
||||
cwd=os.path.join(os.path.dirname(__file__), "base_image"),
|
||||
)
|
||||
|
||||
|
||||
create_base_test_image()
|
14
tests/integration/additional_contexts/README.md
Normal file
14
tests/integration/additional_contexts/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Test podman-compose with build.additional_contexts
|
||||
|
||||
```
|
||||
podman-compose build
|
||||
podman-compose up
|
||||
podman-compose down
|
||||
```
|
||||
|
||||
expected output would be
|
||||
|
||||
```
|
||||
[dict] | Data for dict
|
||||
[list] | Data for list
|
||||
```
|
@ -0,0 +1 @@
|
||||
Data for dict
|
@ -0,0 +1 @@
|
||||
Data for list
|
3
tests/integration/additional_contexts/project/Dockerfile
Normal file
3
tests/integration/additional_contexts/project/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM busybox
|
||||
COPY --from=data data.txt /data/data.txt
|
||||
CMD ["busybox", "cat", "/data/data.txt"]
|
@ -0,0 +1,12 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
dict:
|
||||
build:
|
||||
context: .
|
||||
additional_contexts:
|
||||
data: ../data_for_dict
|
||||
list:
|
||||
build:
|
||||
context: .
|
||||
additional_contexts:
|
||||
- data=../data_for_list
|
6
tests/integration/base_image/Dockerfile
Normal file
6
tests/integration/base_image/Dockerfile
Normal file
@ -0,0 +1,6 @@
|
||||
FROM docker.io/library/debian:bookworm-slim
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
dumb-init \
|
||||
busybox \
|
||||
wget
|
1
tests/integration/build_labels/context/Dockerfile
Normal file
1
tests/integration/build_labels/context/Dockerfile
Normal file
@ -0,0 +1 @@
|
||||
FROM busybox
|
22
tests/integration/build_labels/docker-compose.yml
Normal file
22
tests/integration/build_labels/docker-compose.yml
Normal file
@ -0,0 +1,22 @@
|
||||
version: "3"
|
||||
services:
|
||||
test_build_labels_map:
|
||||
build:
|
||||
context: ./context
|
||||
dockerfile: Dockerfile
|
||||
labels:
|
||||
com.example.description: "Accounting webapp"
|
||||
com.example.department: "Finance"
|
||||
com.example.label-with-empty-value: ""
|
||||
image: my-busybox-build-labels-map
|
||||
command: env
|
||||
test_build_labels_array:
|
||||
build:
|
||||
context: ./context
|
||||
dockerfile: Dockerfile
|
||||
labels:
|
||||
- "com.example.description=Accounting webapp"
|
||||
- "com.example.department=Finance"
|
||||
- "com.example.label-with-empty-value"
|
||||
image: my-busybox-build-labels-array
|
||||
command: env
|
60
tests/integration/build_labels/test_build_labels.py
Normal file
60
tests/integration/build_labels/test_build_labels.py
Normal file
@ -0,0 +1,60 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from tests.integration.test_podman_compose import podman_compose_path
|
||||
from tests.integration.test_podman_compose import test_path
|
||||
from tests.integration.test_utils import RunSubprocessMixin
|
||||
|
||||
|
||||
class TestBuildLabels(unittest.TestCase, RunSubprocessMixin):
|
||||
def test_build_labels(self):
|
||||
"""The build context can contain labels which should be added to the resulting image. They
|
||||
can be either an array or a map.
|
||||
"""
|
||||
|
||||
compose_path = os.path.join(test_path(), "build_labels/docker-compose.yml")
|
||||
|
||||
try:
|
||||
self.run_subprocess_assert_returncode([
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
compose_path,
|
||||
"build",
|
||||
"test_build_labels_map",
|
||||
"test_build_labels_array",
|
||||
])
|
||||
|
||||
expected_labels = {
|
||||
"com.example.department": "Finance",
|
||||
"com.example.description": "Accounting webapp",
|
||||
"com.example.label-with-empty-value": "",
|
||||
}
|
||||
|
||||
out, _ = self.run_subprocess_assert_returncode([
|
||||
"podman",
|
||||
"inspect",
|
||||
"my-busybox-build-labels-map",
|
||||
"my-busybox-build-labels-array",
|
||||
])
|
||||
|
||||
images = json.loads(out)
|
||||
self.assertEqual(len(images), 2)
|
||||
labels_map = images[0].get("Config", {}).get("Labels", {})
|
||||
labels_array = images[1].get("Config", {}).get("Labels", {})
|
||||
for k, v in expected_labels.items():
|
||||
self.assertIn(k, labels_map)
|
||||
self.assertEqual(labels_map[k], v)
|
||||
self.assertIn(k, labels_array)
|
||||
self.assertEqual(labels_array[k], v)
|
||||
|
||||
finally:
|
||||
self.run_subprocess_assert_returncode([
|
||||
"podman",
|
||||
"rmi",
|
||||
"my-busybox-build-labels-map",
|
||||
"my-busybox-build-labels-array",
|
||||
])
|
9
tests/integration/build_secrets/Dockerfile
Normal file
9
tests/integration/build_secrets/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM busybox
|
||||
|
||||
RUN --mount=type=secret,required=true,id=build_secret \
|
||||
ls -l /run/secrets/ && cat /run/secrets/build_secret
|
||||
|
||||
RUN --mount=type=secret,required=true,id=build_secret,target=/tmp/secret \
|
||||
ls -l /run/secrets/ /tmp/ && cat /tmp/secret
|
||||
|
||||
CMD [ 'echo', 'nothing here' ]
|
22
tests/integration/build_secrets/docker-compose.yaml
Normal file
22
tests/integration/build_secrets/docker-compose.yaml
Normal file
@ -0,0 +1,22 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
test:
|
||||
image: test
|
||||
secrets:
|
||||
- run_secret # implicitly mount to /run/secrets/run_secret
|
||||
- source: run_secret
|
||||
target: /tmp/run_secret2 # explicit mount point
|
||||
|
||||
build:
|
||||
context: .
|
||||
secrets:
|
||||
- build_secret # can be mounted in Dockerfile with "RUN --mount=type=secret,id=build_secret"
|
||||
- source: build_secret
|
||||
target: build_secret2 # rename to build_secret2
|
||||
|
||||
secrets:
|
||||
build_secret:
|
||||
file: ./my_secret
|
||||
run_secret:
|
||||
file: ./my_secret
|
18
tests/integration/build_secrets/docker-compose.yaml.invalid
Normal file
18
tests/integration/build_secrets/docker-compose.yaml.invalid
Normal file
@ -0,0 +1,18 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
test:
|
||||
image: test
|
||||
build:
|
||||
context: .
|
||||
secrets:
|
||||
# invalid target argument
|
||||
#
|
||||
# According to https://github.com/compose-spec/compose-spec/blob/master/build.md, target is
|
||||
# supposed to be the "name of a *file* to be mounted in /run/secrets/". Not a path.
|
||||
- source: build_secret
|
||||
target: /build_secret
|
||||
|
||||
secrets:
|
||||
build_secret:
|
||||
file: ./my_secret
|
25
tests/integration/deps/docker-compose.yaml
Normal file
25
tests/integration/deps/docker-compose.yaml
Normal file
@ -0,0 +1,25 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
web:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
sleep:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600"]
|
||||
depends_on:
|
||||
- "web"
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
sleep2:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600"]
|
||||
depends_on:
|
||||
- sleep
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
|
2
tests/integration/env-file-tests/.env
Normal file
2
tests/integration/env-file-tests/.env
Normal file
@ -0,0 +1,2 @@
|
||||
ZZVAR1='This value is overwritten by env-file-tests/.env'
|
||||
ZZVAR3='This value is loaded from env-file-tests/.env'
|
4
tests/integration/env-file-tests/.gitignore
vendored
Normal file
4
tests/integration/env-file-tests/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# This overrides the repository root .gitignore (ignoring all .env).
|
||||
# The .env files in this directory are important for the test cases.
|
||||
!.env
|
||||
!project/.env
|
37
tests/integration/env-file-tests/README.md
Normal file
37
tests/integration/env-file-tests/README.md
Normal file
@ -0,0 +1,37 @@
|
||||
running the following commands should always give podman-rocks-123
|
||||
|
||||
```
|
||||
podman-compose -f project/container-compose.yaml --env-file env-files/project-1.env up
|
||||
```
|
||||
|
||||
```
|
||||
podman-compose -f $(pwd)/project/container-compose.yaml --env-file $(pwd)/env-files/project-1.env up
|
||||
```
|
||||
|
||||
```
|
||||
podman-compose -f $(pwd)/project/container-compose.env-file-flat.yaml up
|
||||
```
|
||||
|
||||
```
|
||||
podman-compose -f $(pwd)/project/container-compose.env-file-obj.yaml up
|
||||
```
|
||||
|
||||
```
|
||||
podman-compose -f $(pwd)/project/container-compose.env-file-obj-optional.yaml up
|
||||
```
|
||||
|
||||
based on environment variable precedent this command should give podman-rocks-321
|
||||
|
||||
```
|
||||
ZZVAR1=podman-rocks-321 podman-compose -f $(pwd)/project/container-compose.yaml --env-file $(pwd)/env-files/project-1.env up
|
||||
```
|
||||
|
||||
_The below test should print three environment variables_
|
||||
|
||||
```
|
||||
podman-compose -f $(pwd)/project/container-compose.load-.env-in-project.yaml run --rm app
|
||||
|
||||
ZZVAR1=This value is overwritten by env-file-tests/.env
|
||||
ZZVAR2=This value is loaded from .env in project/ directory
|
||||
ZZVAR3=This value is loaded from env-file-tests/.env
|
||||
```
|
3
tests/integration/env-file-tests/env-files/project-1.env
Normal file
3
tests/integration/env-file-tests/env-files/project-1.env
Normal file
@ -0,0 +1,3 @@
|
||||
ZZVAR1=podman-rocks-123
|
||||
ZZVAR2=podman-rocks-124
|
||||
ZZVAR3=podman-rocks-125
|
2
tests/integration/env-file-tests/env-files/project-2.env
Normal file
2
tests/integration/env-file-tests/env-files/project-2.env
Normal file
@ -0,0 +1,2 @@
|
||||
ZZVAR1=podman-rocks-223
|
||||
ZZVAR2=podman-rocks-224
|
2
tests/integration/env-file-tests/project/.env
Normal file
2
tests/integration/env-file-tests/project/.env
Normal file
@ -0,0 +1,2 @@
|
||||
ZZVAR1='This value is loaded but should be overwritten'
|
||||
ZZVAR2='This value is loaded from .env in project/ directory'
|
@ -0,0 +1,9 @@
|
||||
services:
|
||||
app:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "env | grep ZZ"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
env_file:
|
||||
- ../env-files/project-1.env
|
@ -0,0 +1,11 @@
|
||||
services:
|
||||
app:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "env | grep ZZ"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
env_file:
|
||||
- path: ../env-files/project-1.env
|
||||
- path: ../env-files/project-2.env
|
||||
required: false
|
@ -0,0 +1,9 @@
|
||||
services:
|
||||
app:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "env | grep ZZ"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
env_file:
|
||||
- path: ../env-files/project-1.env
|
@ -0,0 +1,11 @@
|
||||
services:
|
||||
app:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "sh", "-c", "env | grep ZZ"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
environment:
|
||||
ZZVAR1: $ZZVAR1
|
||||
ZZVAR2: $ZZVAR2
|
||||
ZZVAR3: $ZZVAR3
|
21
tests/integration/exit-from/docker-compose.yaml
Normal file
21
tests/integration/exit-from/docker-compose.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
version: "3"
|
||||
services:
|
||||
too_long:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600; exit 0"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
sh1:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 1; exit 1"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
sh2:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 1; exit 2"]
|
||||
tmpfs:
|
||||
- /run
|
||||
- /tmp
|
||||
|
@ -2,6 +2,6 @@ services:
|
||||
webapp_default:
|
||||
|
||||
webapp_special:
|
||||
image: busybox
|
||||
image: nopush/podman-compose-test
|
||||
volumes:
|
||||
- "/data"
|
@ -1,7 +1,7 @@
|
||||
version: "3"
|
||||
services:
|
||||
web:
|
||||
image: busybox
|
||||
image: nopush/podman-compose-test
|
||||
extends:
|
||||
file: common-services.yml
|
||||
service: webapp_default
|
@ -0,0 +1 @@
|
||||
FROM nopush/podman-compose-test as base
|
1
tests/integration/filesystem/compose_symlink/docker-compose.yml
Symbolic link
1
tests/integration/filesystem/compose_symlink/docker-compose.yml
Symbolic link
@ -0,0 +1 @@
|
||||
../compose_symlink_dest/docker-compose.yml
|
1
tests/integration/filesystem/compose_symlink/file
Normal file
1
tests/integration/filesystem/compose_symlink/file
Normal file
@ -0,0 +1 @@
|
||||
data_compose_symlink
|
@ -0,0 +1,7 @@
|
||||
version: "3"
|
||||
services:
|
||||
container1:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["/bin/busybox", "cat", "/file"]
|
||||
volumes:
|
||||
- "./file:/file"
|
1
tests/integration/filesystem/compose_symlink_dest/file
Normal file
1
tests/integration/filesystem/compose_symlink_dest/file
Normal file
@ -0,0 +1 @@
|
||||
data_compose_symlink_dest
|
47
tests/integration/filesystem/test_filesystem.py
Normal file
47
tests/integration/filesystem/test_filesystem.py
Normal file
@ -0,0 +1,47 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from tests.integration.test_podman_compose import podman_compose_path
|
||||
from tests.integration.test_podman_compose import test_path
|
||||
from tests.integration.test_utils import RunSubprocessMixin
|
||||
|
||||
|
||||
class TestFilesystem(unittest.TestCase, RunSubprocessMixin):
|
||||
def test_compose_symlink(self):
|
||||
"""The context of podman-compose.yml should come from the same directory as the file even
|
||||
if it is a symlink
|
||||
"""
|
||||
|
||||
compose_path = os.path.join(test_path(), "filesystem/compose_symlink/docker-compose.yml")
|
||||
|
||||
try:
|
||||
self.run_subprocess_assert_returncode([
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
compose_path,
|
||||
"up",
|
||||
"-d",
|
||||
"container1",
|
||||
])
|
||||
|
||||
out, _ = self.run_subprocess_assert_returncode([
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
compose_path,
|
||||
"logs",
|
||||
"container1",
|
||||
])
|
||||
|
||||
# BUG: figure out why cat is called twice
|
||||
self.assertEqual(out, b'data_compose_symlink\ndata_compose_symlink\n')
|
||||
|
||||
finally:
|
||||
out, _ = self.run_subprocess_assert_returncode([
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
compose_path,
|
||||
"down",
|
||||
])
|
@ -0,0 +1,9 @@
|
||||
version: "3"
|
||||
services:
|
||||
cont:
|
||||
image: nopush/podman-compose-test
|
||||
userns_mode: keep-id:uid=1000
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-p", "8080"]
|
||||
|
||||
x-podman:
|
||||
in_pod: false
|
@ -0,0 +1,6 @@
|
||||
version: "3"
|
||||
services:
|
||||
cont:
|
||||
image: nopush/podman-compose-test
|
||||
userns_mode: keep-id:uid=1000
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-p", "8080"]
|
@ -0,0 +1,9 @@
|
||||
version: "3"
|
||||
services:
|
||||
cont:
|
||||
image: nopush/podman-compose-test
|
||||
userns_mode: keep-id:uid=1000
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-p", "8080"]
|
||||
|
||||
x-podman:
|
||||
in_pod: true
|
7
tests/integration/include/docker-compose.base.yaml
Normal file
7
tests/integration/include/docker-compose.base.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
version: '3.6'
|
||||
|
||||
services:
|
||||
web:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", ".", "-p", "8003"]
|
||||
|
6
tests/integration/include/docker-compose.extend.yaml
Normal file
6
tests/integration/include/docker-compose.extend.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
version: '3.6'
|
||||
|
||||
services:
|
||||
web2:
|
||||
image: nopush/podman-compose-test
|
||||
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", ".", "-p", "8004"]
|
@ -2,3 +2,4 @@ version: '3.6'
|
||||
|
||||
include:
|
||||
- docker-compose.base.yaml
|
||||
- docker-compose.extend.yaml
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user