rocker-org / devcontainer-features

A collection of Dev Container Features.
https://rocker-project.org/images/devcontainer/features.html
MIT License
52 stars 16 forks source link

[r-packages] Install dependencies from DESCRIPTION #208

Closed dpprdan closed 6 months ago

dpprdan commented 11 months ago

Is there a way to install packages from a DESCRIPTION file in the same repo? This would help to DRY, i.e. not having to specify dependencies in two places, namely DESCRIPTION and devcontainer.json

Specifying deps::. like this does not seem to work:

"features": {
    "ghcr.io/rocker-org/devcontainer-features/r-packages:1": {
        "packages": "deps::."
    }
}
93.80 > pak::repo_add(); pak::pak(trimws(unlist(strsplit('deps::.', ',')))); pak
::cache_clean()
100.0 Error:
100.0 ! error in pak subprocess
100.0 Caused by error:
100.0 ! Could not solve package dependencies:
100.0 * deps::.: ! pkgdepends resolution error for deps::..
100.0 Caused by error:
[2023-12-14T18:38:20.820Z] 
100.0 ! No root directory found in /tmp/r-packages or its parent directories. Ro
ot criterion: contains a file "DESCRIPTION" with contents matching "^Package: "
100.0 ---

I assume this is because DESCRIPTION is not yet available in the container when the feature is run?

Is there a way to make it available or should what I want be specified differently?

eitsupi commented 11 months ago

In general, I think that it is assumed that the processing that depends on the files in the repository will be handled by the lifecycle scripts. https://containers.dev/implementors/json_reference/#lifecycle-scripts

Alternatively, we can use the COPY clause in the Dockerfile to copy the file and reference it at build time, but this is not ideal because it means that we have to redo the build every time we update the contents of the repository. Like this: https://github.com/mamba-org/devcontainer-features/tree/main/src/micromamba#create-a-new-environment-with-the-envfile-option

Wild examples I have: https://github.com/eitsupi/prqlr/blob/9284c2d11a3c8115067d4b1031ccfeb355185385/.devcontainer/devcontainer.json#L37-L39 https://github.com/eitsupi/querying-with-prql/blob/4dcdfd6b58d7860ae6d29f9299ef1175f309061e/.devcontainer/devcontainer.json#L22-L26

eitsupi commented 6 months ago

I believe this can be accomplished by using lifecycle scripts set by the Feature. I would like this functionality and will try to implement it.

eitsupi commented 6 months ago

This is a completely different behavior from the existing r-packages feature and should probably be implemented as a separate Feature.

eitsupi commented 6 months ago

@dpprdan Could you try https://github.com/rocker-org/devcontainer-features/tree/main/src/r-dependent-packages?

dpprdan commented 6 months ago

@eitsupi Sorry, I haven't been able to try this out yet and will not for another two weeks. But definitely looking forward to it and will do it ASAP!

eitsupi commented 6 months ago

FYI, a usage example is here: https://github.com/eitsupi/r-glaredb/blob/f47e4426b2859f27ef8d00a3277d6b80bd0a4740/.devcontainer/devcontainer.json#L8-L30