458 Commits

Author SHA1 Message Date
d38b26bb01 Release 1.2.0
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-06-26 10:43:28 +03:00
22a4ad5806 Merge pull request #975 from p12tic/changelog
Add release notes for v1.2.0
2024-06-26 10:41:59 +03:00
37e2cb28d4 Add release notes for v1.2.0
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-06-26 10:39:48 +03:00
0cd3902c5f Merge pull request #974 from p12tic/newsfragments
Use newsfragments pattern for the release notes
2024-06-26 10:37:54 +03:00
6ef759c6fd Use newsfragments pattern for the release notes
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-06-26 10:21:03 +03:00
16cbcf4152 Merge pull request #956 from Genzer/fix/loading-.env-breaking-since-1.1.0
Load .env from Compose file's directory and cwd
2024-06-24 23:37:33 +03:00
67ce900885 Commit .env in tests/env-file-tests, bypassing root .gitignore
This commit adds a .gitignore in tests/env-file-tests to allow .env files
to be committed.

Fix: #937
Signed-off-by: Genzer <732937+Genzer@users.noreply.github.com>
2024-06-24 23:29:57 +03:00
4e9f76768c Load .env from Compose file's directory and cwd
This commit loads dotenv `.env` (exactly that name) from the following location (the later takes
precedence):

- The `.env` file in the Compose file's directory.
- The `.env` file in the current working directory (invoking podman-compose).

This preserves the behavior prior to 1.1.0 and to match with Docker Compose CLI.

Fix: https://github.com/containers/podman-compose/issues/937
Signed-off-by: Genzer <732937+Genzer@users.noreply.github.com>
2024-06-24 23:29:56 +03:00
84f7fdd7da Merge pull request #971 from mokibit/type-env-secret-support
Add support for environment variable secrets
2024-06-24 23:17:34 +03:00
405001b990 Fix comment
Signed-off-by: Monika Kairaityte <monika@kibit.lt>
2024-06-24 21:24:34 +03:00
6b1aeff55f Add unittests for type=env secret
Signed-off-by: Monika Kairaityte <monika@kibit.lt>
2024-06-24 21:24:34 +03:00
f06975b346 Update tests for type=env secret
Signed-off-by: Brett Calliss <brett@obligatory.email>
2024-06-24 20:12:44 +03:00
546cad5171 Add type=env secret support
Signed-off-by: Brett Calliss <brett@obligatory.email>
2024-06-24 20:12:44 +03:00
e07c28d127 Merge pull request #771 from wgnathanael/environment-precedence
Fix environment variable precedents
2024-06-22 20:00:08 +03:00
935029dc33 Fix environment variable precedents
Per https://docs.docker.com/compose/environment-variables/envvars-precedence/#advanced-example

Signed-off-by: nathanael.noblet <nathanael.noblet@willowglensystems.com>
2024-06-22 19:58:02 +03:00
80b2aa6ed0 Merge pull request #964 from mokibit/set-custom-in_pod-in-compose-file
Allow providing custom in_pod argument as a global compose file variable
2024-06-20 09:45:41 +03:00
360b85bf2d Allow providing custom in_pod argument as a global compose file variable
Default command line argument `in_pod` was set to True, but this breaks
the compose file for users who want to use `--userns` argument. This
commit sets default `in_pod` value to None, and later resolves whether
to create a pod by checking compose file, as new argument in compose
file x-podman is now available. Now it is convenient for users to pass
custom `in_pod` value (True or False) as a compose file argument when
command line value of `in_pod` is not provided.

Signed-off-by: Monika Kairaityte <monika@kibit.lt>
2024-06-20 09:42:22 +03:00
650a835eca Merge pull request #966 from ArthoPacini/enhance/stdin-docker-compose-support
Add ability to input docker-compose.yaml via stdin
2024-06-19 20:06:15 +03:00
82740cc311 Add ability to input docker-compose.yaml via stdin
Signed-off-by: Artho Pacini <eu@arthopacini.com>
2024-06-18 00:05:31 +03:00
0f645e4c70 Add ability to input docker-compose.yaml via stdin
Signed-off-by: Artho Pacini <eu@arthopacini.com>
2024-06-18 00:05:31 +03:00
3b15170ccf Changed the global parser help message for file input, to reflect changes for reading from stdin
Signed-off-by: Artho Pacini <eu@arthopacini.com>
2024-06-18 00:05:31 +03:00
3359380ec6 Add ability to input docker-compose.yaml via stdin
Signed-off-by: Artho Pacini <eu@arthopacini.com>
2024-06-18 00:05:31 +03:00
14f39e5b86 Merge pull request #965 from mokibit/fix-gidmap-typo
Fix x-podman.gidmap typo
2024-06-17 10:08:17 +03:00
e799a0b0ea Fix x-podman.gidmap typo
Signed-off-by: Monika Kairaityte <monika@kibit.lt>
2024-06-14 17:31:55 +03:00
6d8d3e94fe Merge pull request #960 from mokibit/github-verbose-integration-tests
github: Add verbose option to integration tests
2024-06-08 20:15:13 +03:00
65d1fdeaa3 github: Add verbose option to integration tests
Currently it is not possible to see which test output corresponds to
which test exactly. Now before each new test its test name is printed.

Signed-off-by: Monika Kairaityte <monika@kibit.lt>
2024-06-08 20:05:12 +03:00
d905a7c638 Merge pull request #949 from mokibit/multiline-env-file
Add support for multi-line environment files
2024-05-29 00:47:58 +03:00
2e8ed2f924 pytests: Add test for object required but path non existent
Signed-off-by: Monika Kairaityte <monika@kibit.lt>
2024-05-29 00:09:22 +03:00
040b73adab pytests: Add tests for several multi-line environment files
Signed-off-by: Monika Kairaityte <monika@kibit.lt>
2024-05-29 00:09:15 +03:00
f3e9a96c96 Fixes #908: Add support for multi-line environment files
Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
2024-05-28 23:43:15 +03:00
04b107805a Merge pull request #954 from mokibit/fix-codespelling-update
github/workflows: Fix automatic codespelling update
2024-05-28 23:40:59 +03:00
2c5d00d3e7 github/workflows: Add codespellignore file to address false positives
Signed-off-by: Monika Kairaityte <monika@kibit.lt>
2024-05-28 20:20:33 +03:00
cac90f69b8 Merge pull request #946 from charliemirabile/selinux_tests
Missing SELinux tests
2024-05-22 10:17:05 +03:00
b513f50f30 test: add missing unit tests for selinux in verbose mount
Support for setting the selinux flags on a bind mount specified using
the verbose syntax was merged as part of #911, but at that time the PR
lacked unit tests. This commit adds the missing tests

Signed-off-by: charliemirabile <46761267+charliemirabile@users.noreply.github.com>
2024-05-21 19:43:03 -04:00
8f618b6fab Merge pull request #763 from otto-liljalaakso-nt/additional_contexts
Support additional_contexts
2024-05-21 19:49:23 +03:00
cac836b0f5 Support additional_contexts
Signed-off-by: Otto Liljalaakso <otto.liljalaakso@novatron.fi>
2024-05-21 19:44:37 +03:00
3bb305cef4 Merge pull request #945 from p12tic/split-gpu-test
test: Split test_gpu test
2024-05-21 12:25:11 +03:00
09034a0c38 test: Split test_gpu test
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-05-21 12:04:32 +03:00
e668a339ce Merge pull request #943 from HernandoR/fix/multi-sub-composes
Fix the test_include for multi subcomposes
2024-05-21 11:32:17 +03:00
0065082db9 refine the test_include for multi subcomposes
Signed-off-by: Zhen Liu <lzhen.dev@outlook.com>
2024-05-21 11:28:27 +03:00
5d4de80ab7 Merge pull request #911 from charliemirabile/selinux
Add support for selinux in verbose bind mount specification
2024-05-19 11:13:45 +03:00
23ad5c3ef7 Merge pull request #920 from mokeyish/gpu
Add supoort for enabling GPU access
2024-05-19 11:12:34 +03:00
45efe461b0 Merge pull request #941 from HernandoR/patch-1
Update podman_compose.py
2024-05-19 11:10:39 +03:00
4f73f2b79e fix: add include test file, edit the assertion
Signed-off-by: Zhen Liu <lzhen.dev@outlook.com>
2024-05-18 21:23:43 +08:00
1d64f2cf8c Update podman_compose.py
fix #940

Signed-off-by: Zhen Liu <lzhen.dev@outlook.com>
2024-05-18 20:33:10 +08:00
2ce6d1a1e7 Merge pull request #933 from hedayat/fix-build-error-log
Fix logging build error message
2024-05-13 16:24:15 +03:00
4e22faefd6 Fix logging build error message
Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
2024-05-13 15:13:40 +03:00
7a2da76ab8 Merge pull request #724 from hedayat/fix-merge-depends-on
Fixes #723: merge short & long syntax of depends_on dependencies
2024-05-08 17:57:44 +03:00
79865c2e13 Add support for enabling GPU access
Signed-off-by: YISH <mokeyish@hotmail.com>
2024-05-07 10:32:24 +08:00
33d7d35a4d Merge pull request #851 from fccagou/fix-ipam-driver-default
fix(ipam_driver): do not pass --ipam-driver option when value set to …
2024-05-06 17:31:59 +03:00
c23a8b2cbd Do not pass --ipam-driver option when value set to default
fixes #852.

Signed-off-by: fccagou <me@fccagou.fr>
2024-05-06 17:00:17 +03:00
36a3d3c207 Merge pull request #925 from GerkinDev/feat/env-file-object
Fixes #897: support `env_file` as objects
2024-05-06 16:57:25 +03:00
b202a09501 Add support for env_file as objects
Fixes: https://github.com/containers/podman-compose/issues/897

Signed-off-by: Alexandre Germain <nihilivin@gmail.com>
2024-05-06 14:13:37 +03:00
35cbc49160 Merge pull request #928 from schugabe/patch-1
add await for create_pods call
2024-05-06 14:00:29 +03:00
5c4aa40032 add await for create_pods call
fixes log output podman_compose.py:2527: RuntimeWarning: coroutine 'create_pods' was never awaited

Signed-off-by: Johannes Kasberger <schugabe@gmx.at>
2024-05-06 11:02:45 +02:00
0ee7c2630a Merge pull request #641 from DaniruKun/devel
Add instructions on install from Homebrew
2024-05-04 18:03:43 +03:00
cef1785cd5 Add instructions on install from Homebrew
Signed-off-by: Daniils Petrovs <thedanpetrov@gmail.com>
2024-05-04 17:50:06 +03:00
b4cfef12e9 Merge pull request #926 from p12tic/cleanup-tests
Cleanup tests
2024-05-04 17:32:00 +03:00
b761050b0b tests: Merge multiple compose merging tests into single test class
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-05-04 17:30:09 +03:00
e1d0ea7b4e tests: Move normalize_service tests to a separate test class
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-05-04 17:29:04 +03:00
1430578568 tests: Simplify command and entrypoint normalization tests
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-05-04 17:28:59 +03:00
8f41cd3cdb Merge pull request #731 from g2p/patch-1
README: explain that netavark is an alternative to the dnsname plugin
2024-05-01 21:16:27 +03:00
a73dac2e39 Merge pull request #923 from winston-yallow/remove-sideeffect-from-systemd-registration
Don't create pods/container when registering systemd unit
2024-05-01 21:05:13 +03:00
d31a8b124d Don't create pods/container when registering systemd unit
Signed-off-by: Winston <44872771+winston-yallow@users.noreply.github.com>
2024-05-01 20:03:14 +02:00
5df4e786ee README: explain that netavark is an alternative to the dnsname plugin
This is a useful hint when the dnsname plugin is not packaged.

Signed-off-by: Gabriel de Perthuis <g2p.code@gmail.com>
2024-05-01 15:13:29 +02:00
27e27e9fe9 Merge pull request #918 from p12tic/fix-in-pod
Fix handling of --in-pod argument
2024-04-28 21:33:50 +03:00
70a0e2d003 Fix handling of --in-pod argument
Currently --in-pod handling is broken because the only way to set False
is by providing empty argument like "--in-pod=". As of Python 3.7 the
solution is to accept string and parse manually.

Co-authored-by: Randolph Sapp <res.sapp@gmail.com>
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-04-28 21:16:34 +03:00
58641f0545 Merge pull request #716 from Tayeh/images_cmd
add `podman-compose images` command
2024-04-28 20:37:07 +03:00
eea8bac496 Add images command
Signed-off-by: Mohammed Tayeh <m.tayeh94@gmail.com>
2024-04-28 19:04:23 +03:00
09a8a3edf9 Merge pull request #917 from p12tic/x-podman-keys
Migrate x-podman dictionary on container root to x-podman.* fields
2024-04-28 18:29:33 +03:00
a6c4263738 Add tests for x-podman.uidmaps and x-podman.gidmaps
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-04-28 18:25:04 +03:00
9599cc039e Migrate x-podman dictionary to x-podman.* fields in container root
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-04-28 18:24:37 +03:00
0a6c057486 Merge pull request #737 from ftyghome/feat_rootfs
Support podman's external rootfs management
2024-04-28 18:04:37 +03:00
2b4ecee082 Add docs for podman specific compose file extensions
Signed-off-by: GnSight <ftyg@live.com>
2024-04-28 17:55:39 +03:00
77f2e8e5b0 Support podman's external rootfs management
Signed-off-by: GnSight <ftyg@live.com>
2024-04-28 17:55:39 +03:00
12d46ca836 Merge pull request #916 from beledouxdenis/main-run-implement-publish
implement --publish in docker-compose run
2024-04-28 17:33:56 +03:00
72a94d5185 implement --publish in docker-compose run
Signed-off-by: Denis Ledoux <dle@odoo.com>
2024-04-28 00:54:35 +02:00
2681566580 Release 1.1.0 2024-04-19 12:37:30 +03:00
62ce087c6e Merge pull request #914 from p12tic/release-notes
Add release notes for v1.1.0
2024-04-17 20:26:52 +03:00
c97f003732 Add release notes for v1.1.0
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-04-17 20:23:48 +03:00
c88558b4ec Merge pull request #913 from p12tic/network-mac-address-vendor-prefix
Use x- prefix for x-podman.mac_address
2024-04-17 20:21:56 +03:00
131010bc9d Use x- prefix for x-podman.mac_address
Docker compose documents x- prefix as standard vendor prefix.

https://github.com/compose-spec/compose-spec/pull/18

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-04-17 20:16:03 +03:00
1da2f85a90 Merge pull request #906 from camspiers/fixes/ulimit-build-args
Fix, use "service.build.ulimits" when it is present instead of "service.ulimits"
2024-04-17 19:48:55 +03:00
cdcedeb6b2 Use "service.build.ulimits" when present instead of "service.ulimits"
Signed-off-by: Cam Spiers <camspiers@gmail.com>
2024-04-17 19:45:34 +03:00
3e1f7d554b add tests for selinux with verbose bind mount
based on seccomp test. Without the selinux option, visiting localhost:8080
will give a 404 error because httpd cannot access the file, but with selinux: z
the context for the file will be appropriately updated so httpd can access it

Signed-off-by: charliemirabile <46761267+charliemirabile@users.noreply.github.com>
2024-04-10 15:29:03 -04:00
d7cf0966d3 add support for selinux in verbose mount
This corresponds to specifying the `z` or `Z` option in the third
portion of a terse mount specification (i.e. src:trg:z)

Signed-off-by: charliemirabile <46761267+charliemirabile@users.noreply.github.com>
2024-04-10 15:29:03 -04:00
e893d06313 Merge pull request #867 from baszoetekouw/fix-networks
Fix multiple networks with separately specified ip and mac
2024-04-08 23:21:38 +03:00
1f35c00694 Add unit test for depends_on normalization as a dict
Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
2024-04-08 23:31:41 +03:30
9a5b43907f Merge pull request #905 from acotty/main
FIX issue https://github.com/containers/podman-compose/issues/704 - Windows fix sock not working.
2024-04-07 12:43:43 +03:00
6c09ce710e FIX issue https://github.com/containers/podman-compose/issues/704 - Windows fix sock not working. 2024-04-07 16:28:45 +10:00
953534a71a Support and document all podman-specific network_modes
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
6feff244db slirp4netns can be used without options
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
9fd4cf43c1 Add unit tests for network_mode
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
65849c95e2 add comment about per-network aliases
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
9baea704d7 use preferred format of podman command line options
Specifically:
  - use "--network=foo" instead of "--network foo"
  - specify "--network-alias" multiple times instead of concatenating values

Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
bdff78dcba Ignore files generated by tests
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
45ca1f994f Support podman-specific per-network mac_address specifiation
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
91fbea3d89 Add unit tests for get_net_args()
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
2743d690d2 Fix support for multiple networks with explicitly specified ipv4/ipv6 addresses
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
dd34a90068 Add testcase for failing network config
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-28 16:09:43 +02:00
6103df78fb Merge pull request #777 from wiehe/build-secrets
Pass file secrets to "podman build" via parameter "--secret"
2024-03-28 00:40:12 +02:00
07128f6b37 Merge pull request #779 from jbaptperez/lint-fixes-and-enhancements
Lint fixes and enhancements
2024-03-28 00:36:50 +02:00
81d81fb303 Formats CONTRIBUTING.md
Signed-off-by: Jean-Baptiste Perez <jbaptperez@gmail.com>
2024-03-17 19:31:47 +01:00
b263dc1a7d Fixes typos and enhances CONTRIBUTING.md
Signed-off-by: Jean-Baptiste Perez <jbaptperez@gmail.com>
2024-03-17 19:31:47 +01:00
078ee7b649 Updates Signed-off-by link in CONTRIBUTING.md
The initial link was related to GPG signature in commits (--gpg-sign or
-S git-commit option) as the required signature is actually a
"Signed-off-by" trailer at the end of the commit message (--signoff or
-s git-commit option).

Signed-off-by: Jean-Baptiste Perez <jbaptperez@gmail.com>
2024-03-17 19:31:47 +01:00
a6e3ae7b31 Fixes invalid name of test package in setup.py
Signed-off-by: Jean-Baptiste Perez <jbaptperez@gmail.com>
2024-03-17 19:31:47 +01:00
1e9cf1dff0 Pass file secrets to "podman build" via parameter "--secret"
to make them available for "RUN --mount=type=secret" statements inside the
Dockerfile.

Keep using --volume to pass file secrets to "podman run".

Signed-off-by: wiehe <28457227+wiehe@users.noreply.github.com>
2024-03-12 17:23:40 +01:00
d704622522 Merge pull request #890 from containers/dependabot/github_actions/actions/checkout-4
Bump actions/checkout from 3 to 4
2024-03-12 15:27:34 +02:00
bbfff78e25 Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-11 21:44:23 +00:00
abb0cb1649 Merge pull request #888 from aripollak/fix-test-class-names
Rename test classes to match filenames
2024-03-10 00:21:20 +02:00
d53df307f8 Merge pull request #889 from aripollak/add-coverage-to-job-summary
Add coverage to Github Action summary
2024-03-10 00:20:50 +02:00
c351f99da5 Add coverage to Github Action summary
Signed-off-by: Ari Pollak <ajp@aripollak.com>
2024-03-09 17:10:14 -05:00
829cde0de9 Rename test classes to match filenames
Signed-off-by: Ari Pollak <ajp@aripollak.com>
2024-03-09 16:34:06 -05:00
f18c8092cc Merge pull request #887 from baszoetekouw/fix-oldpython
Fix support for older python versions
2024-03-09 23:29:32 +02:00
43059dc16f Merge pull request #783 from ChuJiani/devel
Fix #782: add support for `http-proxy` option of podman
2024-03-09 23:27:22 +02:00
da63048775 Don't spellcheck requirementfiles
As some python module names are not proper english words

Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-09 22:26:36 +01:00
7987a7185e Merge pull request #861 from aripollak/remove-implemented-from-missing
Remove implemented commands from Missing Commands
2024-03-09 23:26:36 +02:00
5e55df890c fix python < 3.9 compatibility
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-09 22:26:36 +01:00
fde7995cb8 Fix python < 3.11 compatibility
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-09 22:26:36 +01:00
c592596a5e Split out the different tests into separate CI steps
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-09 22:26:36 +01:00
688ee9a104 Fix pylint issues
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-09 22:26:35 +01:00
c3a152e68f Enable pylint, because it catches stuff that ruff misses
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-09 22:26:35 +01:00
bd60bc9f21 Run tests on all supported python versions
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-09 22:26:35 +01:00
9d8b0b8632 add editorconfig
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
2024-03-09 22:26:32 +01:00
ee013316c0 Merge pull request #860 from aripollak/fix-env-vars-with-equals
Allow run/exec -e with equals sign in value
2024-03-09 23:25:56 +02:00
f2f5483a74 Extract compose_run args parsing and add unit tests
Signed-off-by: Ari Pollak <ajp@aripollak.com>
2024-03-09 16:18:13 -05:00
c4fa8f7a16 Split exec args parsing into new function and add unit tests for it
Signed-off-by: Ari Pollak <ajp@aripollak.com>
2024-03-09 16:02:47 -05:00
4c270b9116 Allow run/exec -e with equals sign in value
Fixes: #798
Signed-off-by: Ari Pollak <ajp@aripollak.com>
2024-03-09 14:35:08 -05:00
c5f7f550f9 Remove implemented commands from Missing Commands
Signed-off-by: Ari Pollak <ajp@aripollak.com>
2024-03-09 14:32:29 -05:00
c98cbaaaf0 Fix #782: add support for http_proxy
Signed-off-by: ChuJiani <archet@chujiani.top>
2024-03-09 17:10:09 +00:00
f2f2f15a3b Merge pull request #765 from timocov/devel
Added handling `pid` option
2024-03-09 18:30:48 +02:00
91d316ff1f Added handling pid option
Fixes #554

Signed-off-by: Evgeniy Timokhov <timocov@gmail.com>
2024-03-09 16:10:37 +00:00
121b5f6ea1 Merge pull request #749 from maxi0604/more-network-options
Add support for enable_ipv6
2024-03-09 13:03:27 +02:00
969edb88d0 Add support for enable_ipv6
Signed-off-by: Maximilian R <maxi.rostock@outlook.de>
2024-03-09 13:01:41 +02:00
bba1f33d51 Factor out arg creation for "network create". Add unit tests.
Signed-off-by: Maximilian R <public@complexvector.space>
2024-03-09 13:00:09 +02:00
970e4ac4ab Merge pull request #764 from lemmi/sysctls-dict
Handle sysctls maps
2024-03-09 12:47:10 +02:00
a9c335bf82 Handle sysctls maps
- Add support to handle sysctls maps.
- Directly raise an error if sysctls is neither an array nor map instead
  of letting podman fail with an unhelpful message.

Support for sysctls arrays was added in #261.

Fixes #754: sysctls only works with arrays, not maps

Signed-off-by: lemmi <lemmi@nerd2nerd.org>
2024-03-09 12:44:55 +02:00
e67c52f2c4 test_container_to_args: handle async tests
Signed-off-by: lemmi <lemmi@nerd2nerd.org>
2024-03-09 12:44:55 +02:00
e0fc9a7546 Merge pull request #696 from dkull/devel
Fix stop/restart args stacking
2024-03-09 12:42:54 +02:00
2cdfb3e6d4 Fix stop/restart args stacking
Signed-off-by: Tanel Liiv <tanel.liiv@reconeyez.com>
Signed-off-by: Tanel Liiv <liivtanel@gmail.com>
2024-03-09 12:39:53 +02:00
60137eb7f9 Merge pull request #741 from maurerle/quiet-output
Output: use logging, remove verbose output by default
2024-03-09 12:35:00 +02:00
a7a993faef Merge pull request #886 from p12tic/github-pr-template
github: Add PR template
2024-03-09 12:27:17 +02:00
8ec5e0372a github: Add PR template
Adding a link to related part of compose spec is much easier for the
contributors, because they're already working on the feature. This saves
reviewer time.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-09 12:18:19 +02:00
da520e299b switch to % string lazy formatting
* fix black and pylint issues

Signed-off-by: Florian Maurer <f.maurer@outlook.de>
2024-03-09 10:40:24 +01:00
1e9e2ee776 Output: use logging, remove garbage output by default
Fixes #489.

Introduces a --verbose flag if you want to see all the noise that
was previously printed by default.

Signed-off-by: James O'Beirne <james.obeirne@pm.me>
Signed-off-by: Florian Maurer <f.maurer@outlook.de>
2024-03-09 10:36:20 +01:00
dcb6cdb55a Merge pull request #858 from breca/asyncio_compat
Replaces asyncio timeout with bespoke timeout function
2024-03-09 11:05:17 +02:00
0f693ee584 Replaces asyncio timeout with bespoke timeout function
Signed-off-by: Brett Calliss <brett@obligatory.email>
2024-03-09 19:02:32 +11:00
d468f85fd1 Merge pull request #755 from yarikoptic/enh-codespell
Add codespell config (to ignore loved "poped") and github workflow to prevent future typos
2024-03-09 01:47:25 +02:00
cf90ab2858 Run codespell throughout fixing typos automagically
Signed-off-by: Yaroslav Halchenko <debian@onerussian.com>
2024-03-08 18:41:03 -05:00
d2fa80196f ignore poped (not sure why not to make it popped)
Signed-off-by: Yaroslav Halchenko <debian@onerussian.com>
2024-03-08 18:41:03 -05:00
247774822c Add pre-commit definition for codespell
Signed-off-by: Yaroslav Halchenko <debian@onerussian.com>
2024-03-08 18:41:03 -05:00
6e65a73ab9 Add rudimentary codespell config
Signed-off-by: Yaroslav Halchenko <debian@onerussian.com>
2024-03-08 18:41:03 -05:00
f95ca7aca7 Add github action to codespell devel on push and PRs
Signed-off-by: Yaroslav Halchenko <debian@onerussian.com>
2024-03-08 18:41:03 -05:00
cdf5961bf2 Merge pull request #758 from containers/dependabot/github_actions/actions/checkout-4
Bump actions/checkout from 3 to 4
2024-03-09 01:09:28 +02:00
0c0e77c246 Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-08 22:51:44 +00:00
e6fc585702 Merge pull request #884 from p12tic/lint-fixes
Fix unsorted imports
2024-03-08 23:59:06 +02:00
bb2338e447 Fix unsorted imports
This is a logical merge conflict that has been caused by several PRs
landing in parallel.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:54:48 +02:00
a8db898ac6 Merge pull request #883 from p12tic/lint-fixes
Enable ruff check and fix lint errors
2024-03-08 23:51:25 +02:00
1ba1c364b9 Merge pull request #819 from p12tic/service-runtime
Add support for runtime service configuration key
2024-03-08 23:51:17 +02:00
15ae2140d4 Add support for runtime service configuration key
https://docs.docker.com/compose/compose-file/05-services/#runtime

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:48:55 +02:00
ed39523342 github: Enable ruff check
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:47:13 +02:00
4e43606df3 Shorten too long lines
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:46:24 +02:00
91052cb2d9 Fix ambiguous variable name
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:46:23 +02:00
a6e0092627 Remove unused variable
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:46:22 +02:00
59a1fa3942 Use 'not in' for membership test
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:46:21 +02:00
36139fb282 Remove unused f-string
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:46:20 +02:00
b0da6f82d3 Fix import formatting
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 23:46:19 +02:00
b1e4324d41 Merge pull request #882 from p12tic/readme-fix-badge-status
README: fix status badges
2024-03-08 16:26:23 +02:00
94df95acea README: Fix link to tests badge
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 16:09:15 +02:00
3a5a283cf6 README: Remove link to pylint test badge
This is an internal metric that the users don't need to care about at
all.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 16:09:11 +02:00
16a90e2bce Merge pull request #873 from p12tic/github-run-container
github: Run actions on python:3.11-bookworm
2024-03-08 15:58:18 +02:00
7c81044860 github: Run actions on python:3.11-bookworm
This ensures a stable environment for tests even when ubuntu-latest
changes. Also, the dependency on setup-python action has been
removed. That action supports only Ubuntu and limited architectures.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 15:56:30 +02:00
5b571942e0 Merge pull request #880 from p12tic/fix-test-names
github: Fix test names
2024-03-08 15:56:01 +02:00
de8f545f07 Merge pull request #881 from p12tic/test-fix-teardown
tests: Properly tear down containers in extends_w_file_subdir test
2024-03-08 15:55:54 +02:00
1a24cde608 tests: Properly tear down containers in extends_w_file_subdir test
podman rmi does not guarantee that the container itself is shut down.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 15:52:40 +02:00
a90da4dfaf github: Fix test names
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 15:51:24 +02:00
6841619b9c Merge pull request #879 from p12tic/tests-debug-output
tests: Add verbose debug option via env variable
2024-03-08 15:50:58 +02:00
27c8cebbdc tests: Add verbose debug option via env variable
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 15:34:00 +02:00
c84b4c33fc Merge pull request #878 from p12tic/tests-decoded-output
tests: Print decoded subprocess output in case of failure
2024-03-08 15:15:24 +02:00
0614687840 tests: Print decoded subprocess output in case of failure
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 15:11:25 +02:00
a494f20e15 Merge pull request #877 from p12tic/tests-faster
tests: Optimize speed by using dumb-init to handle SIGTERM signal
2024-03-08 14:49:25 +02:00
6af7a2d691 tests: Optimize speed by using dumb-init to handle SIGTERM signal
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 14:45:53 +02:00
872664b727 Merge pull request #876 from p12tic/tests-print-subprocess-errors
tests: Print output in case subprocess returns unexpected code
2024-03-08 14:41:23 +02:00
f4dc5f3b93 tests: Print output in case subprocess returns unexpected code
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 13:14:02 +02:00
ac5034065d Merge pull request #875 from p12tic/spdx-identifiers
Add SPDX license identifiers to each source file
2024-03-08 12:35:02 +02:00
b34f699adb Add SPDX license identifiers to each source file
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 12:19:51 +02:00
3d68d2432d Merge pull request #874 from p12tic/github-tests-on-all-branches
github: Run tests on all branches
2024-03-08 12:09:57 +02:00
2c6c1be197 github: Run tests on all branches
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 12:02:06 +02:00
f81cbe39b5 Merge pull request #872 from containers/dependabot/github_actions/actions/setup-python-5
Bump actions/setup-python from 4 to 5
2024-03-08 11:43:49 +02:00
91737ee0a6 Bump actions/setup-python from 4 to 5
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-08 09:41:46 +00:00
9d1407ba90 Merge pull request #871 from p12tic/unittest
Migrate tests to unittest
2024-03-08 11:39:20 +02:00
b65d4a3916 github: Fix ruff job setup
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 11:36:57 +02:00
23fe9e7e1d Migrate tests to unittest
unittest is much more straightforward without any magic. In a small
project like podman-compose being easy to understand is more important
than features.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 11:33:17 +02:00
7539257ee8 requirements: Install . for tests
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-08 11:00:33 +02:00
9e29891aa7 Merge pull request #870 from p12tic/ruff
Use ruff for formatting
2024-03-07 18:28:52 +02:00
a967cab02b Format codebase with ruff
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-07 18:28:06 +02:00
a5c354d60b Replace flake8, black, pylint with ruff
For now pylint checks are disabled.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-07 18:28:05 +02:00
e4e5b7d461 Make test requirements reproducible
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2024-03-07 18:28:04 +02:00
e0edd5dac1 Fix package installation
Signed-off-by: Brett Calliss <brett@obligatory.email>
2024-02-25 01:25:28 +03:00
831caa6276 remove recursion 2024-02-06 00:23:14 +03:00
9ac33392a0 Fix issue #831
Signed-off-by: Ben Plessinger <Benjamin.Plessinger@roswellpark.org>
2024-02-06 00:20:11 +03:00
c5be5bae90 Fixup tests
Signed-off-by: Falmarri <463948+Falmarri@users.noreply.github.com>
2024-02-04 10:11:57 +03:00
c6a1c4c432 Add tests to make sure all async paths are covered
Not at 100% yet. But upped code coverage significantly and covered major
async calls.

Signed-off-by: Falmarri <463948+Falmarri@users.noreply.github.com>
2024-02-04 10:11:57 +03:00
3c9628b462 Fix a couple issues and update docs
Signed-off-by: Falmarri <463948+Falmarri@users.noreply.github.com>
2024-02-04 10:11:57 +03:00
38b13a34ea Use asyncio for subprocess calls
Removes the threads from compose_up and manages it using async. Also
uses async processing to format the log messages instead of piping
through sed. This should work on windows without having sed installed

Adds --parallel to support pull and build in parallel, same as docker
compose

Signed-off-by: Falmarri <463948+Falmarri@users.noreply.github.com>
2024-02-04 10:11:57 +03:00
bce40c2db3 Change "an key-value" to "a key-value" 2023-08-08 18:05:58 +03:00
78f8cad7c4 Fix typos
Found via `codespell -L poped`
2023-08-08 18:05:25 +03:00
7942a540cd fix styling errors
Signed-off-by: Mohammed Tayeh <m.tayeh94@gmail.com>
2023-08-08 18:05:02 +03:00
cb9cf6002f add stats command
Signed-off-by: Mohammed Tayeh <info@tayeh.me>
2023-08-08 18:05:02 +03:00
06587c1dca rm redundant tests
Signed-off-by: Evedel <svbiriukov@gmail.com>
2023-08-02 14:19:15 +03:00
bc9168b039 add no-normalize flag
Signed-off-by: Evedel <svbiriukov@gmail.com>
2023-08-02 14:19:15 +03:00
57c527c2c9 add edits from review
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-08-02 14:19:15 +03:00
d1f5ac9edc convert build context path to absolute during final normalisation
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-08-02 14:19:15 +03:00
0164c1db56 Simplify the fix using or.
Signed-off-by: Natanael Arndt <arndtn@gmail.com>
2023-07-26 17:32:14 +03:00
e5cdce4e7d default to an empty dict for the from service if the service is None
Signed-off-by: Natanael Arndt <arndtn@gmail.com>
2023-07-26 17:32:14 +03:00
280f1770bf Add a test to extend using an empty service (placeholder)
Signed-off-by: Natanael Arndt <arndtn@gmail.com>
2023-07-26 17:32:14 +03:00
f75d12af21 broken in py 3.7 2023-07-18 13:23:55 +03:00
5454c3ad0f Add 'links' aliases to container aliases
Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
2023-07-18 13:14:57 +03:00
901adf47d0 Use defined environment variables in the image build process
Build images with service environment variables defined so that they can be
used in the build process

Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
2023-07-18 13:13:33 +03:00
bf07e91163 Implement include from compose-spec
Signed-off-by: Mahmoud Abduljawad <mahmoud@masaar.com>
2023-07-18 13:05:46 +03:00
c31b4e2816 Fixes #723: merge short & long syntax of depends_on dependencies
Signed-off-by: Hedayat Vatankhah <hedayat.fwd@gmail.com>
2023-07-08 04:10:43 +03:30
3890eacf57 Merge branch 'Evedel-allow-config-to-merge-strings-and-dicts-in-build' into devel 2023-05-29 11:47:41 +03:00
cfd24cc2e8 Merge branch 'devel' into allow-config-to-merge-strings-and-dicts-in-build
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-05-06 18:14:44 +10:00
79bfad103c move logic from rec_merge to normalize_service
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-05-06 10:42:44 +03:00
d1509468c3 allow empty list to be a command/entrypoint
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-05-06 10:42:44 +03:00
9011e9faa1 add tests, dry up code, use shlex.split instead of str.split
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-05-06 10:42:44 +03:00
517aeba330 Allow config to merge strings and lists in command and entrypoint
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-05-06 10:42:44 +03:00
85d5d5dcc9 move logic from rec_merge to normalize_service
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-05-06 15:17:54 +10:00
1ffd24dcf9 Python version support: sync verified and advertised versions
There are differences with regards to the versions of Python that are
verified (somehow) through Pylint, and the ones that are advertised.

Given that there's no pinning of Pylint versions, it shouldn't be
possible to use it on Python versions such as 3.5 and 3.6 (latest
Pylint doesn't support those).  With that, let's cover all the
currently supported Python versions.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
2023-05-06 00:28:13 +03:00
8c66b1cda7 add test case for when build is a complex dictionary
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-04-30 15:37:52 +10:00
a0005db474 add code implementing build value merge
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-04-29 13:52:19 +10:00
221cf14501 add tests for build value merge
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-04-29 13:17:43 +10:00
a61945b516 fix format
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-04-21 20:47:53 +03:00
6b6330c587 add build subcommand and --build arg to compose_run
Signed-off-by: Sergei Biriukov <svbiriukov@gmail.com>
2023-04-21 20:47:53 +03:00
5d279c4948 Build-fail test example
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-12 22:25:33 +03:00
5a3bdbf89b Exit code managed at PodmanCompose.run()
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-12 22:25:33 +03:00
1eb166445b Linting fixes
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-12 22:25:33 +03:00
82182b7bc6 Finish execution in compose_build only on command=build calls
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-12 22:25:33 +03:00
3f4618866b Update project-1.env 2023-04-10 14:14:14 +03:00
91bc6ebdb4 Keep chdir after loading env file
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-10 14:14:14 +03:00
59a59c1a3a Fixes #636: env-file shall be resolved relative to the CWD
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-10 14:14:14 +03:00
620f5d7473 pre-commit black config: run in check only mode
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-10 14:13:00 +03:00
6f902faed0 Fix linting issues
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-10 14:12:32 +03:00
ccdf01e9b0 Revert "Use SELinux mount flag for secrets"
This reverts commit 874192568f.
2023-04-10 12:26:53 +03:00
e6b1eabe4c Revert "Use more lenient SELinux mount flag for secrets"
This reverts commit 75de39c239.
2023-04-10 12:26:53 +03:00
75de39c239 Use more lenient SELinux mount flag for secrets
Signed-off-by: Henry Reed <60915078+henryreed@users.noreply.github.com>
2023-04-10 12:25:53 +03:00
874192568f Use SELinux mount flag for secrets
Signed-off-by: Henry Reed <github.69ofd@simplelogin.com>
2023-04-10 12:25:53 +03:00
0b853f29f4 Ignore access mode when merging volumes short syntax
The target path inside the container is treated as a key. Ref:
https://github.com/compose-spec/compose-spec/blob/master/spec.md#merging-service-definitions

Signed-off-by: Bhavin Gandhi <bhavin7392@gmail.com>
2023-04-10 12:25:05 +03:00
847f01a6c6 Add a docker-compose test file for uidmaps/gidmaps
Add a simple docker-compose.yml test to use the x-podman extension with
uidmaps and gitmaps
2023-04-10 12:22:25 +03:00
e511e6420f FIXES #228: Add support for uidmap and gidmap
Implement an x-podman extension on the level of the individual services
to handle `--uidmap` and `--gidmap`
2023-04-10 12:22:25 +03:00
a9723ec1cf Added a way to start containers with multiple ips and nets
Signed-off-by: KuhnChris <kuhnchris@kuhnchris.eu>
2023-04-10 12:16:54 +03:00
1cb608d8a7 allow project name to be fetched from dotenv
Look for project name in `self.environ` which includes both `os.environ`
and dotenv variables so that the project name can also be defined in an
environment file.

Signed-off-by: Kuan-Yi Li <kyli@abysm.org>
2023-04-10 12:13:23 +03:00
252f1d57a5 updating black formatting for podman-compose.py
Signed-off-by: Dixon Whitmire <dixonwh@gmail.com>
2023-04-10 12:12:18 +03:00
13856d2e9c updating black formatting
Signed-off-by: Dixon Whitmire <dixonwh@gmail.com>
2023-04-10 12:12:18 +03:00
8d8df0bc28 Adding basic support for --profile argument
Signed-off-by: Dixon Whitmire <dixonwh@gmail.com>
2023-04-10 12:12:18 +03:00
bc5f0123d9 add option to start podman in existing network namespace 2023-04-10 12:11:02 +03:00
9a08f85ffd FIXES #586: preserve exit code for podman-compose build
Signed-off-by: Roman Blanco <rblanco@redhat.com>
2023-04-10 12:10:16 +03:00
8625d7a4e8 add ipam-driver support
Signed-off-by: Benedikt Braunger <bb@emlix.com>
2023-04-10 12:02:47 +03:00
016c97fd1e Fixes #663 - Fixes linting/pylint errors
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-10 11:53:47 +03:00
2df11674c4 Fixes #661 - Fixes linting/flake8 errors
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-10 11:53:47 +03:00
5eff38e743 Fixes #659: fix permissions when installing OS packages for linting/black
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-10 11:28:07 +03:00
7f5ce26b1b start version 1.0.7 and default with pod enabled by default 2023-04-09 14:08:54 +03:00
f6dbce3618 version 1.0.6 2023-04-09 14:02:10 +03:00
dfb64d884d fix pylint 2023-04-09 13:10:33 +03:00
990f774659 fix pylint 2023-04-09 12:47:15 +03:00
5e518c7ca7 #648: check if sed exists to color logs 2023-04-09 12:07:43 +03:00
9046f7eee0 #634: follow up 2023-04-09 12:00:45 +03:00
ef55067834 add support for network priorities
Signed-off-by: Benedikt Braunger <bb@emlix.com>
2023-04-09 11:44:21 +03:00
ed2a6c0917 Support network_mode: none
Fixes #566
2023-04-09 11:36:30 +03:00
b4c0792995 Add --remove-orphans on down command
Signed-off-by: Sander Hoentjen <shoentjen@antagonist.nl>
2023-04-09 11:35:46 +03:00
e84451f4ea Allow environment parameters without value
Signed-off-by: Sander Hoentjen <shoentjen@antagonist.nl>
2023-04-09 11:34:25 +03:00
456370bd46 Support build secrets
Signed-off-by: Excedrin <290525+Excedrin@users.noreply.github.com>
2023-04-09 11:33:45 +03:00
efe3714266 Add support for the group_add property of a service. 2023-04-09 11:33:16 +03:00
c55a2f4c26 Fixes #657: Support act and developer-friendly environment
Signed-off-by: BugFest <bugfest.dev@pm.me>
2023-04-09 11:31:12 +03:00
b8a7593026 #154: timeout 2023-03-29 11:30:24 +03:00
bd29ddb3e9 #154: no -t for start 2023-03-29 01:31:42 +03:00
38219eb85c FIXES #154: handle stop_grace_period 2023-03-28 17:33:02 +03:00
08ffcf6126 updating test_podman_compose_extends_w_file_subdir to use the correct image name
Signed-off-by: Dixon Whitmire <dixonwh@gmail.com>
2022-10-28 00:13:56 +02:00
801faea30b Bump actions/setup-python from 2 to 4
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 4.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v2...v4)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-19 00:00:10 +03:00
06da9667f3 Bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-18 23:59:50 +03:00
de3f607758 Check for github actions updates weekly
Signed-off-by: John Losito <lositojohnj@gmail.com>
2022-10-17 18:15:27 +03:00
db1861d33f pull: accept service names as positional arguments
Fixes #547

Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
2022-09-01 23:07:56 +03:00
9d5b255927 Use top-level name property as project name if user doesn't set one explicitly
Signed-off-by: Simon Cornish <7t9jna402@sneakemail.com>
2022-08-18 10:00:28 +03:00
2d05c5c339 FIXES #534: add systemd unit label 2022-07-29 21:13:44 +03:00
3c460160e0 FIXES #534: add systemd unit label 2022-07-29 21:13:07 +03:00
5b9cfe5d17 implement services.*.build.tags
https://github.com/compose-spec/compose-spec/blob/master/build.md#tags
2022-07-28 02:25:49 +03:00
8d1a4d7274 Implemented basic Bash shell completion
Signed-off-by: Carmine Zaccagnino <carmine@carminezacc.com>
2022-07-20 00:33:22 +03:00
859f03cbe6 Add healthcheck.disable support
Signed-off-by: inganault <p.po.oo.on.n@gmail.com>
2022-07-14 23:33:16 +03:00
ae6be272b5 reformat 2022-07-14 00:59:10 +03:00
ccdb98c0e4 implement podman kill command
Signed-off-by: Mohammed Tayeh <info@tayeh.me>
2022-07-14 00:55:33 +03:00
909d05e718 reformat 2022-07-13 20:45:16 +03:00
0cf98c7893 reimplement the of pause and unpause commands
Signed-off-by: Mohammed Tayeh <info@tayeh.me>
2022-07-13 20:31:46 +03:00
843b876885 fix typo
Signed-off-by: Mohammed Tayeh <info@tayeh.me>
2022-07-13 20:31:46 +03:00
1188463734 fix Typo podman-composer in version command
Signed-off-by: Mohammed Tayeh <info@tayeh.me>
2022-07-13 20:31:46 +03:00
10580db329 Add pause,unpause commands support
Signed-off-by: Mohammed Tayeh <info@tayeh.me>
2022-07-13 20:31:46 +03:00
f7d335dc6a #516: allow empty network 2022-07-04 18:21:31 +03:00
4a73ae86bc FIXES #511: ipv6 2022-06-29 12:03:54 +03:00
f674ab8cfb #512: only use --net when bridge 2022-06-29 11:55:39 +03:00
265e0ca32a #512: only use --net when bridge 2022-06-29 10:46:47 +03:00
92662f3409 FIXES #511: ipv6 2022-06-28 15:58:19 +03:00
42c0078e6b mac_address with dash 2022-06-22 14:24:34 +03:00
da5ee723c3 reformat 2022-06-21 21:54:44 +03:00
06fc0715fe reformat 2022-06-21 21:51:09 +03:00
9eda56caf9 FIXES #507: respecte mac_address 2022-06-21 21:48:45 +03:00
13c8981c6d Fix help message for systemd subcommand
- Fix wording in docstring about initial setup of systemd service.
- Trim extra indentation at start of multiline docstrings.

Signed-off-by: Stefan Marinov <smarnv@dnl.sk>
2022-05-15 17:50:27 +03:00
ee7029fbde reformat 2022-05-10 02:32:08 +03:00
75033a4ed7 add python demo example 2022-05-10 02:28:17 +03:00
c175fd1b10 reformat 2022-05-10 01:30:03 +03:00
d479001454 reference awesome-compose 2022-05-10 01:27:52 +03:00
a2defdd06a example wordpress 2022-05-10 01:24:06 +03:00
c55cd67bd2 #307: default to /etc/ 2022-05-10 01:13:34 +03:00
eed38ce76c Fixed accidental deletion of project functionality. 2022-05-10 01:11:32 +03:00
86ffad86c7 Added port subcommand. 2022-05-10 01:11:32 +03:00
118d39b5bb Fix linter errors 2022-05-10 01:10:29 +03:00
814bd2a31a Support driver_opts for networks 2022-05-10 01:10:29 +03:00
606b9d94c8 Simplify var assignment 2022-04-29 17:11:58 +03:00
0057a4bb31 Fix default external name in dict case 2022-04-29 17:11:58 +03:00
8ecb74916d Update external volume name management 2022-04-29 17:11:58 +03:00
d983056982 Update external volume name management 2022-04-29 17:11:58 +03:00
ed302ca518 Fix external volume name when no name provided 2022-04-29 17:11:58 +03:00
0b5c844431 Add runtime error if no external volume exists 2022-04-29 17:11:58 +03:00
9c29c8914f FIXES #486: replace realpath with abspath 2022-04-27 13:01:24 +03:00
89d2062579 Fixed some spelling and grammar issues
Signed-off-by: Bastian Venthur <bastian.venthur@flixbus.com>
2022-04-25 10:49:39 +03:00
Muz
f42b568fc2 Correct the help text for --pod-args
Signed-off-by: Muz <git@mustaqila.li>
2022-04-10 22:21:35 +03:00
a1d3ba4ea2 Lint fixes for --services flag handling in config
Signed-off-by: Muz Ali <muz.ali@shopify.com>
2022-04-07 08:25:03 +03:00
6be661f6da Support platform property
As per https://github.com/compose-spec/compose-spec/blob/master/spec.md#platform

Example:

```
services:
  mysql:
    image: mysql:5.7
    platform: linux/x86_64
```

Signed-off-by: Shane Smith <shane.smith@shopify.com>
2022-04-07 08:24:46 +03:00
Muz
fc3598faf2 Allow --services in config
Signed-off-by: Muz <git@mustaqila.li>
2022-04-04 11:20:41 +03:00
fbff315e18 FIXES #464: accept -v in run 2022-03-29 21:17:02 +03:00
fc34703dd4 format 2022-03-28 14:07:36 +03:00
c7ada820de format 2022-03-28 13:54:55 +03:00
5e286f6356 format 2022-03-28 13:52:21 +03:00
3dd8b05d74 format 2022-03-28 13:47:28 +03:00
3ecb4b5dd5 FIXES #462: fix extends merge 2022-03-28 13:40:02 +03:00
d05cad4c65 FIXES #462: fix extends merge 2022-03-28 13:32:22 +03:00
ebb3dfe634 #452: better missing network message 2022-03-20 17:16:59 +03:00
7b99b38f0e nethost test 2022-03-19 00:17:22 +03:00
4ef8afc63e hit counter with redis cluster example 2022-03-19 00:12:48 +03:00
a1aed09a58 GCR hello app 2022-03-18 23:14:26 +03:00
2cacf9cfb5 add echo example 2022-03-18 23:00:21 +03:00
4064c84521 add azure vote example 2022-03-18 22:43:18 +03:00
0dde95ac1d update gitignore 2022-03-18 18:34:01 +03:00
1be41b46a5 do not merge command array 2022-03-18 18:29:27 +03:00
105c27c8dc example nodejs project 2022-03-18 18:05:57 +03:00
f820594257 use exec for wait 2022-03-18 15:50:24 +03:00
8a72321720 FIXES #409: detect changes and recreate 2022-03-16 15:27:30 +03:00
529391963d FIXES #409: detect changes and recreate 2022-03-16 15:25:57 +03:00
48a19f13fc print more help with systemd 2022-03-15 23:01:22 +03:00
a9faabb1b0 print more help with systemd 2022-03-15 22:50:03 +03:00
3fb2b98ecc print more help with systemd 2022-03-15 22:47:54 +03:00
b35b7e448a add systemd -a list 2022-03-14 14:17:49 +03:00
1a72e1e087 add systemd -a list 2022-03-14 14:05:20 +03:00
b620311aaf FIXES #449: accept int port 2022-03-13 23:36:25 +03:00
bf8004b04d systemd unit file 2022-03-13 11:20:59 +03:00
cadf046306 fix pylint 2022-03-13 10:18:03 +03:00
8d8149cfe5 fix pylint 2022-03-13 10:12:36 +03:00
3dd981727b fix pylint 2022-03-13 10:08:48 +03:00
0b469e0590 format 2022-03-12 23:17:26 +03:00
9e3020a9df FIXES #307: systemd command 2022-03-12 23:08:24 +03:00
fc9ed19b2b wait command 2022-03-12 21:16:16 +03:00
2d6bb52e36 FIXES #442: allow --no-pod or custom --pod-args 2022-03-08 21:22:43 +03:00
7942a091c3 FIXES #442: allow --no-pod or custom --pod-args 2022-03-08 21:13:14 +03:00
701311aa7a FIXES #447: support --env-file 2022-03-08 12:01:02 +03:00
d7049150d0 FIXES #447: support --env-file 2022-03-08 10:57:44 +03:00
3b7bf81051 remove unused test 2022-03-08 10:47:16 +03:00
a735aa5b96 Fix inverted condition in merging arguments
Signed-off-by: Tom Bu <tombu@tombu.info>
2022-03-02 06:12:26 +03:00
b78509527b Fix linter issues
Make _cmd_desc a public attribute, so that it can be used outside of the
class methods.

Signed-off-by: Piotr Husiatyński <phusiatynski@gmail.com>
2022-03-01 17:16:04 +03:00
762318093c Force black formatting
Black removes the burden of manual code formatting and is by now
considered the standard Python formatting tool.

https://black.readthedocs.io/en/stable/

Format all Python code with black.

GitHub linting action is updated to ensure all files are formatted with
Black.

Signed-off-by: Piotr Husiatyński <phusiatynski@gmail.com>
2022-03-01 17:16:04 +03:00
af10345483 FIXES #440: absolute secret 2022-02-28 01:19:39 +03:00
2d1bcddf09 update readme 2022-02-26 03:13:38 +03:00
4f025679cf add unit tests 2022-02-26 03:10:35 +03:00
064521255b add badge 2022-02-26 02:58:26 +03:00
b7c5609603 pylint 2022-02-26 02:51:06 +03:00
44508352e8 pylint 2022-02-26 02:49:34 +03:00
5c33e4efbb pylint 2022-02-26 01:41:07 +03:00
cbd6f6b1b6 pylint cleanups 2022-02-26 00:48:42 +03:00
de1e59d1d5 fix some pylint 2022-02-25 23:59:15 +03:00
2f0ca9e41d add pytest ci 2022-02-25 21:50:52 +03:00
59c9a69689 add pylint 2022-02-25 21:42:32 +03:00
b7eac1e898 pylint 2022-02-25 21:39:10 +03:00
0d47e470fc activate test 2022-02-25 21:30:15 +03:00
c2d7b26f2e #434: handle unknown service 2022-02-25 21:13:10 +03:00
1e895c0873 calc proper hash 2022-02-25 18:56:36 +03:00
132a22b524 #130: handle nested extend and normalize build context 2022-02-25 18:32:19 +03:00
0bde01de07 remove unused imports
Signed-off-by: kjunker <junker.kurt@googlemail.com>
2022-02-22 13:26:44 +02:00
91a579b81e Adding Test that the changes can build Image from build context of extended compose-file
Signed-off-by: kjunker <junker.kurt@googlemail.com>
2022-02-22 13:26:44 +02:00
56b88639ad Fixing subdirectory from extends where extended service will build a Service from Dockerfile in an own subdirectory
Signed-off-by: kjunker <junker.kurt@googlemail.com>
2022-02-22 13:26:44 +02:00
5c3ec5f49a FIXES #431: support dns 2022-02-20 22:11:15 +02:00
779198b003 #379: no infra container 2022-02-17 17:19:25 +02:00
40cb6a760e log version 2022-02-17 13:36:44 +02:00
4fd9d86e17 #379: nothing shared in the pod to allow hostname 2022-02-17 13:28:31 +02:00
2a2c3a09c1 Fix timeout value data type
Signed-off-by: Devansh Sharma <devansh.sharma@gmail.com>
2022-02-17 10:16:39 +02:00
80e852717d #379: create a pod 2022-02-15 01:55:28 +02:00
d6e21dc752 FIXES #425: pass --requires 2022-02-15 01:33:00 +02:00
b9b2f83d04 FIXES #415: allow network_mode=slirp4netns 2022-02-12 17:39:42 +02:00
9af65ea112 adjust comment 2022-02-12 17:35:04 +02:00
3e6e268034 test for logs 2022-02-12 13:54:30 +02:00
af6a3069ce fix syntax error without a new line
Signed-off-by: Cody Hutchins <codyhutchins@seed-innovations.com>
2022-02-12 13:47:45 +02:00
68f745fe62 referenced unmerged pr #192 to bring colors into container logging
Signed-off-by: Cody Hutchins <codyhutchins@seed-innovations.com>
2022-02-12 13:47:45 +02:00
90dcfdbf44 FIXES #420: document -t 2022-02-12 13:42:00 +02:00
ed8635a9a3 FIXES #422: Remove debug print
Signed-off-by: Geoffroy Doucet <geoffroy.doucet@kloodz.com>
2022-02-12 13:35:58 +02:00
1d972ef174 Propagate all bind-type mount options
Before this commit, adding multiple options to a bind-type mount
(e.g. /foo/bar:/baz:Z,U) would result in a podman command in which
only the last option would be used (e.g. U).

This is because when parsing the mount string, a loop would go over
each mount option and assign it to mount_opt_dict, this meant that
this dict was overridden for each option, thus only the last option
in the mount string would be kept and passed onto podman.

This commit solves this by appending to a temporary list and then
converting it to a comma-separated string and assigning it to the
mount_opt_dict.

Fixes #412

Signed-off-by: Adrian Torres <atorresj@redhat.com>
2022-02-12 13:27:49 +02:00
536925ca78 FIXES #413: parse network_mode: container:container_name correctly
Signed-off-by: Bernd Schoolmann <mail@quexten.com>
2022-01-30 14:55:21 +02:00
09c6cbe503 FIXES #408: preserve exit code 2022-01-22 00:24:17 +02:00
154a51245f FIXES #386: make sure volumes are present in top level 2022-01-22 00:15:05 +02:00
523d215b48 #407: allow network_mode=service:mysrv 2022-01-18 20:40:29 +02:00
25494b5f6e Update README.md 2022-01-18 17:57:37 +02:00
19662c02a1 Fix healthcheck test type on replicas 2022-01-15 20:22:05 +02:00
4943e52344 #395: make podman respect PODMAN_* in .env 2022-01-12 22:06:47 +02:00
4aa08cd016 FIXES #399: pass specific ip 2022-01-12 21:48:42 +02:00
15e0ab9261 FIXES #397: support host network mode 2022-01-12 15:44:47 +02:00
f66861f89a #249: read COMPOSE_PROJECT_NAME env 2022-01-12 15:37:07 +02:00
af53b65068 Simplify volume identification
The filtering provided by "volume ls" did not work as expected
in previous versions of podman:
https://github.com/containers/podman/pull/8345

Verified that this now works properly on podman 3.4.4

Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
2022-01-06 17:39:52 +02:00
890c584881 Update README.md 2022-01-04 16:18:20 +02:00
0bd493f1ba Allow empty default/error value in substitution 2021-12-31 18:40:26 +02:00
481c6d0a41 #394: config: multiple yaml 2021-12-31 01:54:32 +02:00
31df70b8d2 updated per maintainer review 2021-12-31 01:39:03 +02:00
df400518a7 removes version from CONTRIBUTING 2021-12-31 01:39:03 +02:00
21a716cfd3 added log back in 2021-12-31 01:39:03 +02:00
f00ac92640 added config command 2021-12-31 01:39:03 +02:00
0433410702 added args for version 2021-12-31 01:39:03 +02:00
0f9fe2bf9f FiXES #393: missing arg when build as part of run 2021-12-31 01:17:26 +02:00
a1be5ce6b3 add fallback to get 2021-12-31 00:06:48 +02:00
56a4988481 Add support for volume driver and options 2021-12-31 00:04:58 +02:00
377b5525c9 Fix substitution for empty variables 2021-12-31 00:00:10 +02:00
c50599c0e7 FIXES #388: do not force build in run 2021-12-28 21:03:21 +02:00
4557279930 #88: multiple aliases 2021-12-25 21:06:29 +02:00
7ad377557d FIXES #380: output to stderr 2021-12-24 18:55:30 +02:00
30051c2f5b Update README.md. Add link to podman dns plugin source 2021-12-24 14:05:46 +02:00
9e8e25c159 #378: down -v 2021-12-23 01:17:34 +02:00
2c60516f77 fix hostname in test 2021-12-23 00:34:01 +02:00
24ec539932 release 1.0.3 2021-12-21 23:15:52 +02:00
2803046ac3 add awx 17 example 2021-12-21 22:57:45 +02:00
d1768c1d9d FIXES #377: down -v 2021-12-21 22:57:45 +02:00
820ea012c5 FIXES #: U mount propagation option 2021-12-21 22:57:45 +02:00
5ba96a1082 #365: 'Namespace' object has no attribute 'volumes' 2021-12-21 22:57:45 +02:00
49fe6e7e0f Update README.md 2021-12-18 23:34:32 +02:00
6c1ccfcefa Add missing arguments to the log (latest, names, since, until) 2021-12-14 11:35:30 +02:00
724d2fd18c Support viewing all logs 2021-12-14 11:35:30 +02:00
3e940579d9 Support for starting/stopping/restarting all services
Reverse services when stopping or restarting
2021-12-14 11:35:30 +02:00
af1697e9bf FIXES #288: extenal as dict 2021-12-13 03:25:17 +02:00
e62f1a54af FIXES #288: extenal as dict 2021-12-13 01:21:34 +02:00
179f9ab0e3 FIXES #288: do not create external network 2021-12-13 00:24:23 +02:00
dd6b1ee88c FIXES #288: do not create external network 2021-12-13 00:21:53 +02:00
9a8dc4ca17 release 1.0.2 2021-12-11 02:06:10 +02:00
6b5f62d693 Fixes #199: seccomp:unconfined 2021-12-11 01:50:40 +02:00
3782b4ab84 FIXES #371: respect COMPOSE_FILE env 2021-12-10 23:26:13 +02:00
95e07e27f0 FIXES #185: creates dirs 2021-12-10 22:46:22 +02:00
a3123ce480 #222: normalize basedir using os.path.realpath 2021-12-10 22:27:00 +02:00
02f78dc3d7 FIXES #333: when volumes are merged, remove duplicates 2021-12-10 02:06:43 +02:00
8cd97682d0 FIXES #370: bug-for-bug hanlding of .env 2021-12-10 01:01:45 +02:00
85244272ff FIXES #368: parse depends_on of type dict 2021-12-09 16:18:52 +02:00
30cfe2317c set version 2021-12-09 16:12:59 +02:00
7fda1cc835 fix AttributeError when running a one-off command
Without this, I get errors when running "podman-compose -p podname run".
2021-12-09 16:11:04 +02:00
5f40f4df31 Remove named volumes during "down -v"
Fixes containers#105

Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
2021-12-09 16:09:59 +02:00
d38aeaa713 update README 2021-12-09 15:59:34 +02:00
17f9ca61bd test fixes for SELinux (Fedora) 2021-11-24 18:06:18 +02:00
80a47a13d5 add network-alias 2021-11-21 12:35:13 +02:00
872404c3a7 initial work on CNI podman network create 2021-11-21 01:23:29 +02:00
156 changed files with 8109 additions and 1118 deletions

1
.codespellignore Normal file
View File

@ -0,0 +1 @@
assertIn

4
.codespellrc Normal file
View 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
View File

@ -0,0 +1,2 @@
[run]
parallel=True

19
.editorconfig Normal file
View 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

View File

@ -35,7 +35,7 @@ What is the behavior you actually got and that should not happen.
```
$ podman-compose version
using podman version: 3.4.0
podman-composer version 0.1.7dev
podman-compose version 0.1.7dev
podman --version
podman version 3.4.0

10
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View 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.

6
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

22
.github/workflows/codespell.yml vendored Normal file
View 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

25
.github/workflows/static-checks.yml vendored Normal file
View 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
View 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
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
- name: Run tests in tests/
run: |
python -m unittest -v tests/*.py
env:
TESTS_DEBUG: 1
- name: Run tests in pytests/
run: |
coverage run --source podman_compose -m unittest pytests/*.py
- name: Report coverage
run: |
coverage combine
coverage report --format=markdown | tee -a $GITHUB_STEP_SUMMARY

5
.gitignore vendored
View File

@ -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

36
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,36 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.10
types: [python]
args: [
"--check", # Don't apply changes automatically
]
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
types: [python]
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
[
"-rn", # Only display messages
"-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

View File

@ -1,13 +1,18 @@
[MESSAGES CONTROL]
disable=W0614,C0410,C0321,C0111,I0011,C0103
# C0111 missing-docstring: missing-class-docstring, missing-function-docstring, missing-method-docstring, missing-module-docstrin
# consider-using-with: we need it for color formatter pipe
disable=too-many-lines,too-many-branches,too-many-locals,too-many-statements,too-many-arguments,too-many-instance-attributes,fixme,multiple-statements,missing-docstring,line-too-long,consider-using-f-string,consider-using-with,unnecessary-lambda-assignment
# allow _ for ignored variables
# allow generic names like a,b,c and i,j,k,l,m,n and x,y,z
# allow k,v for key/value
# allow e for exceptions, it for iterator
# allow e for exceptions, it for iterator, ix for index
# allow ip for ip address
# allow w,h for width, height
# allow op for operation/operator/opcode
# allow t, t0, t1, t2, and t3 for time
# allow dt for delta time
# allow db for database
# allow ls for list
good-names=_,a,b,c,dt,db,e,f,fn,fd,i,j,k,v,kv,kw,l,m,n,ls,t,t0,t1,t2,t3,w,h,x,y,z,it,op
# allow p for pipe
# allow ex for examples, exists ..etc
good-names=_,a,b,c,dt,db,e,f,fn,fd,i,j,k,v,kv,kw,l,m,n,ls,t,t0,t1,t2,t3,w,h,x,y,z,it,ix,ip,op,p,ex

View File

@ -1,74 +1,141 @@
# Contributing to podman-compose
## Who can contribute?
- 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.
## Branches
Please request your pull request to be merged into the `devel` branch.
Changes to the `stable` branch are managed by the repository maintainers.
## Development environment setup
Note: Some steps are OPTIONAL but all are RECOMMENDED.
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 pytests/*.py
$ python -m unittest tests/*.py
$ 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:devel` 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
kill Kill containers
logs View output from containers
pause Pause services
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
unpause Unpause services
version Show the Docker-Compose version information
```

View File

@ -1,46 +1,62 @@
# Podman Compose
## [![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 `docker-compose` with [Podman](https://podman.io/) backend.
The main objective of this project is to be able to run `docker-compose.yml` unmodified and rootless.
This project is aimed to provide drop-in replacement for `docker-compose`,
and it's very useful for certain cases because:
An implementation of [Compose Spec](https://compose-spec.io/) with [Podman](https://podman.io/) backend.
This project focuses on:
- can run rootless
- no daemon, no setup.
- can be used by developers to run single-machine containerized stacks using single familiar YAML file
* rootless
* daemon-less process model, we directly execute podman, no running daemon.
This project only depend 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. 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/)
And it's formed as a single python file script that you can drop into your PATH and run.
And it's formed as a single Python file script that you can drop into your PATH and run.
## References:
* [spec.md](https://github.com/compose-spec/compose-spec/blob/master/spec.md)
* [docker-compose compose-file-v3](https://docs.docker.com/compose/compose-file/compose-file-v3/)
* [docker-compose compose-file-v2](https://docs.docker.com/compose/compose-file/compose-file-v2/)
## Alternatives
As in [this article](https://fedoramagazine.org/use-docker-compose-with-podman-to-orchestrate-containers-on-fedora/) you can setup a `podman.socket` and use unmodified `docker-compose` that talks to that socket but in this case you lose the process-model (ex. `docker-compose build` will send a possibly large context tarball to the daemon)
For production-like single-machine containerized environment consider
- [k3s](https://k3s.io) | [k3s github](https://github.com/rancher/k3s)
- [MiniKube](https://minikube.sigs.k8s.io/)
- [MiniShift](https://www.okd.io/minishift/)
For the real thing (multi-node clusters) check any production
OpenShift/Kubernetes distribution like [OKD](https://www.okd.io/minishift/).
OpenShift/Kubernetes distribution like [OKD](https://www.okd.io/).
## Versions
If you have legacy version of `podman` (before 3.x) you might need to stick with legacy `podman-compose` `0.1.x` branch.
If you have legacy version of `podman` (before 3.1.0) you might need to stick with legacy `podman-compose` `0.1.x` branch.
The legacy branch 0.1.x uses mappings and workarounds to compensate for rootless limitations.
Modern podman versions (>=3.4) do not have those limitations and thus you can use latest and stable 1.x branch.
Modern podman versions (>=3.4) do not have those limitations, and thus you can use latest and stable 1.x branch.
If you are upgrading from `podman-compose` version `0.1.x` then we no longer have global option `-t` to set mapping type
like `hostnet`. If you desire that behavior, pass it the standard way like `network_mode: host` in the YAML.
## Installation
Install latest stable version from PyPI:
### Pip
```
Install the latest stable version from PyPI:
```bash
pip3 install podman-compose
```
@ -48,37 +64,44 @@ 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
```
or
### Homebrew
```bash
brew install podman-compose
```
curl -o /usr/local/bin/podman-compose https://raw.githubusercontent.com/containers/podman-compose/devel/podman_compose.py
### 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
or inside your home
```
curl -o ~/.local/bin/podman-compose https://raw.githubusercontent.com/containers/podman-compose/devel/podman_compose.py
```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
```
## Basic Usage
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
@ -95,19 +118,21 @@ which have
- a django tasks
When testing the `AWX3` example, if you got errors just wait for db migrations to end.
When testing the `AWX3` example, if you got errors, just wait for db migrations to end.
There is also AWX 17.1.0
## Tests
Inside `tests/` directory we have many useless docker-compose stacks
that are meant to test as much cases as we can to make sure we are compatible
that are meant to test as many cases as we can to make sure we are compatible
## How it works
### Unit tests with unittest
run a unittest with following command
The default mapping `1podfw` creates a single pod and attach all containers to
its network namespace so that all containers talk via localhost.
For more information see [docs/Mappings.md](docs/Mappings.md).
```shell
python -m unittest pytests/*.py
```
If you are running as root, you might use identity mapping.
# Contributing guide
If you are a user or a developer and want to contribute please check the [CONTRIBUTING](CONTRIBUTING.md) section

View File

@ -0,0 +1,411 @@
# Naming convention:
# * _camelCase for function names
# * snake_case for variable names
# all functions will return 0 if they successfully complete the argument
# (or establish there is no need or no way to complete), and something
# other than 0 if that's not the case
# complete arguments to global options
_completeGlobalOptArgs() {
# arguments to options that take paths as arguments: complete paths
for el in ${path_arg_global_opts}; do
if [[ ${prev} == ${el} ]]; then
COMPREPLY=( $(compgen -f -- ${cur}) )
return 0
fi
done
# arguments to options that take generic arguments: don't complete
for el in ${generic_arg_global_opts}; do
if [[ ${prev} == ${el} ]]; then
return 0
fi
done
return 1
}
# complete root subcommands and options
_completeRoot() {
# if we're completing an option
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${global_opts}" -- ${cur}) )
return 0
fi
# complete root commands
COMPREPLY=( $(compgen -W "${root_commands}" -- ${cur}) )
return 0
}
# complete names of Compose services
_completeServiceNames() {
# ideally we should complete service names,
# but parsing the compose spec file in the
# completion script is quite complex
return 0
}
# complete commands to run inside containers
_completeCommand() {
# we would need to complete commands to run inside
# a container
return 0
}
# complete the arguments for `podman-compose up` and return 0
_completeUpArgs() {
up_opts="${help_opts} -d --detach --no-color --quiet-pull --no-deps --force-recreate --always-recreate-deps --no-recreate --no-build --no-start --build --abort-on-container-exit -t --timeout -V --renew-anon-volumes --remove-orphans --scale --exit-code-from --pull --pull-always --build-arg --no-cache"
if [[ ${prev} == "--scale" || ${prev} == "-t" || ${prev} == "--timeout" ]]; then
return 0
elif [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${up_opts}" -- ${cur}) )
return 0
else
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose exec` and return 0
_completeExecArgs() {
exec_opts="${help_opts} -d --detach --privileged -u --user -T --index -e --env -w --workdir"
if [[ ${prev} == "-u" || ${prev} == "--user" || ${prev} == "--index" || ${prev} == "-e" || ${prev} == "--env" || ${prev} == "-w" || ${prev} == "--workdir" ]]; then
return 0
elif [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${exec_opts}" -- ${cur}) )
return 0
elif [[ ${comp_cword_adj} -eq 2 ]]; then
# complete service name
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
elif [[ ${comp_cword_adj} -eq 3 ]]; then
_completeCommand
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose down` and return 0
_completeDownArgs() {
down_opts="${help_opts} -v --volumes -t --timeout --remove-orphans"
if [[ ${prev} == "-t" || ${prev} == "--timeout" ]]; then
return 0
elif [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${down_opts}" -- ${cur}) )
return 0
else
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose build` and return 0
_completeBuildArgs() {
build_opts="${help_opts} --pull --pull-always --build-arg --no-cache"
if [[ ${prev} == "--build-arg" ]]; then
return 0
elif [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${build_opts}" -- ${cur}) )
return 0
else
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose logs` and return 0
_completeLogsArgs() {
logs_opts="${help_opts} -f --follow -l --latest -n --names --since -t --timestamps --tail --until"
if [[ ${prev} == "--since" || ${prev} == "--tail" || ${prev} == "--until" ]]; then
return 0
elif [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${logs_opts}" -- ${cur}) )
return 0
else
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose ps` and return 0
_completePsArgs() {
ps_opts="${help_opts} -q --quiet"
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${ps_opts}" -- ${cur}) )
return 0
else
return 0
fi
}
# complete the arguments for `podman-compose pull` and return 0
_completePullArgs() {
pull_opts="${help_opts} --force-local"
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${pull_opts}" -- ${cur}) )
return 0
else
return 0
fi
}
# complete the arguments for `podman-compose push` and return 0
_completePushArgs() {
push_opts="${help_opts} --ignore-push-failures"
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${push_opts}" -- ${cur}) )
return 0
else
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose restart` and return 0
_completeRestartArgs() {
restart_opts="${help_opts} -t --timeout"
if [[ ${prev} == "-t" || ${prev} == "--timeout" ]]; then
return 0
elif [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${restart_opts}" -- ${cur}) )
return 0
else
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose stop` and return 0
_completeStopArgs() {
stop_opts="${help_opts} -t --timeout"
if [[ ${prev} == "-t" || ${prev} == "--timeout" ]]; then
return 0
elif [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${stop_opts}" -- ${cur}) )
return 0
else
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose start` and return 0
_completeStartArgs() {
start_opts="${help_opts}"
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${start_opts}" -- ${cur}) )
return 0
else
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
return 0
fi
}
# complete the arguments for `podman-compose run` and return 0
_completeRunArgs() {
run_opts="${help_opts} -d --detach --privileged -u --user -T --index -e --env -w --workdir"
if [[ ${prev} == "-u" || ${prev} == "--user" || ${prev} == "--index" || ${prev} == "-e" || ${prev} == "--env" || ${prev} == "-w" || ${prev} == "--workdir" ]]; then
return 0
elif [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${run_opts}" -- ${cur}) )
return 0
elif [[ ${comp_cword_adj} -eq 2 ]]; then
# complete service name
_completeServiceNames
if [[ $? -eq 0 ]]; then
return 0
fi
elif [[ ${comp_cword_adj} -eq 3 ]]; then
_completeCommand
if [[ $? -eq 0 ]]; then
return 0
fi
fi
}
_podmanCompose() {
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
root_commands="help version pull push build up down ps run exec start stop restart logs"
# options to output help text (used as global and subcommand options)
help_opts="-h --help"
# global options that don't take additional arguments
basic_global_opts="${help_opts} -v --no-ansi --no-cleanup --dry-run"
# global options that take paths as arguments
path_arg_global_opts="-f --file --podman-path"
path_arg_global_opts_array=($arg_global_opts)
# global options that take arguments that are not files
generic_arg_global_opts="-p --project-name --podman-path --podman-args --podman-pull-args --podman-push-args --podman-build-args --podman-inspect-args --podman-run-args --podman-start-args --podman-stop-args --podman-rm-args --podman-volume-args"
generic_arg_global_opts_array=($generic_arg_global_opts)
# all global options that take arguments
arg_global_opts="${path_arg_global_opts} ${generic_arg_global_opts}"
arg_global_opts_array=($arg_global_opts)
# all global options
global_opts="${basic_global_opts} ${arg_global_opts}"
chosen_root_command=""
_completeGlobalOptArgs
if [[ $? -eq 0 ]]; then
return 0
fi
# computing comp_cword_adj, which thruthfully tells us how deep in the subcommands tree we are
# additionally, set the chosen_root_command if possible
comp_cword_adj=${COMP_CWORD}
if [[ ${COMP_CWORD} -ge 2 ]]; then
skip_next="no"
for el in ${COMP_WORDS[@]}; do
# if the user has asked for help text there's no need to complete further
if [[ ${el} == "-h" || ${el} == "--help" ]]; then
return 0
fi
if [[ ${skip_next} == "yes" ]]; then
let "comp_cword_adj--"
skip_next="no"
continue
fi
if [[ ${el} == -* && ${el} != ${cur} ]]; then
let "comp_cword_adj--"
for opt in ${arg_global_opts_array[@]}; do
if [[ ${el} == ${opt} ]]; then
skip_next="yes"
fi
done
elif [[ ${el} != ${cur} && ${el} != ${COMP_WORDS[0]} && ${chosen_root_command} == "" ]]; then
chosen_root_command=${el}
fi
done
fi
if [[ ${comp_cword_adj} -eq 1 ]]; then
_completeRoot
# Given that we check the value of comp_cword_adj outside
# of it, at the moment _completeRoot should always return
# 0, this is just here in case changes are made. The same
# will apply to similar functions below
if [[ $? -eq 0 ]]; then
return 0
fi
fi
case $chosen_root_command in
up)
_completeUpArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
down)
_completeDownArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
exec)
_completeExecArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
build)
_completeBuildArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
logs)
_completeLogsArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
ps)
_completePsArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
pull)
_completePullArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
push)
_completePushArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
restart)
_completeRestartArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
start)
_completeStartArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
stop)
_completeStopArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
run)
_completeRunArgs
if [[ $? -eq 0 ]]; then
return 0
fi
;;
esac
}
complete -F _podmanCompose podman-compose

33
docs/Changelog-1.1.0.md Normal file
View 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
View 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

111
docs/Extensions.md Normal file
View File

@ -0,0 +1,111 @@
# 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.uidmap` - Run the container in a new user namespace using the supplied UID mapping.
* `x-podman.gidmap` - 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.
## 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
```

View File

@ -1,7 +1,7 @@
---
- name: Manage AWX Container Images
block:
- name: Export Docker awx image if it isnt local and there isnt a registry defined
- name: Export Docker awx image if it isn't local and there isn't a registry defined
docker_image:
name: "{{ awx_image }}"
tag: "{{ awx_version }}"

View File

@ -0,0 +1,17 @@
# Azure Vote Example
This example have two containers:
* backend: `redis` used as storage
* frontend: having supervisord, nginx, uwsgi/python
```
echo "HOST_PORT=8080" > .env
podman-compose up
```
after typing the commands above open your browser on the host port you picked above like
[http://localhost:8080/](http://localhost:8080/)

View File

@ -0,0 +1,16 @@
---
# from https://github.com/Azure-Samples/azure-voting-app-redis/blob/master/docker-compose.yaml
version: '3'
services:
azure-vote-back:
image: mcr.microsoft.com/oss/bitnami/redis:6.0.8
container_name: azure-vote-back
environment:
ALLOW_EMPTY_PASSWORD: "yes"
azure-vote-front:
image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
environment:
REDIS: azure-vote-back
ports:
- "${HOST_PORT:-8080}:80"

31
examples/echo/README.md Normal file
View File

@ -0,0 +1,31 @@
# Echo Service example
```
podman-compose up
```
Test the service with `curl like this`
```
$ curl -X POST -d "foobar" http://localhost:8080/; echo
CLIENT VALUES:
client_address=10.89.31.2
command=POST
real path=/
query=nil
request_version=1.1
request_uri=http://localhost:8080/
SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001
HEADERS RECEIVED:
accept=*/*
content-length=6
content-type=application/x-www-form-urlencoded
host=localhost:8080
user-agent=curl/7.76.1
BODY:
foobar
```

View File

@ -0,0 +1,8 @@
---
version: '3'
services:
web:
image: k8s.gcr.io/echoserver:1.4
ports:
- "${HOST_PORT:-8080}:8080"

View File

@ -0,0 +1,12 @@
# GCR Hello App Redis
A 6-node redis cluster using [Bitnami](https://github.com/bitnami/bitnami-docker-redis-cluster)
with a [simple hit counter](https://github.com/GoogleCloudPlatform/kubernetes-engine-samples/tree/main/hello-app-redis) that persists on that redis cluster
```
podman-compose up
```
then open your browser on [http://localhost:8080/](http://localhost:8080/)

View File

@ -0,0 +1,67 @@
---
version: '3'
volumes:
redis-node1-data:
redis-node2-data:
redis-node3-data:
redis-node4-data:
redis-node5-data:
redis-data:
services:
web:
image: gcr.io/google-samples/hello-app-redis:1.0
depends_on:
- redis-cluster
ports:
- "${HOST_PORT:-8080}:8080"
redis-node1:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-node1-data:/bitnami/redis/data
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-node1 redis-node2 redis-node3 redis-node4 redis-node5 redis-cluster
redis-node2:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-node2-data:/bitnami/redis/data
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-node1 redis-node2 redis-node3 redis-node4 redis-node5 redis-cluster
redis-node3:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-node3-data:/bitnami/redis/data
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-node1 redis-node2 redis-node3 redis-node4 redis-node5 redis-cluster
redis-node4:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-node4-data:/bitnami/redis/data
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-node1 redis-node2 redis-node3 redis-node4 redis-node5 redis-cluster
redis-node5:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-node5-data:/bitnami/redis/data
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-node1 redis-node2 redis-node3 redis-node4 redis-node5 redis-cluster
redis-cluster:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-data:/bitnami/redis/data
depends_on:
- redis-node1
- redis-node2
- redis-node3
- redis-node4
- redis-node5
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_NODES=redis-node1 redis-node2 redis-node3 redis-node4 redis-node5 redis-cluster
- REDIS_CLUSTER_CREATOR=yes

View File

@ -0,0 +1,10 @@
# GCR Hello App
A small ~2MB image, type
```
podman-compose up
```
then open your browser on [http://localhost:8080/](http://localhost:8080/)

View File

@ -0,0 +1,8 @@
---
version: '3'
services:
web:
image: gcr.io/google-samples/hello-app:1.0
ports:
- "${HOST_PORT:-8080}:8080"

View File

@ -0,0 +1,12 @@
FROM python:3.9-alpine
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "-m", "app.web" ]
EXPOSE 8080

View File

@ -0,0 +1,8 @@
# Simple Python Demo
## A Redis counter
```
podman-compose up -d
curl localhost:8080/
curl localhost:8080/hello.json
```

View File

View File

@ -0,0 +1,39 @@
# pylint: disable=import-error
# pylint: disable=unused-import
import asyncio # noqa: F401
import os
import aioredis
from aiohttp import web
REDIS_HOST = os.environ.get("REDIS_HOST", "localhost")
REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379"))
REDIS_DB = int(os.environ.get("REDIS_DB", "0"))
redis = aioredis.from_url(f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}")
app = web.Application()
routes = web.RouteTableDef()
@routes.get("/")
async def hello(request): # pylint: disable=unused-argument
counter = await redis.incr("mycounter")
return web.Response(text=f"counter={counter}")
@routes.get("/hello.json")
async def hello_json(request): # pylint: disable=unused-argument
counter = await redis.incr("mycounter")
data = {"counter": counter}
return web.json_response(data)
app.add_routes(routes)
def main():
web.run_app(app, port=8080)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,21 @@
---
version: '3'
volumes:
redis:
services:
redis:
read_only: true
image: docker.io/redis:alpine
command: ["redis-server", "--appendonly", "yes", "--notify-keyspace-events", "Ex"]
volumes:
- redis:/data
web:
read_only: true
build:
context: .
image: hello-py-aioweb
ports:
- 8080:8080
environment:
REDIS_HOST: redis

View File

@ -0,0 +1,3 @@
aiohttp
aioredis
# aioredis[hiredis]

View File

@ -0,0 +1,71 @@
{
"env": {
"node": true,
"es6": true
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".mjs", ".ts", ".cjs"]
}
}
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"allowImportExportEverywhere": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:promise/recommended",
"google",
"plugin:security/recommended"
],
"plugins": ["promise", "security", "import"],
"overrides": [
{
"files": "public/**/*.min.js",
"env": {
"browser": true,
"node": false,
"es6": false
},
"parserOptions": {
"sourceType": "script"
},
"extends": ["plugin:compat/recommended"],
"plugins": [],
"rules": {
"no-var": ["off"]
}
}
],
"rules": {
"security/detect-non-literal-fs-filename":["off"],
"security/detect-object-injection":["off"],
"camelcase": ["off"],
"no-console": ["off"],
"require-jsdoc": ["off"],
"one-var": ["off"],
"guard-for-in": ["off"],
"max-len": [
"warn",
{
"ignoreComments": true,
"ignoreTrailingComments": true,
"ignoreUrls": true,
"code": 200
}
],
"indent": ["warn", 4],
"no-unused-vars": ["warn"],
"no-extra-semi": ["warn"],
"linebreak-style": ["error", "unix"],
"quotes": ["warn", "double"],
"semi": ["error", "always"]
}
}

5
examples/nodeproj/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
local.env
.env
*.pid
node_modules

1
examples/nodeproj/.home/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*

View File

@ -0,0 +1,16 @@
# How to run example
```
cp example.local.env local.env
cp example.env .env
cat local.env
cat .env
echo "UID=$UID" >> .env
cat .env
podman-compose build
podman-compose run --rm --no-deps init
podman-compose up
```

View File

@ -0,0 +1,12 @@
FROM registry.fedoraproject.org/fedora-minimal:35
ARG NODE_VER=16
# microdnf -y module enable nodejs:${NODE_VER}
RUN \
echo -e "[nodejs]\nname=nodejs\nstream=${NODE_VER}\nprofiles=\nstate=enabled\n" > /etc/dnf/modules.d/nodejs.module && \
microdnf -y install shadow-utils nodejs zopfli findutils busybox && \
microdnf clean all
RUN adduser -d /app app && mkdir -p /app/code/.home && chown app:app -R /app/code && chmod 711 /app /app/code/.home && usermod -d /app/code/.home app
ENV XDG_CONFIG_HOME=/app/code/.home
ENV HOME=/app/code/.home
WORKDIR /app/code

View File

@ -0,0 +1,48 @@
version: '3'
volumes:
redis:
services:
redis:
read_only: true
image: docker.io/redis:alpine
command: ["redis-server", "--appendonly", "yes", "--notify-keyspace-events", "Ex"]
volumes:
- redis:/data
tmpfs:
- /tmp
- /var/run
- /run
init:
read_only: true
#userns_mode: keep-id
user: ${UID:-1000}
build:
context: ./containers/${NODE_IMG:-node16-runtime}
image: ${NODE_IMG:-node16-runtime}
env_file:
- local.env
volumes:
- .:/app/code
command: ["/bin/sh", "-c", "mkdir -p ~/; [ -d ./node_modules ] && echo '** node_modules exists' || npm install"]
tmpfs:
- /tmp
- /run
task:
extends:
service: init
command: ["npm", "run", "cli", "--", "task"]
links:
- redis
depends_on:
- redis
web:
extends:
service: init
command: ["npm", "run", "cli", "--", "web"]
ports:
- ${WEB_LISTEN_PORT:-3000}:3000
depends_on:
- redis
links:
- mongo

View File

@ -0,0 +1,3 @@
WEB_LISTEN_PORT=3000
# pass UID= your IDE user

View File

@ -0,0 +1,2 @@
REDIS_HOST=redis

View File

@ -0,0 +1,6 @@
#! /usr/bin/env node
"use strict";
import {start} from "./lib";
start();

View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"files": [
"index.js"
],
"include": [
"lib/**/*.js"
]
}

View File

@ -0,0 +1,31 @@
"use strict";
import {proj} from "../proj";
async function loop() {
const poped = await proj.predis.blpop("queue", 5);
const task_desc_s = poped[1];
let task_desc;
try {
task_desc = JSON.parse(task_desc_s);
} catch (e) {
console.exception(e);
}
console.info("got task "+task_desc.func);
const func = task_desc.func;
const args = task_desc.args;
if (typeof(proj.tasks[func])!="function") {
console.log(`task ${func} not found`);
process.exit(-1)
}
try {
await ((this.tasks[func])(...args));
} catch (e) {
console.exception(e);
}
}
export async function start() {
while(true) {
loop();
}
}

View File

@ -0,0 +1,21 @@
"use strict";
import {proj} from "../proj";
import http from "http";
import express from "express";
export async function start() {
const app = express();
const server = http.createServer(app);
// Routing
app.use(express.static(proj.config.basedir + "/public"));
app.get("/healthz", function(req, res) {
res.send("ok@"+Date.now());
});
server.listen(proj.config.LISTEN_PORT, proj.config.LISTEN_HOST, function() {
console.warn(`listening at port ${proj.config.LISTEN_PORT}`);
});
}

View File

@ -0,0 +1,24 @@
{
"name": "nodeproj",
"version": "0.0.1",
"description": "nodejs example project",
"exports": {
".": "./index.js",
"./lib": "./lib"
},
"main": "index.js",
"type": "module",
"scripts": {
"cli": "nodemon -w lib -w index.js --es-module-specifier-resolution=node ./index.js"
},
"dependencies": {
"express": "~4.16.4",
"redis": "^3.1.2"
},
"private": true,
"author": "",
"license": "proprietary",
"devDependencies": {
"nodemon": "^2.0.14"
}
}

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Vote</title>
<link rel="stylesheet" href="https://unpkg.com/browse/normalize.css@8.0.1/normalize.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
<script type="text/javascript" src="main.css"></script>
<script type="text/javascript">
//<![CDATA[
console.log("loaded");
//]]>
</script>
</html>

View 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]

View File

@ -0,0 +1,24 @@
---
volumes:
db_data:
services:
wordpress:
image: docker.io/library/wordpress:latest
ports:
- 8080:80
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=password
- WORDPRESS_DB_NAME=wordpress
db:
image: docker.io/library/mariadb:10.6.4-focal
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=somewordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=password

13
newsfragments/README.txt Normal file
View 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

File diff suppressed because it is too large Load Diff

15
pyproject.toml Normal file
View 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"

0
pytests/__init__.py Normal file
View File

View File

@ -0,0 +1,168 @@
# SPDX-License-Identifier: GPL-2.0
from __future__ import annotations
import argparse
import copy
import os
import unittest
import yaml
from parameterized import parameterized
from podman_compose import PodmanCompose
class TestCanMergeBuild(unittest.TestCase):
@parameterized.expand([
({}, {}, {}),
({}, {"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(self, input, override, expected):
compose_test_1 = {"services": {"test-service": input}}
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_compose = {}
if podman_compose.services:
podman_compose.services["test-service"].pop("_deps")
actual_compose = podman_compose.services["test-service"]
self.assertEqual(actual_compose, expected)
# $$$ is a placeholder for either command or entrypoint
@parameterized.expand([
({}, {"$$$": []}, {"$$$": []}),
({"$$$": []}, {}, {"$$$": []}),
({"$$$": []}, {"$$$": "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 test_parse_compose_file_when_multiple_composes_keys_command_entrypoint(
self, base_template, override_template, expected_template
):
for key in ['command', 'entrypoint']:
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"]
self.assertEqual(actual, expected)
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_bool = 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 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_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)

View File

@ -0,0 +1,46 @@
# SPDX-License-Identifier: GPL-2.0
import argparse
import unittest
from podman_compose import compose_exec_args
class TestComposeExecArgs(unittest.TestCase):
def test_minimal(self):
cnt = get_minimal_container()
args = get_minimal_args()
result = compose_exec_args(cnt, "container_name", args)
expected = ["--interactive", "--tty", "container_name"]
self.assertEqual(result, expected)
def test_additional_env_value_equals(self):
cnt = get_minimal_container()
args = get_minimal_args()
args.env = ["key=valuepart1=valuepart2"]
result = compose_exec_args(cnt, "container_name", args)
expected = [
"--interactive",
"--tty",
"--env",
"key=valuepart1=valuepart2",
"container_name",
]
self.assertEqual(result, expected)
def get_minimal_container():
return {}
def get_minimal_args():
return argparse.Namespace(
T=None,
cnt_command=None,
env=None,
privileged=None,
user=None,
workdir=None,
)

View File

@ -0,0 +1,76 @@
# SPDX-License-Identifier: GPL-2.0
import argparse
import unittest
from podman_compose import PodmanCompose
from podman_compose import compose_run_update_container_from_args
class TestComposeRunUpdateContainerFromArgs(unittest.TestCase):
def test_minimal(self):
cnt = get_minimal_container()
compose = get_minimal_compose()
args = get_minimal_args()
compose_run_update_container_from_args(compose, cnt, args)
expected_cnt = {"name": "default_name", "tty": True}
self.assertEqual(cnt, expected_cnt)
def test_additional_env_value_equals(self):
cnt = get_minimal_container()
compose = get_minimal_compose()
args = get_minimal_args()
args.env = ["key=valuepart1=valuepart2"]
compose_run_update_container_from_args(compose, cnt, args)
expected_cnt = {
"environment": {
"key": "valuepart1=valuepart2",
},
"name": "default_name",
"tty": True,
}
self.assertEqual(cnt, expected_cnt)
def test_publish_ports(self):
cnt = get_minimal_container()
compose = get_minimal_compose()
args = get_minimal_args()
args.publish = ["1111", "2222:2222"]
compose_run_update_container_from_args(compose, cnt, args)
expected_cnt = {
"name": "default_name",
"ports": ["1111", "2222:2222"],
"tty": True,
}
self.assertEqual(cnt, expected_cnt)
def get_minimal_container():
return {}
def get_minimal_compose():
return PodmanCompose()
def get_minimal_args():
return argparse.Namespace(
T=None,
cnt_command=None,
entrypoint=None,
env=None,
name="default_name",
rm=None,
service=None,
publish=None,
service_ports=None,
user=None,
volume=None,
workdir=None,
)

View File

@ -0,0 +1,558 @@
# SPDX-License-Identifier: GPL-2.0
import unittest
from os import path
from unittest import mock
from parameterized import parameterized
from podman_compose import container_to_args
def create_compose_mock(project_name="test_project_name"):
compose = mock.Mock()
compose.project_name = project_name
compose.dirname = "test_dirname"
compose.container_names_by_service.get = mock.Mock(return_value=None)
compose.prefer_volume_over_mount = False
compose.default_net = None
compose.networks = {}
return compose
def get_minimal_container():
return {
"name": "project_name_service_name1",
"service_name": "service_name",
"image": "busybox",
}
class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
async def test_minimal(self):
c = create_compose_mock()
cnt = get_minimal_container()
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)
async def test_runtime(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["runtime"] = "runsc"
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--runtime",
"runsc",
"busybox",
],
)
async def test_sysctl_list(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["sysctls"] = [
"net.core.somaxconn=1024",
"net.ipv4.tcp_syncookies=0",
]
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--sysctl",
"net.core.somaxconn=1024",
"--sysctl",
"net.ipv4.tcp_syncookies=0",
"busybox",
],
)
async def test_sysctl_map(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["sysctls"] = {
"net.core.somaxconn": 1024,
"net.ipv4.tcp_syncookies": 0,
}
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--sysctl",
"net.core.somaxconn=1024",
"--sysctl",
"net.ipv4.tcp_syncookies=0",
"busybox",
],
)
async def test_sysctl_wrong_type(self):
c = create_compose_mock()
cnt = get_minimal_container()
# check whether wrong types are correctly rejected
for wrong_type in [True, 0, 0.0, "wrong", ()]:
with self.assertRaises(TypeError):
cnt["sysctls"] = wrong_type
await container_to_args(c, cnt)
async def test_pid(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["pid"] = "host"
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--pid",
"host",
"busybox",
],
)
async def test_http_proxy(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["http_proxy"] = False
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--http-proxy=false",
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)
async def test_uidmaps_extension_old_path(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt['x-podman'] = {'uidmaps': ['1000:1000:1']}
with self.assertRaises(ValueError):
await container_to_args(c, cnt)
async def test_uidmaps_extension(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt['x-podman.uidmaps'] = ['1000:1000:1', '1001:1001:2']
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
'--uidmap',
'1000:1000:1',
'--uidmap',
'1001:1001:2',
"busybox",
],
)
async def test_gidmaps_extension(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt['x-podman.gidmaps'] = ['1000:1000:1', '1001:1001:2']
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
'--gidmap',
'1000:1000:1',
'--gidmap',
'1001:1001:2',
"busybox",
],
)
async def test_rootfs_extension(self):
c = create_compose_mock()
cnt = get_minimal_container()
del cnt["image"]
cnt["x-podman.rootfs"] = "/path/to/rootfs"
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--rootfs",
"/path/to/rootfs",
],
)
async def test_env_file_str(self):
c = create_compose_mock()
cnt = get_minimal_container()
env_file = path.realpath('tests/env-file-tests/env-files/project-1.env')
cnt['env_file'] = env_file
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"-e",
"ZZVAR1=podman-rocks-123",
"-e",
"ZZVAR2=podman-rocks-124",
"-e",
"ZZVAR3=podman-rocks-125",
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)
async def test_env_file_str_not_exists(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt['env_file'] = 'notexists'
with self.assertRaises(ValueError):
await container_to_args(c, cnt)
async def test_env_file_str_array_one_path(self):
c = create_compose_mock()
cnt = get_minimal_container()
env_file = path.realpath('tests/env-file-tests/env-files/project-1.env')
cnt['env_file'] = [env_file]
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"-e",
"ZZVAR1=podman-rocks-123",
"-e",
"ZZVAR2=podman-rocks-124",
"-e",
"ZZVAR3=podman-rocks-125",
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)
async def test_env_file_str_array_two_paths(self):
c = create_compose_mock()
cnt = get_minimal_container()
env_file = path.realpath('tests/env-file-tests/env-files/project-1.env')
env_file_2 = path.realpath('tests/env-file-tests/env-files/project-2.env')
cnt['env_file'] = [env_file, env_file_2]
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"-e",
"ZZVAR1=podman-rocks-123",
"-e",
"ZZVAR2=podman-rocks-124",
"-e",
"ZZVAR3=podman-rocks-125",
"-e",
"ZZVAR1=podman-rocks-223",
"-e",
"ZZVAR2=podman-rocks-224",
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)
async def test_env_file_obj_required(self):
c = create_compose_mock()
cnt = get_minimal_container()
env_file = path.realpath('tests/env-file-tests/env-files/project-1.env')
cnt['env_file'] = {'path': env_file, 'required': True}
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"-e",
"ZZVAR1=podman-rocks-123",
"-e",
"ZZVAR2=podman-rocks-124",
"-e",
"ZZVAR3=podman-rocks-125",
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)
async def test_env_file_obj_required_non_existent_path(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt['env_file'] = {'path': 'not-exists', 'required': True}
with self.assertRaises(ValueError):
await container_to_args(c, cnt)
async def test_env_file_obj_optional(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt['env_file'] = {'path': 'not-exists', 'required': False}
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)
async def test_gpu_count_all(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["command"] = ["nvidia-smi"]
cnt["deploy"] = {"resources": {"reservations": {"devices": [{}]}}}
cnt["deploy"]["resources"]["reservations"]["devices"][0] = {
"driver": "nvidia",
"count": "all",
"capabilities": ["gpu"],
}
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--device",
"nvidia.com/gpu=all",
"--security-opt=label=disable",
"busybox",
"nvidia-smi",
],
)
async def test_gpu_count_specific(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["command"] = ["nvidia-smi"]
cnt["deploy"] = {
"resources": {
"reservations": {
"devices": [
{
"driver": "nvidia",
"count": 2,
"capabilities": ["gpu"],
}
]
}
}
}
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--device",
"nvidia.com/gpu=0",
"--device",
"nvidia.com/gpu=1",
"--security-opt=label=disable",
"busybox",
"nvidia-smi",
],
)
async def test_gpu_device_ids_all(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["command"] = ["nvidia-smi"]
cnt["deploy"] = {
"resources": {
"reservations": {
"devices": [
{
"driver": "nvidia",
"device_ids": "all",
"capabilities": ["gpu"],
}
]
}
}
}
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--device",
"nvidia.com/gpu=all",
"--security-opt=label=disable",
"busybox",
"nvidia-smi",
],
)
async def test_gpu_device_ids_specific(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["command"] = ["nvidia-smi"]
cnt["deploy"] = {
"resources": {
"reservations": {
"devices": [
{
"driver": "nvidia",
"device_ids": [1, 3],
"capabilities": ["gpu"],
}
]
}
}
}
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--device",
"nvidia.com/gpu=1",
"--device",
"nvidia.com/gpu=3",
"--security-opt=label=disable",
"busybox",
"nvidia-smi",
],
)
@parameterized.expand([
(False, "z", ["--mount", "type=bind,source=./foo,destination=/mnt,z"]),
(False, "Z", ["--mount", "type=bind,source=./foo,destination=/mnt,Z"]),
(True, "z", ["-v", "./foo:/mnt:z"]),
(True, "Z", ["-v", "./foo:/mnt:Z"]),
])
async def test_selinux_volume(self, prefer_volume, selinux_type, expected_additional_args):
c = create_compose_mock()
c.prefer_volume_over_mount = prefer_volume
cnt = get_minimal_container()
# This is supposed to happen during `_parse_compose_file`
# but that is probably getting skipped during testing
cnt["_service"] = cnt["service_name"]
cnt["volumes"] = [
{
"type": "bind",
"source": "./foo",
"target": "/mnt",
"bind": {
"selinux": selinux_type,
},
}
]
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
*expected_additional_args,
"--network=bridge",
"--network-alias=service_name",
"busybox",
],
)

View File

@ -0,0 +1,91 @@
# SPDX-License-Identifier: GPL-2.0
import unittest
from podman_compose import container_to_args
from .test_container_to_args import create_compose_mock
from .test_container_to_args import get_minimal_container
class TestContainerToArgsSecrets(unittest.IsolatedAsyncioTestCase):
async def test_pass_secret_as_env_variable(self):
c = create_compose_mock()
c.declared_secrets = {
"my_secret": {"external": "true"} # must have external or name value
}
cnt = get_minimal_container()
cnt["secrets"] = [
{
"source": "my_secret",
"target": "ENV_SECRET",
"type": "env",
},
]
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--secret",
"my_secret,type=env,target=ENV_SECRET",
"busybox",
],
)
async def test_secret_as_env_external_true_has_no_name(self):
c = create_compose_mock()
c.declared_secrets = {
"my_secret": {
"name": "my_secret", # must have external or name value
}
}
cnt = get_minimal_container()
cnt["_service"] = "test-service"
cnt["secrets"] = [
{
"source": "my_secret",
"target": "ENV_SECRET",
"type": "env",
}
]
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--secret",
"my_secret,type=env,target=ENV_SECRET",
"busybox",
],
)
async def test_pass_secret_as_env_variable_no_external(self):
c = create_compose_mock()
c.declared_secrets = {
"my_secret": {} # must have external or name value
}
cnt = get_minimal_container()
cnt["_service"] = "test-service"
cnt["secrets"] = [
{
"source": "my_secret",
"target": "ENV_SECRET",
"type": "env",
}
]
with self.assertRaises(ValueError) as context:
await container_to_args(c, cnt)
self.assertIn('ERROR: unparsable secret: ', str(context.exception))

View File

@ -0,0 +1,298 @@
import unittest
from parameterized import parameterized
from podman_compose import get_net_args
from .test_container_to_args import create_compose_mock
PROJECT_NAME = "test_project_name"
SERVICE_NAME = "service_name"
CONTAINER_NAME = f"{PROJECT_NAME}_{SERVICE_NAME}_1"
def get_networked_compose(num_networks=1):
compose = create_compose_mock(PROJECT_NAME)
for network in range(num_networks):
compose.networks[f"net{network}"] = {
"driver": "bridge",
"ipam": {
"config": [
{"subnet": f"192.168.{network}.0/24"},
{"subnet": f"fd00:{network}::/64"},
]
},
"enable_ipv6": True,
}
return compose
def get_minimal_container():
return {
"name": CONTAINER_NAME,
"service_name": SERVICE_NAME,
"image": "busybox",
}
class TestGetNetArgs(unittest.TestCase):
def test_minimal(self):
compose = get_networked_compose()
container = get_minimal_container()
expected_args = [
"--network=bridge",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_one_net(self):
compose = get_networked_compose()
container = get_minimal_container()
container["networks"] = {"net0": {}}
expected_args = [
f"--network={PROJECT_NAME}_net0",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_alias(self):
compose = get_networked_compose()
container = get_minimal_container()
container["networks"] = {"net0": {}}
container["_aliases"] = ["alias1", "alias2"]
expected_args = [
f"--network={PROJECT_NAME}_net0",
f"--network-alias={SERVICE_NAME}",
"--network-alias=alias1",
"--network-alias=alias2",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_one_ipv4(self):
ip = "192.168.0.42"
compose = get_networked_compose()
container = get_minimal_container()
container["networks"] = {"net0": {"ipv4_address": ip}}
expected_args = [
f"--network={PROJECT_NAME}_net0",
f"--ip={ip}",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertEqual(expected_args, args)
def test_one_ipv6(self):
ipv6_address = "fd00:0::42"
compose = get_networked_compose()
container = get_minimal_container()
container["networks"] = {"net0": {"ipv6_address": ipv6_address}}
expected_args = [
f"--network={PROJECT_NAME}_net0",
f"--ip6={ipv6_address}",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_one_mac(self):
mac = "00:11:22:33:44:55"
compose = get_networked_compose()
container = get_minimal_container()
container["networks"] = {"net0": {}}
container["mac_address"] = mac
expected_args = [
f"--network={PROJECT_NAME}_net0",
f"--mac-address={mac}",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_one_mac_two_nets(self):
mac = "00:11:22:33:44:55"
compose = get_networked_compose(num_networks=6)
container = get_minimal_container()
container["networks"] = {"net0": {}, "net1": {}}
container["mac_address"] = mac
expected_args = [
f"--network={PROJECT_NAME}_net0:mac={mac}",
f"--network={PROJECT_NAME}_net1",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_two_nets_as_dict(self):
compose = get_networked_compose(num_networks=2)
container = get_minimal_container()
container["networks"] = {"net0": {}, "net1": {}}
expected_args = [
f"--network={PROJECT_NAME}_net0",
f"--network={PROJECT_NAME}_net1",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_two_nets_as_list(self):
compose = get_networked_compose(num_networks=2)
container = get_minimal_container()
container["networks"] = ["net0", "net1"]
expected_args = [
f"--network={PROJECT_NAME}_net0",
f"--network={PROJECT_NAME}_net1",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_two_ipv4(self):
ip0 = "192.168.0.42"
ip1 = "192.168.1.42"
compose = get_networked_compose(num_networks=2)
container = get_minimal_container()
container["networks"] = {"net0": {"ipv4_address": ip0}, "net1": {"ipv4_address": ip1}}
expected_args = [
f"--network={PROJECT_NAME}_net0:ip={ip0}",
f"--network={PROJECT_NAME}_net1:ip={ip1}",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_two_ipv6(self):
ip0 = "fd00:0::42"
ip1 = "fd00:1::42"
compose = get_networked_compose(num_networks=2)
container = get_minimal_container()
container["networks"] = {"net0": {"ipv6_address": ip0}, "net1": {"ipv6_address": ip1}}
expected_args = [
f"--network={PROJECT_NAME}_net0:ip={ip0}",
f"--network={PROJECT_NAME}_net1:ip={ip1}",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
# custom extension; not supported by docker-compose
def test_two_mac(self):
mac0 = "00:00:00:00:00:01"
mac1 = "00:00:00:00:00:02"
compose = get_networked_compose(num_networks=2)
container = get_minimal_container()
container["networks"] = {
"net0": {"x-podman.mac_address": mac0},
"net1": {"x-podman.mac_address": mac1},
}
expected_args = [
f"--network={PROJECT_NAME}_net0:mac={mac0}",
f"--network={PROJECT_NAME}_net1:mac={mac1}",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_mixed_mac(self):
ip4_0 = "192.168.0.42"
ip4_1 = "192.168.1.42"
ip4_2 = "192.168.2.42"
mac_0 = "00:00:00:00:00:01"
mac_1 = "00:00:00:00:00:02"
compose = get_networked_compose(num_networks=3)
container = get_minimal_container()
container["networks"] = {
"net0": {"ipv4_address": ip4_0},
"net1": {"ipv4_address": ip4_1, "x-podman.mac_address": mac_0},
"net2": {"ipv4_address": ip4_2},
}
container["mac_address"] = mac_1
expected_exception = (
r"specifying mac_address on both container and network level " r"is not supported"
)
self.assertRaisesRegex(RuntimeError, expected_exception, get_net_args, compose, container)
def test_mixed_config(self):
ip4_0 = "192.168.0.42"
ip4_1 = "192.168.1.42"
ip6_0 = "fd00:0::42"
ip6_2 = "fd00:2::42"
mac = "00:11:22:33:44:55"
compose = get_networked_compose(num_networks=4)
container = get_minimal_container()
container["networks"] = {
"net0": {"ipv4_address": ip4_0, "ipv6_address": ip6_0},
"net1": {"ipv4_address": ip4_1},
"net2": {"ipv6_address": ip6_2},
"net3": {},
}
container["mac_address"] = mac
expected_args = [
f"--network={PROJECT_NAME}_net0:ip={ip4_0},ip={ip6_0},mac={mac}",
f"--network={PROJECT_NAME}_net1:ip={ip4_1}",
f"--network={PROJECT_NAME}_net2:ip={ip6_2}",
f"--network={PROJECT_NAME}_net3",
f"--network-alias={SERVICE_NAME}",
]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
@parameterized.expand([
("bridge", ["--network=bridge", f"--network-alias={SERVICE_NAME}"]),
("host", ["--network=host"]),
("none", []),
("slirp4netns", ["--network=slirp4netns"]),
("slirp4netns:cidr=10.42.0.0/24", ["--network=slirp4netns:cidr=10.42.0.0/24"]),
("private", ["--network=private"]),
("pasta", ["--network=pasta"]),
("pasta:--ipv4-only,-a,10.0.2.0", ["--network=pasta:--ipv4-only,-a,10.0.2.0"]),
("ns:my_namespace", ["--network=ns:my_namespace"]),
("container:my_container", ["--network=container:my_container"]),
])
def test_network_modes(self, network_mode, expected_args):
compose = get_networked_compose()
container = get_minimal_container()
container["network_mode"] = network_mode
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)
def test_network_mode_invalid(self):
compose = get_networked_compose()
container = get_minimal_container()
container["network_mode"] = "invalid_mode"
with self.assertRaises(SystemExit):
get_net_args(compose, container)
def test_network__mode_service(self):
compose = get_networked_compose()
compose.container_names_by_service = {
"service_1": ["container_1"],
"service_2": ["container_2"],
}
container = get_minimal_container()
container["network_mode"] = "service:service_2"
expected_args = ["--network=container:container_2"]
args = get_net_args(compose, container)
self.assertListEqual(expected_args, args)

View File

@ -0,0 +1,203 @@
import unittest
from podman_compose import get_network_create_args
class TestGetNetworkCreateArgs(unittest.TestCase):
def test_minimal(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {"config": []},
"enable_ipv6": False,
}
proj_name = "test_project"
net_name = "test_network"
expected_args = [
"create",
"--label",
f"io.podman.compose.project={proj_name}",
"--label",
f"com.docker.compose.project={proj_name}",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)
def test_ipv6(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {"config": []},
"enable_ipv6": True,
}
proj_name = "test_project"
net_name = "test_network"
expected_args = [
"create",
"--label",
f"io.podman.compose.project={proj_name}",
"--label",
f"com.docker.compose.project={proj_name}",
"--ipv6",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)
def test_bridge(self):
net_desc = {
"labels": [],
"internal": False,
"driver": "bridge",
"driver_opts": {"opt1": "value1", "opt2": "value2"},
"ipam": {"config": []},
"enable_ipv6": False,
}
proj_name = "test_project"
net_name = "test_network"
expected_args = [
"create",
"--label",
f"io.podman.compose.project={proj_name}",
"--label",
f"com.docker.compose.project={proj_name}",
"--driver",
"bridge",
"--opt",
"opt1=value1",
"--opt",
"opt2=value2",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)
def test_ipam_driver_default(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {
"driver": "default",
"config": [
{
"subnet": "192.168.0.0/24",
"ip_range": "192.168.0.2/24",
"gateway": "192.168.0.1",
}
],
},
}
proj_name = "test_project"
net_name = "test_network"
expected_args = [
"create",
"--label",
f"io.podman.compose.project={proj_name}",
"--label",
f"com.docker.compose.project={proj_name}",
"--subnet",
"192.168.0.0/24",
"--ip-range",
"192.168.0.2/24",
"--gateway",
"192.168.0.1",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)
def test_ipam_driver(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {
"driver": "someipamdriver",
"config": [
{
"subnet": "192.168.0.0/24",
"ip_range": "192.168.0.2/24",
"gateway": "192.168.0.1",
}
],
},
}
proj_name = "test_project"
net_name = "test_network"
expected_args = [
"create",
"--label",
f"io.podman.compose.project={proj_name}",
"--label",
f"com.docker.compose.project={proj_name}",
"--ipam-driver",
"someipamdriver",
"--subnet",
"192.168.0.0/24",
"--ip-range",
"192.168.0.2/24",
"--gateway",
"192.168.0.1",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)
def test_complete(self):
net_desc = {
"labels": ["label1", "label2"],
"internal": True,
"driver": "bridge",
"driver_opts": {"opt1": "value1", "opt2": "value2"},
"ipam": {
"driver": "someipamdriver",
"config": [
{
"subnet": "192.168.0.0/24",
"ip_range": "192.168.0.2/24",
"gateway": "192.168.0.1",
}
],
},
"enable_ipv6": True,
}
proj_name = "test_project"
net_name = "test_network"
expected_args = [
"create",
"--label",
f"io.podman.compose.project={proj_name}",
"--label",
f"com.docker.compose.project={proj_name}",
"--label",
"label1",
"--label",
"label2",
"--internal",
"--driver",
"bridge",
"--opt",
"opt1=value1",
"--opt",
"opt2=value2",
"--ipam-driver",
"someipamdriver",
"--ipv6",
"--subnet",
"192.168.0.0/24",
"--ip-range",
"192.168.0.2/24",
"--gateway",
"192.168.0.1",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)

View File

@ -0,0 +1,43 @@
import copy
from podman_compose import normalize_service
test_cases_simple = [
(
{"depends_on": "my_service"},
{"depends_on": {"my_service": {"condition": "service_started"}}},
),
(
{"depends_on": ["my_service"]},
{"depends_on": {"my_service": {"condition": "service_started"}}},
),
(
{"depends_on": ["my_service1", "my_service2"]},
{
"depends_on": {
"my_service1": {"condition": "service_started"},
"my_service2": {"condition": "service_started"},
},
},
),
(
{"depends_on": {"my_service": {"condition": "service_started"}}},
{"depends_on": {"my_service": {"condition": "service_started"}}},
),
(
{"depends_on": {"my_service": {"condition": "service_healthy"}}},
{"depends_on": {"my_service": {"condition": "service_healthy"}}},
),
]
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

View File

@ -0,0 +1,271 @@
# SPDX-License-Identifier: GPL-2.0
# pylint: disable=protected-access
from __future__ import annotations
import argparse
import os
import unittest
import yaml
from parameterized import parameterized
from podman_compose import PodmanCompose
from podman_compose import normalize_final
from podman_compose import normalize_service_final
cwd = os.path.abspath(".")
class TestNormalizeFinalBuild(unittest.TestCase):
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",
},
},
),
]
@parameterized.expand(cases_simple_normalization)
def test_normalize_service_final_returns_absolute_path_in_context(self, input, expected):
# Tests that [service.build] is normalized after merges
project_dir = cwd
self.assertEqual(normalize_service_final(input, project_dir), expected)
@parameterized.expand(cases_simple_normalization)
def test_normalize_returns_absolute_path_in_context(self, input, expected):
project_dir = cwd
compose_test = {"services": {"test-service": input}}
compose_expected = {"services": {"test-service": expected}}
self.assertEqual(normalize_final(compose_test, project_dir), compose_expected)
@parameterized.expand(cases_simple_normalization)
def test_parse_compose_file_when_single_compose(self, input, expected):
compose_test = {"services": {"test-service": 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"]
self.assertEqual(actual_compose, expected)
@parameterized.expand([
(
{},
{"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"],
}
},
),
])
def test_parse_when_multiple_composes(self, input, override, expected):
compose_test_1 = {"services": {"test-service": input}}
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"],
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"]
self.assertEqual(actual_compose, expected)
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_bool = 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)

View File

@ -0,0 +1,70 @@
# SPDX-License-Identifier: GPL-2.0
import unittest
from parameterized import parameterized
from podman_compose import normalize_service
class TestNormalizeService(unittest.TestCase):
@parameterized.expand([
({"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"}},
),
(
{"build": {"additional_contexts": ["ctx=../ctx", "ctx2=../ctx2"]}},
{"build": {"additional_contexts": ["ctx=../ctx", "ctx2=../ctx2"]}},
),
(
{"build": {"additional_contexts": {"ctx": "../ctx", "ctx2": "../ctx2"}}},
{"build": {"additional_contexts": ["ctx=../ctx", "ctx2=../ctx2"]}},
),
])
def test_simple(self, input, expected):
self.assertEqual(normalize_service(input), expected)
@parameterized.expand([
({"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(self, input, expected):
self.assertEqual(normalize_service(input, sub_dir="./sub_dir"), expected)
@parameterized.expand([
([], []),
(["sh"], ["sh"]),
(["sh", "-c", "date"], ["sh", "-c", "date"]),
("sh", ["sh"]),
("sleep infinity", ["sleep", "infinity"]),
(
"bash -c 'sleep infinity'",
["bash", "-c", "sleep infinity"],
),
])
def test_command_like(self, input, expected):
for key in ['command', 'entrypoint']:
input_service = {}
input_service[key] = input
expected_service = {}
expected_service[key] = expected
self.assertEqual(normalize_service(input_service), expected_service)

20
pytests/test_volumes.py Normal file
View File

@ -0,0 +1,20 @@
# SPDX-License-Identifier: GPL-2.0
# pylint: disable=redefined-outer-name
import unittest
from podman_compose import parse_short_mount
class ParseShortMountTests(unittest.TestCase):
def test_multi_propagation(self):
self.assertEqual(
parse_short_mount("/foo/bar:/baz:U,Z", "/"),
{
"type": "bind",
"source": "/foo/bar",
"target": "/baz",
"bind": {
"propagation": "U,Z",
},
},
)

View File

@ -3,3 +3,7 @@ universal = 1
[metadata]
version = attr: podman_compose.__version__
[flake8]
# The GitHub editor is 127 chars wide
max-line-length=127

View File

@ -1,49 +1,49 @@
# SPDX-License-Identifier: GPL-2.0
import os
from setuptools import setup
try:
readme = open(os.path.join(os.path.dirname(__file__), 'README.md')).read()
except:
readme = ''
README = open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf-8").read()
except: # noqa: E722 # pylint: disable=bare-except
README = ""
setup(
name='podman-compose',
name="podman-compose",
description="A script to run docker-compose.yml using podman",
long_description=readme,
long_description_content_type='text/markdown',
long_description=README,
long_description_content_type="text/markdown",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"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",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Development Status :: 3 - Alpha",
"Topic :: Software Development :: Build Tools",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
],
keywords='podman, podman-compose',
author='Muayyad Alsadi',
author_email='alsadi@gmail.com',
url='https://github.com/containers/podman-compose',
py_modules=['podman_compose'],
entry_points={
'console_scripts': [
'podman-compose = podman_compose:main'
]
},
keywords="podman, podman-compose",
author="Muayyad Alsadi",
author_email="alsadi@gmail.com",
url="https://github.com/containers/podman-compose",
py_modules=["podman_compose"],
entry_points={"console_scripts": ["podman-compose = podman_compose:main"]},
include_package_data=True,
license='GPL-2.0-only',
license="GPL-2.0-only",
install_requires=[
'pyyaml',
'python-dotenv',
"pyyaml",
"python-dotenv",
],
extras_require={"devel": ["ruff", "pre-commit", "coverage", "parameterized"]},
# test_suite='tests',
# tests_require=[
# 'coverage',
# 'pytest-cov',
# 'pytest',
# 'tox',
# ]
)

View File

@ -1,8 +1,33 @@
# 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
# 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
tomlkit==0.12.4
virtualenv==20.25.1

12
tests/__init__.py Normal file
View 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()

View 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
```

View File

@ -0,0 +1 @@
Data for dict

View File

@ -0,0 +1 @@
Data for list

View File

@ -0,0 +1,3 @@
FROM busybox
COPY --from=data data.txt /data/data.txt
CMD ["busybox", "cat", "/data/data.txt"]

View File

@ -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

View File

@ -0,0 +1,6 @@
FROM docker.io/library/debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y \
dumb-init \
busybox \
wget

View File

@ -0,0 +1,22 @@
# 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
```

View File

@ -0,0 +1,3 @@
FROM busybox
RUN this_command_does_not_exist
CMD ["sh"]

View File

@ -0,0 +1,5 @@
version: "3"
services:
test:
build: ./context
image: build-fail-img

View 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' ]

View 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

View 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

View File

@ -0,0 +1 @@
important-secret-is-important

View File

@ -1,4 +1,4 @@
```
podman-compose run --rm sleep /bin/sh -c 'wget -O - http://localhost:8000/hosts'
podman-compose run --rm sleep /bin/sh -c 'wget -O - http://web:8000/hosts'
```

View File

@ -1,21 +1,22 @@
version: "3.7"
services:
web:
image: busybox
command: ["/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"]
image: nopush/podman-compose-test
command: ["dumb-init", "/bin/busybox", "httpd", "-f", "-h", "/etc/", "-p", "8000"]
tmpfs:
- /run
- /tmp
sleep:
image: busybox
command: ["/bin/busybox", "sh", "-c", "sleep 3600"]
depends_on: "web"
image: nopush/podman-compose-test
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600"]
depends_on:
- "web"
tmpfs:
- /run
- /tmp
sleep2:
image: busybox
command: ["/bin/busybox", "sh", "-c", "sleep 3600"]
image: nopush/podman-compose-test
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600"]
depends_on:
- sleep
tmpfs:

View 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/env-file-tests/.gitignore vendored Normal file
View 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

View 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
```

View File

@ -0,0 +1,3 @@
ZZVAR1=podman-rocks-123
ZZVAR2=podman-rocks-124
ZZVAR3=podman-rocks-125

View File

@ -0,0 +1,2 @@
ZZVAR1=podman-rocks-223
ZZVAR2=podman-rocks-224

View File

@ -0,0 +1,2 @@
ZZVAR1='This value is loaded but should be overwritten'
ZZVAR2='This value is loaded from .env in project/ directory'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,9 @@
services:
app:
image: busybox
command: ["/bin/busybox", "sh", "-c", "env | grep ZZ"]
tmpfs:
- /run
- /tmp
environment:
ZZVAR1: $ZZVAR1

View File

@ -1,20 +1,20 @@
version: "3"
services:
too_long:
image: busybox
command: ["/bin/busybox", "sh", "-c", "sleep 3600; exit 0"]
image: nopush/podman-compose-test
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 3600; exit 0"]
tmpfs:
- /run
- /tmp
sh1:
image: busybox
command: ["/bin/busybox", "sh", "-c", "sleep 5; exit 1"]
image: nopush/podman-compose-test
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 1; exit 1"]
tmpfs:
- /run
- /tmp
sh2:
image: busybox
command: ["/bin/busybox", "sh", "-c", "sleep 5; exit 2"]
image: nopush/podman-compose-test
command: ["dumb-init", "/bin/busybox", "sh", "-c", "sleep 1; exit 2"]
tmpfs:
- /run
- /tmp

View File

@ -0,0 +1,7 @@
services:
webapp_default:
webapp_special:
image: nopush/podman-compose-test
volumes:
- "/data"

View File

@ -0,0 +1,10 @@
version: "3"
services:
web:
image: nopush/podman-compose-test
extends:
file: common-services.yml
service: webapp_default
environment:
- DEBUG=1
cpu_shares: 5

View File

@ -0,0 +1,8 @@
version: "3"
services:
web:
extends:
file: sub/docker-compose.yml
service: webapp
environment:
- DEBUG=1

View File

@ -0,0 +1,12 @@
version: "3"
services:
webapp:
build:
context: docker/example
dockerfile: Dockerfile
image: localhost/subdir_test:me
ports:
- "8000:8000"
volumes:
- "/data"

Some files were not shown because too many files have changed in this diff Show More