-
Notifications
You must be signed in to change notification settings - Fork 236
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
Packrat support #110
Comments
I guess there are two ways of addressing this. Firstly, for the least impact in the short term, taking your approach, using the Secondly, in the medium term, to add "native support" by including packrat by default, changing the detection logic to look for a packrat directory (and/or packrat.lock file) in the root (possibly removing the need for the init.R file) to determine whether the R buildpack applies, and then to run the restore. I'll try and get the first option working in the meantime. |
Thanks for looking into this. My workaround for the time being is to parse the packrat.lock file myself in init.R and install the packages from the tarballs already contained in packrat/src: install.packages("remotes")
pkgs <- as.data.frame(read.dcf("/app/packrat/packrat.lock")[-1, , drop = FALSE])
for (i in 1:nrow(pkgs)) {
pkg <- pkgs[i, ]
message("Trying to install ", pkg$Package)
if (pkg$Package %in% rownames(installed.packages())) {
message(pkg$Package, " is already installed")
} else if (pkg$Source == "CRAN") {
f <- file.path("/app/packrat/src", pkg$Package, paste0(pkg$Package, "_", pkg$Version, ".tar.gz"))
message("...from ", f)
remotes::install_local(f, INSTALL_opts = "--no-docs --no-help --no-demo")
} else if (pkg$Source == "github") {
f <- file.path("/app/packrat/src", pkg$Package, paste0(pkg$GithubSha1, ".tar.gz"))
message("...from ", f)
remotes::install_local(f, INSTALL_opts = "--no-docs --no-help --no-demo")
}
} Packrat supports more sources than just CRAN and GitHub, but this is good enough for my purposes right now. Note: I also had to add .Rprofile to .slugignore so that that |
Yes, I found the issue with execution of the I've experimented with the first approach I suggested above, but without much luck. The main issue is that since the I have reached out to the Heroku team to see whether they have any ideas for a better way to package R given it's unique requirements and the restrictions imposed during slug compilation; which is why I had to resort to using a fake chroot. |
See the heroku-buildpack-r-packrat-test project. You will see that Also since |
Hey @virtualstaticvoid, did the Heroku team have any ideas? |
Hi @ankane Yes, their feedback was to use the container stack together with a build manifest (heroku.yml). I went ahead and implemented a compatible solution which will work for most cases, but will require rework if multiple buildpacks were used. Currently I am working on implementing "native support" for packrat in the buildpack. See heroku-16-packrat branch. Note that this is still work in progress. |
Thanks @virtualstaticvoid, I'll check out that branch. The general issue I've seen with container only solutions is it doesn't allow for the same fine-grained caching as buildpacks (like package-level caching). Even as containers gain popularity, I still think buildpacks are needed for fast deploys (Dokku does a great job combining both technologies). |
+1 I definitely need packrat support in my project but I also need to run R along with Ruby, so it looks like the container approach is the way to go |
Fixed by #123 . |
Packrat is, in my opinion, a necessary component in R projects these days, especially if there are multiple developers and/or multiple servers running your project's code.
While I could write my init.R to specify the exact package versions to install, it would be great if this buildpack could use Packrat to install dependencies since we're using it anyway.
When I deploy my code to a VPS for the first time (or when I add a dependency), it's just a matter of running
packrat::restore()
inside the project folder. If you're not familiar with the package, there's a local .Rprofile file that sources packrat/init.R. Therestore
function parses packrat/packrat.lock, which is like the Gemfile.lock file in a Ruby project, and runsinstall.packages
for each specific package version. Tarballs for the dependencies are already in packrat/src/ (since they're checked in to git) and the dependencies are installed into packrat/lib/x86_64-apple-darwin15.6.0/3.4.3 (which is gitignored). So no need to go out to CRAN and download them, which is nice.In my buildpack's init.R (not the packrat/init.R), I figured you could do something this:
This doesn't work, though, since I'm apparently not in the app directory. If I replace the last three lines with
then
git push heroku master
printsSo
/app
symlinks to a temp directory, which contains my app files. But when I try to enter that directory, the files disappear. Any idea what's going on? Thanks!The text was updated successfully, but these errors were encountered: