Search code examples
rdockerjenkinsdockerfilerscript

Docker build is slow on Jenkins


I'm trying to build a docker image through a Jenkins pipeline which is taking a really long time (4-5 hours and most times failing). When I build the image from the command line of the same Jenkins machine, it is taking around 20 minutes. These are the Dockerfile commands at which the job is stalling -

ARG PKGS="askpass, assertthat, backports, base64enc, BH, bit, bit64, blob, brew, brio, broom, callr, caret, cellranger, chron, cli, clipr, colorspace, commonmark, config, covr, cpp11, crayon, credentials, crosstalk, curl, data.table, DBI, dbplyr, desc, devtools, diffobj, digest, dplyr, DT, ellipsis, evaluate, fansi, farver, fastmap, forcats, foreach, forge, fs, future, generics, gert, ggplot2, gh, gitcreds, glmnet, globals, glue, gower, gridExtra, gsubfn, gtable, haven, highr, hms, htmlwidgets, httpuv, httr, ini, ipred, isoband, iterators, jsonlite, knitr, labeling, later, lava, lazyeval, lifecycle, listenv, lubridate, magrittr, markdown, memoise, mime, ModelMetrics, modelr, munsell, numDeriv, openssl, parallelly, pillar, pkgbuild, pkgconfig, pkgload, plogr, plyr, praise, prettyunits, pROC, processx, prodlim, progress, promises, proto, ps, purrr, r2d3, R6, randomForest, rappdirs, rcmdcheck, RColorBrewer, Rcpp, readxl"
# Install through pak and other cleanup tasks
RUN Rscript -e 'install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")' \
    && echo "$PKGS" \
    | Rscript -e 'pak::pkg_install(strsplit(readLines("stdin"), ", ?")[[1L]], ask = FALSE)' \
    && Rscript -e 'pak::cache_clean()'

ARG PKGS="recipes, rematch, rematch2, remotes, reprex, reshape2, rex, rlang, rmarkdown, roxygen2, rprojroot, RSQLite, rstudioapi, rversions, rvest, scales, selectr, sessioninfo, shape, shiny, sourcetools, sparklyr, SparkR, sqldf, SQUAREM, stringi, stringr, sys, testthat, tibble, tidyr, tidyselect, tidyverse, timeDate, tinytex, usethis, utf8, uuid, vctrs, viridisLite, waldo, whisker, withr, xfun, xml2, xopen, xtable, yaml, zip"
# Install through pak and other cleanup tasks
RUN Rscript -e 'install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")' \
    && echo "$PKGS" \
    | Rscript -e 'pak::pkg_install(strsplit(readLines("stdin"), ", ?")[[1L]], ask = FALSE)' \
    && Rscript -e 'pak::cache_clean()'

I suspect this has something to do with Jenkins since the build goes through fine from the command line. Is there some setting in Jenkins that is slowing down the download and install of these packages? Thank you.


Solution

  • Figured this out, needed to escape the $ character with a preceding \ so that it doesn't get evaluated. Basically replace "$PKGS" with "\\$PKGS".