Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Apptainer/Singularity support #134

Merged
merged 33 commits into from
Apr 17, 2023
Merged

Conversation

e-kotov
Copy link
Contributor

@e-kotov e-kotov commented Apr 14, 2023

I have added support for Apptainer (formerly Singularity) containers.
To do this I:

  • moved a few helper functions from dockerize.R to installarion.R, specifically: .insert_materials_dir() and .write_dockerfile(). Also .write_dockerfile() is now more generic .write_container_file(), because it serves both dockerize() and apptainerize(). .insert_materials_dir() now also serves both functions and distinguishes between docker and apptainer/singularity containers. It seems safe to do so, all existing tests pass and I also added a separate test for it in test_apptainerize.R.
  • added apptainerize() function (with name variations). I am not sure you want to "pollute" the package with singularize() synonyms. Kindly let me know what you think.
  • covered apptainerize() with formal tests that mirror what you have for `dockerize()' + I did a lot of testing using the actual singularity module on a linux server. All singularity definitions seem to work just fine.
  • caching of debian rootfs tar does not work in an easy way for Apptainer/Singularity, as it requires user to have debootstrap installed https://apptainer.org/docs/user/latest/appendix.html#id17 therefore, at least for now, I think it is much more user friendly to skip the caching of Debian image and just use the Docker image of debian:eol in the Apptainer/Singularity definition.
  • updated README and FAQ vignette
  • extensively tested using Linux VPS, all Apptainer/Singularity image definition files that I get out of the new function seem to build without issues.

@codecov-commenter
Copy link

codecov-commenter commented Apr 14, 2023

Codecov Report

Merging #134 (b546f78) into v0.3 (d665fdf) will decrease coverage by 1.77%.
The diff coverage is 84.93%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             v0.3     #134      +/-   ##
==========================================
- Coverage   97.26%   95.50%   -1.77%     
==========================================
  Files          10       11       +1     
  Lines         988     1157     +169     
==========================================
+ Hits          961     1105     +144     
- Misses         27       52      +25     
Impacted Files Coverage Δ
R/dockerfile.R 100.00% <ø> (ø)
R/apptainer.R 82.53% <82.53%> (ø)
R/installation.R 93.97% <86.40%> (-3.45%) ⬇️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@chainsawriot chainsawriot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot again! These comments are some suggestions, mostly stylistic. I still need to conduct some smoke tests; and will report to you again.

(If you can, please also set the indentation to 4 spaces. Unfortunately, RStudio doesn't support the .editorconfig file provided. If you are using RStudio, you might add your .Rproj.)

R/installation.R Outdated Show resolved Hide resolved
R/installation.R Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
vignettes/faq.Rmd Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@chainsawriot
Copy link
Collaborator

chainsawriot commented Apr 15, 2023

Smoke

  • resolve("github::cran/psych", snapshot_date = "2013-01-01") (if prepend fixed)
  • resolve("chimeraviz", snapshot_date = "2023-01-01")
  • resolve("chimeraviz", snapshot_date = "2023-01-01") + quarto
  • resolve("chimeraviz", snapshot_date = "2023-01-01") + material (although the materials_dir seems to work differently to docker)
  • resolve(pkgs = "quanteda", snapshot_date = "2018-10-06") + rstudio

R/apptainer.R Outdated Show resolved Hide resolved
@chainsawriot
Copy link
Collaborator

chainsawriot commented Apr 16, 2023

@e-kotov Did you try to apptainerize with image = "rstudio"? I can't make it work.

somewhere <- ""
x <- resolve(pkgs = "quanteda", snapshot_date = "2018-10-06")
apptainerize(x, somewhere, image = "rstudio")

It can be built fine.

cd somewhere
apptainer build container.sif container.def

But can't be launched correctly. Specifically /init won't run.

 ## wouldn't run, with error
apptainer instance start container.sif
## can access via 0.0.0.0:8787, but error
apptainer exec container.sif /usr/lib/rstudio-server/bin/rserver --auth-none=1 --auth-pam-helper-path=pam-helper 
## password won't pass
PASSWORD='abc123' singularity exec container.sif /usr/lib/rstudio-server/bin/rserver --auth-none=0 --auth-pam-helper-path=pam-helper 

But I must admit I am a pretty lousy apptainer user (just learned to use it 72 hours ago). Maybe you would have a better idea how it works.

@e-kotov
Copy link
Contributor Author

e-kotov commented Apr 16, 2023

@chainsawriot I have tested, but in a slightly different environment. I am woking on (a) fixes and (b) readme for apptainer. Some more testing needs to be done, as it does not work in every environment reliably yet. I have addressed most of your comments already, but I have not pushed my commits to GitHub yet. I will let you know once I re-check everything so that you don't have to spend your time troubleshooting.

Thanks for your feedback and patience.

@e-kotov
Copy link
Contributor Author

e-kotov commented Apr 17, 2023

@e-kotov Did you try to apptainerize with image = "rstudio"? I can't make it work.

I did some more testing and here are the details on how to run those. I am also adding the info below to package readme, Apptainer readme template and FAQ vignette.

To run RStudio IDE in Apptainer/Singularity container, some writeable folders and a config file have to be created locally:

mkdir -p run var-lib-rstudio-server .rstudio
printf 'provider=sqlite\ndirectory=/var/lib/rstudio-server\n' > database.conf

After that, you can run the container (do not run as root user, otherwise you will not be able to login to RStudio IDE).

Start instance (on default RSTUDIO port 8787):

apptainer instance start \
    --bind run:/run,var-lib-rstudio-server:/var/lib/rstudio-server,database.conf:/etc/rstudio/database.conf,.rstudio:/home/rstudio/.rstudio/ \
    container.sif \
    rangtest

Now open a browser and go to localhost:8787.
The default username is your local username, default password is 'set_your_password' (if you are using container generated by rang).

List running instances:

apptainer instance list

Stop instance:

apptainer instance stop rangtest

Start instance with custom port (e.g. 8080) and password:

apptainer instance start \
    --enc RPORT=8080
    --env PASSWORD='set_your_password' \
    --bind run:/run,var-lib-rstudio-server:/var/lib/rstudio-server,database.conf:/etc/rstudio/database.conf,.rstudio:/home/rstudio/.rstudio/ \
    container.sif \
    rangtest

Run container with custom rserver command line:

apptainer exec \
    --env PASSWORD='set_your_password' \
    --bind run:/run,var-lib-rstudio-server:/var/lib/rstudio-server,database.conf:/etc/rstudio/database.conf,.rstudio:/home/rstudio/.rstudio/ \
    container.sif \
    /usr/lib/rstudio-server/bin/rserver \
    --auth-none=0 --auth-pam-helper-path=pam-helper \
    --server-user=$(whoami) --www-port=8787

If you run the container using apptainer exec command, you will have to kill the rserver process manually or Cmd/Ctrl+C from the running container to stop the server.

@e-kotov
Copy link
Contributor Author

e-kotov commented Apr 17, 2023

@chainsawriot I have addressed all of your review suggestions and questions and have done some more testing on a VPS with both admin and user privileges. I hope my README additions will easily allow you to check the updates and successfully run an Apptainer container.

@e-kotov
Copy link
Contributor Author

e-kotov commented Apr 17, 2023

For quicker tests, I use:

somewhere <- ""
x <- resolve(pkgs = "data.table", snapshot_date = "2019-10-06")
apptainerize(x, somewhere, image = "rstudio")

It is not 'foolproof', but for quick iteration it is ideal, as data.table has no dependencies and builds very quickly during container builds.

e-kotov added 2 commits April 17, 2023 17:08
…pteinerize() and are carbon copies of tests in tests_dockerize.R
@chainsawriot
Copy link
Collaborator

@e-kotov Thanks a lot! I can get all smoke tests running. I will merge it now. I think there are still some minor issues related to the documentation. But those can be fixed later.

Again, thanks a lot for your tremendous contribution to this package!

@chainsawriot chainsawriot merged commit de2e349 into gesistsa:v0.3 Apr 17, 2023
@e-kotov
Copy link
Contributor Author

e-kotov commented Apr 17, 2023

@chainsawriot Thank you too! I will look out for issues on your repo related to Apptainer/Singularity.

@e-kotov e-kotov deleted the singularity branch April 18, 2023 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants