Andrewncf
Andrewncf

Reputation: 25

Google Cloud Run for Dockerized Rshiny app using RMySQL and EBImage. Having trouble installing the two listed packages when building app on GCR

This is my first real attempt at deploying an app to Google Cloud Run beyond a simple application. The instructions I am following were in this video along with other resources like this

There two issues I am having is that both RMySQL and EBImage fail to install while building the app on GCR.

Checking the logs I see the following error for RMySQL

Step #0 - "Build": * installing *source* package ‘RMySQL’ ...
Step #0 - "Build": ** package ‘RMySQL’ successfully unpacked and MD5 sums checked
Step #0 - "Build": ** using staged installation
Step #0 - "Build": Found mysql_config cflags and libs!
Step #0 - "Build": Using PKG_CFLAGS=-I/usr/include/mysql 
Step #0 - "Build": Using PKG_LIBS=-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lzstd -lssl -lcrypto -lresolv -lm
Step #0 - "Build": ** libs
Step #0 - "Build": rm -f RMySQL.so RMySQL-init.o connection.o db-apply.o driver.o exception.o fields.o result.o utils.o
Step #0 - "Build": gcc -I"/usr/local/lib/R/include" -DNDEBUG -I/usr/include/mysql   -I/usr/local/include   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RMySQL-init.c -o RMySQL-init.o
Step #0 - "Build": gcc -I"/usr/local/lib/R/include" -DNDEBUG -I/usr/include/mysql   -I/usr/local/include   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c connection.c -o connection.o
Step #0 - "Build": gcc -I"/usr/local/lib/R/include" -DNDEBUG -I/usr/include/mysql   -I/usr/local/include   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c db-apply.c -o db-apply.o
Step #0 - "Build": db-apply.c: In function ‘check_groupEvents’:
Step #0 - "Build": db-apply.c:426:7: error: ‘PROBLEM’ undeclared (first use in this function)
Step #0 - "Build":   426 |       PROBLEM
Step #0 - "Build":       |       ^~~~~~~
Step #0 - "Build": db-apply.c:426:7: note: each undeclared identifier is reported only once for each function it appears in
Step #0 - "Build": db-apply.c:426:14: error: expected ‘;’ before string constant
Step #0 - "Build":   426 |       PROBLEM
Step #0 - "Build":       |              ^
Step #0 - "Build":       |              ;
Step #0 - "Build":   427 |       "un-regongnized R/S data type %d", fld_Sclass[jcol]
Step #0 - "Build":       |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step #0 - "Build": make: *** [/usr/local/lib/R/etc/Makeconf:169: db-apply.o] Error 1
Step #0 - "Build": ERROR: compilation failed for package ‘RMySQL’
Step #0 - "Build": * removing ‘/usr/local/lib/R/site-library/RMySQL’

The docker file I tried using on this is

# get shiny server and R from the rocker project
FROM rocker/shiny:4.1.0

# system libraries
# Try to only install system libraries you actually need
# Package Manager is a good resource to help discover system deps
RUN apt-get update && apt-get install -y \
    libcurl4-gnutls-dev \
    libssl-dev

RUN apt-get update && \
    apt-get install -y default-libmysqlclient-dev

# install R packages required 
RUN R -e 'install.packages(c("RMySQL","DBI","tidyverse", "shiny", "plotly","googleCloudStorageR","shinyWidgets"), \
            repos="https://packagemanager.rstudio.com/cran/__linux__/focal/2021-04-23"\
          )'

RUN apt update
RUN apt-get install -y curl
RUN apt-get -y install libcurl4-openssl-dev

# install required R libraries https://stackoverflow.com/questions/70991621/installing-r-package-decipher-in-a-docker-image https://gist.github.com/zoevanhavre/ed78a14db3a8763e15457f04764b40e6

RUN Rscript -e 'requireNamespace("BiocManager"); BiocManager::install();' \
&& Rscript -e 'requireNamespace("BiocManager"); BiocManager::install("EBImage")' 

# copy the app directory into the image
COPY ./shiny-app/* /srv/shiny-server/

# run app
CMD ["/usr/bin/shiny-server"]

I have tried several different iterations of this but am unsure where I am going with this as I am very new here. For example I have looked into EBImage and saw this and this but I honestly am not sure where to even go here or where to start. If anyone had any help or other resources to learn with, that would be greatly appreciated.

Upvotes: 0

Views: 163

Answers (1)

Andrewncf
Andrewncf

Reputation: 25

Using this as my docker file seems to have resolved the issue on the install end. I am sure there are unnecessary things in this file, but it got the job done and I will be working on figuring out what is necessary

# get shiny server and R from the rocker project
FROM rocker/shiny-verse:4.0.5

# system libraries
# Try to only install system libraries you actually need
# Package Manager is a good resource to help discover system deps
RUN apt-get update && apt-get install -y \
    libcurl4-gnutls-dev \
    libssl-dev 
    
RUN apt-get update && \
    apt-get install -y default-libmysqlclient-dev
    
RUN apt-get update \
 && apt-get install -y --no-install-recommends \
   libfftw3-dev \
   gcc && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
 
RUN apt update
RUN apt-get install -y curl
RUN apt-get -y install libcurl4-openssl-dev
    
# install R packages required 
RUN R -e 'install.packages(c("DBI","tidyverse", "shiny", "plotly","googleCloudStorageR","shinyWidgets","BiocManager"), \
            repos="https://packagemanager.rstudio.com/cran/__linux__/focal/2021-04-23"\
          )'
          
RUN R -e "install.packages('RMySQL', repos='http://cran.rstudio.com/', version='0.10.21', dependencies=TRUE)"



# install required R libraries https://stackoverflow.com/questions/70991621/installing-r-package-decipher-in-a-docker-image https://gist.github.com/zoevanhavre/ed78a14db3a8763e15457f04764b40e6

RUN Rscript -e 'requireNamespace("BiocManager"); BiocManager::install();' \
&& Rscript -e 'requireNamespace("BiocManager"); BiocManager::install("EBImage")' 

# copy the app directory into the image
COPY ./shiny-app/* /srv/shiny-server/

# run app
CMD ["/usr/bin/shiny-server"]

Upvotes: 0

Related Questions