Open TheChymera opened 3 months ago
@yarikoptic I can't find any sort of Containerfile in this repo... any idea how/what I should adapt?
this is a tool which produces Containerfile's (based on such templates etc), it doesn't contain them. What do you need it for? in any case -- just try to follow what you see done (tests etc) for e.g. neurodebian -- just git grep neurodebian
Ok, I'll do some more digging in the actual code, but:
git grep neurodebian
neurodebian is only mentioned in that file and templates/ndfreeze.yaml
.
I also see no mentions of “container” in templates/
.
I assume this is all in the logic somewhere.
Basically what needs to be done for Gentoo images, is for this container file I wrote to be loaded, and on the last line whatever packages the user wants should get concatenated.
@TheChymera - dockerfiles are rendered here:
and singularity files are rendered here:
the templates in templates/
are used during the rendering process to construct the dockerfile or singularity file.
@kaczmarj any idea where the YAML is loaded? I can't find either “.yaml”, or “neurodebian”, or “templates/” anywhere in that module.
I assume this somehow happens dynamically, and I tried to look for tests... but I couldn't find the relevant test exemplifying this. Tried to break the neurodocker.yaml file on purpose and see where the test breaks, but I only get a nondescript:
ERROR neurodocker/reproenv/tests/test_renderers.py - yaml.scanner.ScannerError: while scanning a simple key
With a traceback that's mainly <frozen importlib._bootstrap>
.
Basically what I'd like to do is just give it a series of commands to concatenate... but I see no analogous lines to what I have in the Containerfile in neurodebian.yaml
didn't check but quite often to do such "where is it loaded" I "break" the medium -- make file not readable, or break json or yaml formatting -- that causes failure to occur and I see in the traceback where is it happening.
ha -- now read fully and saw that you thought alike ;) ok, will look inside now
so points to https://github.com/ReproNim/neurodocker/blob/HEAD/neurodocker/__init__.py#L16 -- that registers templates. And then all jinja templating happens in https://github.com/ReproNim/neurodocker/blob/HEAD/neurodocker/reproenv/renderers.py
Ok, so I think I finally found a test I think I could work off of.
Basically I'm looking for some test that shows how a neurodebian Containerfile is generated, and then determine how/what to change to get my gentoo Containerfile instead.
Sadly I get the following:
(mydev) [deco]~/src/neurodocker ❱ python -m pytest -vvs neurodocker/cli/tests/test_build_images_with_cli.py::test_gentoo_image
=========================================================== test session starts ============================================================
platform linux -- Python 3.11.8, pytest-8.1.1, pluggy-1.5.0 -- /home/chymera/src/neurodocker/.venvs/mydev/bin/python
cachedir: .pytest_cache
rootdir: /home/chymera/src/neurodocker
configfile: pyproject.toml
plugins: cov-5.0.0, reportlog-0.4.0, xdist-3.5.0
collected 1 item
neurodocker/cli/tests/test_build_images_with_cli.py::test_gentoo_image FAILED
================================================================= FAILURES =================================================================
____________________________________________________________ test_gentoo_image _____________________________________________________________
tmp_path = PosixPath('/tmp/pytest-of-chymera/pytest-10/test_gentoo_image0')
def test_gentoo_image(tmp_path: Path):
# also add singularity like in the test above
cmd = "neurodocker generate docker"
_TemplateRegistry._reset()
runner = CliRunner()
result = runner.invoke(
generate,
[
cmd,
"--pkg-manager apt",
"--base-image neurodebian:bullseye",
"--ants version=2.4.3",
"--user nonroot"
],
)
> assert result.exit_code == 0, result.output
E AssertionError: Usage: generate [OPTIONS] COMMAND [ARGS]...
E Try 'generate --help' for help.
E
E Error: No such command 'neurodocker generate docker'.
E
E assert 2 == 0
E + where 2 = <Result SystemExit(2)>.exit_code
cmd = 'neurodocker generate docker'
result = <Result SystemExit(2)>
runner = <click.testing.CliRunner object at 0x7f92bbd442d0>
tmp_path = PosixPath('/tmp/pytest-of-chymera/pytest-10/test_gentoo_image0')
neurodocker/cli/tests/test_build_images_with_cli.py:134: AssertionError
Any idea why this is happening?
The command works if I run it from bash — I got it from here → https://www.repronim.org/neurodocker/user_guide/quickstart.html
make it not cmd = "neurodocker generate docker"
but cmd = "docker"
-- look at other examples how it is done, e.g. git grep -A4 CliRunner
and see which "commands" are provided
cmd
neurodocker generate docker --pkg-manager portage --base-image gentoo --gentoo portage_image_version=20240324 --install afni
new command, works better:
neurodocker generate docker --pkg-manager portage --base-image "docker.io/gentoo/portage:20240324 as portage" --base-image "docker.io/gentoo/stage3:20240318" --gentoo gentoo_hash=2d25617a1d085316761b06c17a93ec972f172fc6 --install afni
Ongoing issues:
--gentoo
needs a parameter, won't work with no parameters even if they have defaultsas_
parameter for the FROM line generator but I couldn't figure out how to access this.@yarikoptic thanks for your help yesterday, I think I can navigate this better now, but feedback on the above would still be helpful :)
--gentoo
needs a parameter, won't work with no parameters even if they have defaults
IMHO worth filing a dedicated issue or PR to address that
- putting the entire docker resource link ...
sorry - already forgot what would be that resource link, but may be it is something to template in the urls:
?
3. There is an
as_
parameter for the FROM line generator but I couldn't figure out how to access this.
FWIW -- here is an example of a target use case - https://github.com/nimh-dsst/dsst-defacing-pipeline/pull/41
neurodocker generate docker --pkg-manager portage --copy --from=portage /var/db/repos/gentoo /var/db/repos/gentoo --base-image gentoo --gentoo gentoo_hash=2d25617a1d085316761b06c17a93ec972f172fc6 --install afni
This can be used to add the COPY line, but it does so at the beginning of the container file
This adds the COPY line after the RUN line from templates/gentoo.yaml
:
neurodocker generate docker --pkg-manager portage --base-image gentoo --gentoo gentoo_hash=2d25617a1d085316761b06c17a93ec972f172fc6 --copy --from=portage /var/db/repos/gentoo /var/db/repos/gentoo --install afni
Not sure how to control the position
this is the command we ended up testing with
neurodocker generate docker --pkg-manager portage --base-image gentoo --gentoo gentoo_hash=2d25617a1d085316761b06c17a93ec972f172fc6 >| Dockerfile && docker build -t test .
works with
neurodocker generate docker --pkg-manager portage --base-image gentoo --gentoo gentoo_hash=0e9370b45a589867220384ca6c63bc6bcaec3f74 --install afni >| Containerfile && podman build -t test .
any progress here to bring PR into the general usability and "ready for review" state @TheChymera ?
work in progress... from here.