简体   繁体   中英

R function devtools::install_github in a Dockerfile returns a 404 error

I'm writing a Dockerfile to create a docker image that builds on rocker/verse:3.6.1. I need to install R packages that are available on Github, and I need to install each package from a specific commit. I'm using a Dockerfile with the following contents:

FROM rocker/verse:3.6.1
LABEL maintainer='Unknown'
RUN  R -e "devtools::install_github('rstudio/renv', ref = '1584b7fccb49c2bd502ea4bdf3b7de27b0243561')" 

I see the output below after typing at the shell prompt docker build . in the directory that contains this Dockerfile.

 docker build .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM rocker/verse:3.6.1
 ---> 8a978a45abab
Step 2/3 : LABEL maintainer='Unknown'
 ---> Using cache
 ---> d054ca33baac
Step 3/3 : RUN  R -e "devtools::install_github('rstudio/renv', ref = '1584b7fccb49c2bd502ea4bdf3b7de27b0243561')"
 ---> Running in dea49b1bb351

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> devtools::install_github('rstudio/renv', ref = '1584b7fccb49c2bd502ea4bdf3b7de27b0243561')
Error: Failed to install 'unknown package' from GitHub:
  HTTP error 404.
  No commit found for the ref 1584b7fccb49c2bd502ea4bdf3b7de27b0243561

  Did you spell the repo owner (`rstudio`) and repo name (`renv`) correctly?
  - If spelling is correct, check that you have the required permissions to access the repo.
Execution halted
The command '/bin/sh -c R -e "devtools::install_github('rstudio/renv', ref = '1584b7fccb49c2bd502ea4bdf3b7de27b0243561')"' returned a non-zero code: 1

I have successfully installed the needed package (at the desired commit) when not using docker by entering in a shell

R -e "devtools::install_github('rstudio/renv', ref = '1584b7fccb49c2bd502ea4bdf3b7de27b0243561')" 

I can also succeed in building a docker image with this Dockerfile:

FROM rocker/verse:3.6.1
LABEL maintainer='Unknown'
RUN  R -e "devtools::install_github('rstudio/renv')" 

where I omit the explicit inclusion of the argument ref . However, I'm still struggling to build the image that I need.

I appreciate any solutions and explanations for these observations.

PS - here is the R code that I used to identify the commit hash:

github_lookup_commit_sha_and_date <- function(remote_pkg, date, limit = 1000){
  commits_list  <- gh::gh(paste0("/repos/", remote_pkg, "/commits"), .limit = limit) 
  commit_dates <- purrr::map(.x = commits_list, .f = function(x) lubridate::as_datetime(x$commit$author$date)) 
  commit_shas <- purrr::map_chr(.x = commits_list, .f = function(x)x$commit$tree$sha)
  tibble::tibble(commit_date = lubridate::as_datetime(unlist(commit_dates)), sha = commit_shas) %>%
    dplyr::filter(commit_date < as_datetime(date)) %>%
    dplyr::mutate(datetime_diff = abs(commit_date - as_datetime(date)), remote_package = remote_pkg) %>%
    dplyr::filter(datetime_diff == min(datetime_diff))
}

github_lookup_commit_sha_and_date("rstudio/renv", lubridate::as_date("2019-01-01"))

PPS - here is the output that I see when installing rstudio/renv outside docker.

> devtools::install_github('rstudio/renv', ref = '1584b7fccb49c2bd502ea4bdf3b7de27b0243561')
Downloading GitHub repo rstudio/renv@1584b7fccb49c2bd502ea4bdf3b7de27b0243561
✔  checking for file ‘/private/var/folders/wd/lxmyvz590xb81c5z1j88b3800000gn/T/RtmpNW1W3J/remotesc63521cc2a5d/rstudio-renv-1584b7f/DESCRIPTION’ ...
─  preparing ‘renv’:
✔  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘renv_0.0.1-42.tar.gz’

* installing *source* package ‘renv’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (renv)

My guess is that your hash specification is wrong. Please check commit hash.

在此处输入图片说明

Using a valid hash installs just fine.

> remotes::install_github('rstudio/renv', ref = '810b0da975840f408f0f9d61348cc797ff06eac8')
Downloading GitHub repo rstudio/renv@810b0da975840f408f0f9d61348cc797ff06eac8
✔  checking for file ‘/tmp/Rtmp6AVyuj/remotes765d1d4957b2/rstudio-renv-810b0da/DESCRIPTION’ ...
─  preparing ‘renv’:
✔  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘renv_0.6.0-118.tar.gz’

Installing package into ‘/home/romunov/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
* installing *source* package ‘renv’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (renv)

Also works from within docker

$ docker build -t testcase .
Sending build context to Docker daemon  3.628MB
Step 1/3 : FROM rocker/verse:3.6.1
 ---> 802df297107c
Step 2/3 : LABEL maintainer='Unknown'
 ---> Running in 098c39a9ec93
Removing intermediate container 098c39a9ec93
 ---> 09ead2a80379
Step 3/3 : RUN  R -e "remotes::install_github('rstudio/renv', ref = '810b0da975840f408f0f9d61348cc797ff06eac8')"
 ---> Running in 1ed4f5a3aea8

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> remotes::install_github('rstudio/renv', ref = '810b0da975840f408f0f9d61348cc797ff06eac8')
Downloading GitHub repo rstudio/renv@810b0da975840f408f0f9d61348cc797ff06eac8
✔  checking for file ‘/tmp/RtmpDBKP3J/remotes63de88040/rstudio-renv-810b0da/DESCRIPTION’ ...
─  preparing ‘renv’:
✔  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘renv_0.6.0-118.tar.gz’

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
* installing *source* package ‘renv’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (renv)
> 
> 
Removing intermediate container 1ed4f5a3aea8
 ---> 41166e3420e9
Successfully built 41166e3420e9
Successfully tagged testcase:latest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM