improved docker images

This commit is contained in:
Patrick Schratz 2024-09-07 22:39:36 +02:00
commit 893afd4d98
Signed by: pat-s
GPG key ID: 3C6318841EF78925

View file

@ -3,6 +3,14 @@ FROM alpine:3.20
ENV PATH=/opt/R/4.4.1/bin:$PATH
ENV TZ="Europe/Berlin"
ENV ARCH=arm64
ENV NCPUS=2
ENV AWS_ACCESS_KEY_ID=""
ENV AWS_SECRET_ACCESS_KEY=""
ENV PGPASS=""
ARG GITHUB_PAT
# Background: JAGS needs lapack & lapack-dev but these conflict with openblas-dev which is required by R-dev
@ -23,7 +31,13 @@ RUN apk add -q --no-cache R-dev curl ca-certificates bash g++ tzdata openjdk17 t
# https://github.com/RcppCore/Rcpp/issues/448#issuecomment-220148774
# LDFLAGS+=-fPIC -> arrow (https://github.com/r-hub/r-minimal/blob/main/examples/arrow/Dockerfile)
RUN mkdir ~/.R && echo -e "CXXFLAGS+=-D__MUSL__\nCPPFLAGS+= -D__MUSL__\nLDFLAGS+=-fPIC" >> ~/.R/Makevars
# Makevars
RUN mkdir -p /root/.R && bash -c 'echo -e "CXX_STD = CXX14\nCC=ccache gcc\nCPP=ccache gcc\nCXX=ccache g++\nCXX11=ccache g++\nCXX14=ccache g++\nCXX17=ccache g++\nF77=ccache /usr/bin/gfortran\nFC=ccache /usr/bin/gfortran" >> /root/.R/Makevars'
RUN mkdir -p ~/.R && bash -c 'echo -e "CXXFLAGS+=-D__MUSL__\nCPPFLAGS+= -D__MUSL__\nLDFLAGS+=-fPIC" >> root/.R/Makevars'
# R repos
RUN bash -c 'echo -e "options(crayon.enabled = TRUE, Ncpus = ${NCPUS}, future.globals.onReference = NULL, repos = structure(c(devxy = \"https://cran.devxy.io/${ARCH}/alpine320/latest\", INLA = \"https://inla.r-inla-download.org/R/stable\", CRAN = \"https://cloud.r-project.org\")))" > /root/.Rprofile'
RUN bash -c 'echo -e "PKG_SYSREQS = TRUE\nPKG_SYSREQS_VERBOSE = TRUE" > /root/.Renviron'
### INSTALL R
RUN curl -O https://devxy-r-builds.s3.eu-central-2.amazonaws.com/alpine320/r-4.4.1_1_$(arch).apk
@ -31,11 +45,11 @@ RUN apk add --allow-untrusted r-4.4.1_1_$(arch).apk && rm r-4.4.1_1_$(arch).apk
RUN R -q -e 'install.packages("remotes", repo = "cloud.r-project.org"); remotes::install_github("pat-s/pak@alpine")'
COPY . .
RUN apk add libxml2-dev
# FIXME: switch to pak after https://github.com/r-lib/pak/issues/628
RUN export ARCH=$(echo $(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')) && \
R -q -e 'Sys.setenv(PKG_SYSREQS = TRUE, PKG_SYSREQS_VERBOSE = TRUE); options(Ncpus = 4, repos = structure(c(devxy = sprintf("https://cran.devxy.io/%s/alpine320/latest", Sys.getenv("ARCH")), CRAN = "https://cloud.r-project.org"))); install.packages("remotes"); remotes::install_deps()'
RUN rm -rf r-pkg-binaries
# deps from pak::pkg_deps(".")$package
RUN R -q -e 'pak::pak(c("DBI", "R6", "RPostgres", "Rcpp", "askpass", "base64enc", "bit64", "bit", "blob", "callr", "cli", "credentials", "curl", "data.table", "pat-s/desc@description-from-remote", "digest", "dplyr", "fansi", "fs", "future.apply", "future", "generics", "gert", "globals", "glue", "hms", "httr", "jsonlite", "lgr", "lifecycle", "listenv", "lubridate", "magrittr", "mime", "openssl", "parallelly", "paws.common", "paws.storage", "pillar", "pkgbuild", "pkgconfig", "processx", "progressr", "ps", "purrr", "rlang", "rstudioapi","s3fs", "stringi", "stringr", "sys", "tibble", "tidyselect", "timechange", "utf8", "vctrs", "withr", "xml2", "zip", "codetools", "pat-s/cranlike@s3", "RSQLite", "cachem", "crayon", "debugme", "fastmap", "memoise"))'
COPY . .
RUN R CMD INSTALL . && rm -rf r-pkg-binaries
CMD ["/bin/bash"]