Skip to content

Commit 1009041

Browse files
committed
Specify base image when writing Dockerfile
1 parent 3c43000 commit 1009041

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

β€ŽDockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# ----- R Package Dockerfile -----
2+
#
3+
# This Dockerfile is designed for developers of any R package stored on GitHub.
4+
#
5+
# It runs several steps:
6+
# 1. Pulls the official bioconductor Docker container (which includes Rstudio).
7+
# 2. Runs CRAN checks on the R package.
8+
# 3. Installs the R package and all of its dependencies (including Depends, Imports, and Suggests).
9+
#
10+
# You can then create an image of the Docker container in any command line:
11+
# docker pull <DockerHub_repo_name>/<package_name>
12+
# Once the image has been created, you can launch it with:
13+
# docker run -d -e ROOT=true -e PASSWORD=bioc -v ~/Desktop:/Desktop -v /Volumes:/Volumes --rm -p 8788:8787 <DockerHub_repo_name>/<package_name>
14+
# Finally, launch the containerised Rstudio by entering the following URL in any web browser:
15+
# http://localhost:8788/
16+
#
17+
# The username will be "rstudio" by default,
18+
# and you can set the password to whatever you like,
19+
#
20+
# This DockerFile was partly adapted from the [scFlow Dockerfile](https://github.com/combiz/scFlow/blob/master/Dockerfile).
21+
FROM $CONT
22+
RUN apt-get update && \
23+
apt-get install -y \
24+
git-core \
25+
libcurl4-openssl-dev \
26+
libgit2-dev \
27+
libicu-dev \
28+
libssl-dev \
29+
make pandoc \
30+
pandoc-citeproc \
31+
zlib1g-dev \
32+
xfonts-100dpi \
33+
xfonts-75dpi \
34+
biber \
35+
libsbml5-dev \
36+
qpdf \
37+
cmake \
38+
&& apt-get clean \
39+
&& rm -rf /var/lib/apt/lists/*
40+
# Create a buildzone folder named after the R package
41+
# BiocCheck requires the buildzone to have the same name as the R package
42+
ARG PKG
43+
RUN echo $PKG
44+
RUN mkdir -p /$PKG
45+
ADD . /$PKG
46+
WORKDIR /$PKG
47+
# Install dependencies with AnVil (faster)
48+
RUN Rscript -e 'options(download.file.method="libcurl", crayon.enabled=TRUE, timeout=2000); \
49+
if(!require("BiocManager")) install.packages("BiocManager"); \
50+
if(!require("AnVIL")) {BiocManager::install("AnVIL", ask = FALSE)}; \
51+
AnVIL::install(c("remotes","devtools")); \
52+
try({remotes::install_github("bergant/rapiclient")}); \
53+
bioc_ver <- BiocManager::version(); \
54+
options(repos = c(AnVIL::repositories(),\
55+
AnVIL = file.path("https://bioconductordocker.blob.core.windows.net/packages",bioc_ver,"bioc"),\
56+
CRAN = "https://cran.rstudio.com/"),\
57+
download.file.method = "libcurl", Ncpus = 2); \
58+
deps <- remotes::dev_package_deps(dependencies = TRUE)$package; \
59+
AnVIL::install(pkgs = deps, ask = FALSE); \
60+
deps_left <- deps[!deps %in% rownames(installed.packages())]; \
61+
if(length(deps_left)>0) devtools::install_dev_deps(dependencies = TRUE, upgrade = "never");'
62+
# Install R package from source
63+
RUN R -e 'options(crayon.enabled = TRUE); \
64+
remotes::install_local(upgrade="never")'
65+
RUN rm -rf /$PKG

β€ŽR/use_dockerfile.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#'
33
#' Creates a Docker file to be used with the GitHub Actions (GHA) workflows
44
#' distributed by \pkg{rworkflows}.
5+
#' @param base_image Base Docker image to use.
56
#' @param save_dir Directory to save the Docker file to.
67
#' @param path Path to the Docker file.
78
#' @param force_new If a Docker file already exists, overwrite it
@@ -17,9 +18,11 @@
1718
#' path <- use_dockerfile(save_dir=tempdir())
1819
use_dockerfile <- function(save_dir=here::here(),
1920
path=file.path(save_dir,"Dockerfile"),
21+
base_image=construct_cont()[[1]],
2022
force_new=FALSE,
2123
show=FALSE,
2224
verbose=TRUE){
25+
# devoptera::args2vars(use_dockerfile)
2326

2427
if(file.exists(path) &&
2528
isFALSE(force_new)){
@@ -31,6 +34,9 @@ use_dockerfile <- function(save_dir=here::here(),
3134
package = "rworkflows"),
3235
to = path,
3336
overwrite = TRUE)
37+
txt <- readLines(path)
38+
txt <- gsub("^FROM \\{BASE_IMAGE\\}",paste("FROM",base_image),txt)
39+
writeLines(txt,path)
3440
}
3541
if(isTRUE(show)){
3642
messager("Docker file preview:",v=verbose)

β€Žaction.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,12 @@ runs:
486486
- name: 🐳✏️ Create Docker file
487487
if: |
488488
(!contains(github.event.head_commit.message, '/nodocker')) && inputs.run_docker == 'true' && runner.os == 'Linux'
489+
env:
490+
BASE_IMAGE: ${{ matrix.config.cont }}
489491
run: |
490492
options(crayon.enabled = TRUE)
491493
if(!require("rworkflows", quietly=TRUE)) remotes::install_github("neurogenomics/rworkflows")
492-
path <- rworkflows::use_dockerfile()
494+
path <- rworkflows::use_dockerfile(base_image=Sys.getenv("BASE_IMAGE"))
493495
shell: Rscript {0}
494496

495497
- name: πŸ³πŸš€ Build and push to GHCR

β€Žinst/templates/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# and you can set the password to whatever you like,
1919
#
2020
# This DockerFile was partly adapted from the [scFlow Dockerfile](https://github.com/combiz/scFlow/blob/master/Dockerfile).
21-
FROM $BASE_IMAGE
21+
FROM {BASE_IMAGE}
2222
RUN apt-get update && \
2323
apt-get install -y \
2424
git-core \

β€Žman/use_dockerfile.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)