[R-sig-Debian] Trying to install r-stan without using rocker

Jesse McMullen-Crummey je@@e @end|ng |rom voxpop|@b@@com
Mon Jun 13 18:19:41 CEST 2022


Hi All,

   I found your mailing list via a stack overflow mention.  I’m currently on my second full day of trying to build a docker container to use as an AWS lambda fcn and am feeling pretty stuck - I was hoping someone here could help.  It needs to support python+R+rstan.


I currently construct the docker image from a python/debian base image.  I can get R working fine, but when I try to run an r-stan script within the lambda function I get a ’there is no package called Stan”, despite a good 5 minutes of the image build being dedicated to the download of rstan.  Am looking for advice here on how to proceed.  My current dockerfile follows…

################
FROM python:3.8-slim-bullseye

ENV DEBIAN_FRONTEND=noninteractive

ENV LC_ALL=C.UTF-8
ENV LANG=en_US.UTF-8
ENV TZ=:/etc/localtime
ENV PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin
ENV LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
ENV LAMBDA_TASK_ROOT=/var/task
ENV LAMBDA_RUNTIME_DIR=/var/runtime

# Define custom function directory
ARG FUNCTION_DIR="/var/task"
WORKDIR ${FUNCTION_DIR}

# Install aws-lambda-cpp build dependencies + r
RUN apt-get update && \
  apt-get install -y \
  g++ \
  make \
  cmake \
  unzip \
  libcurl4-openssl-dev \
  r-base 

COPY requirements.txt  .
COPY irt_dim_red.R .
COPY . .

#install the python requirements
RUN pip install -r requirements.txt

COPY scripts/install_stan.R install_stan.R

RUN Rscript "install_stan.R"
RUN R -e "install.packages('stringr')"
RUN R -e "install.packages('gtools')"
RUN R -e "install.packages('tidyr')"

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "main.handler"]
Where the script install_rstan.R is:

# Following instructions from
# https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux

print("Running install_stan.R")

## Creating /home/rstudio/.R/Makevars

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars")
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native -mtune=native -fPIC",
    "CXX14=clang++",
    file = M, sep = "\n", append = TRUE)

## Installing rstan

install.packages("rstan", dependencies=TRUE, type = "source")

Any help would be massively appreciated.

Jesse


—


Jesse McMullen-Crummey, PhD (he/him)
Data Engineer


	[[alternative HTML version deleted]]



More information about the R-SIG-Debian mailing list