【问题标题】:R function devtools::install_github in a Dockerfile returns a 404 errorDockerfile 中的 R 函数 devtools::install_github 返回 404 错误
【发布时间】:2019-08-17 02:56:01
【问题描述】:

我正在编写一个 Dockerfile 来创建一个基于 rocker/verse:3.6.1 的 docker 映像。我需要安装 Github 上可用的 R 包,并且我需要安装来自特定提交的每个包。 我正在使用具有以下内容的 Dockerfile:

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

在包含此 Dockerfile 的目录中,在 shell 提示符下输入 docker build . 后,我看到了以下输出。

 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

在不使用 docker 时,我通过进入 shell 成功安装了所需的包(在所需的提交处)

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

我也可以用这个 Dockerfile 成功构建一个 docker 镜像:

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

我省略了参数ref 的显式包含。但是,我仍在努力构建我需要的图像。

感谢您对这些观察结果的任何解决方案和解释。

PS - 这是我用来识别提交哈希的 R 代码:

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 - 这是我在 docker 外部安装 rstudio/renv 时看到的输出。

> 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)

【问题讨论】:

  • 可以以某种方式缓存您的哈希吗? checking for file ‘/private/var/folders/wd/lxmyvz590xb81c5z1j88b3800000gn/T/RtmpNW1W3J
  • 我想这是可能的。您能否建议我如何知道它是否在本地缓存?

标签: r docker github dockerfile devtools


【解决方案1】:

我的猜测是您的哈希规范是错误的。请检查提交哈希。

使用有效的哈希安装就好了。

> 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)

也可以在 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

【讨论】:

  • 我复制了你的结果。但是,我仍然不明白为什么我的哈希在 docker 外部运行时会导致安装成功,而不是在内部运行。
  • @FredBoehm 这个哈希有什么特别之处?
  • 据我所知,哈希并没有什么特别之处。我之所以选择它,是因为它是日期最近的哈希 - 2019 年 1 月 1 日 - 我想要包。
  • @FredBoehm 我滚动浏览了所有提交页面,但从 2019 年 1 月 1 日起找不到一个。12 月 27 日和 1 月 3 日是该日期前后唯一存在的日期,或者我可能是缺少一些东西。
  • 是的,没错。我的目标是指定一个日期并找到该日期“最近”的提交,即在指定日期之前的最短时间。我相信 12 月 27 日的提交具有我在上面对 devtools::install_github 的调用中指定的哈希值。
猜你喜欢
  • 2016-02-17
  • 2014-06-10
  • 1970-01-01
  • 2021-08-06
  • 2014-06-06
  • 2019-07-01
  • 2015-10-17
  • 2017-02-01
  • 1970-01-01
相关资源
最近更新 更多