ThinkR-open / dockerfiler

Easy Dockerfile Creation from R
https://thinkr-open.github.io/dockerfiler/
Other
176 stars 26 forks source link

Add options(warn = 2) to Dockerfile #9

Open ColinFay opened 3 years ago

ColinFay commented 3 years ago

remotes::install will not make the Dockerfile fail if there is an error. options(warn = 2) solves that.

[node1] (local) root@192.168.0.13 ~
$ echo "FROM rocker/tidyverse:latest" >> Dockerfile
[node1] (local) root@192.168.0.13 ~
$ echo "RUN Rscript -e 'remotes::install_cran(\"pouetpouet\")'" >> Dockerfile
[node1] (local) root@192.168.0.13 ~
$ docker build -t pouet .
Sending build context to Docker daemon     47MB
Step 1/2 : FROM rocker/tidyverse:latest
 ---> b17fba18db1d
Step 2/2 : RUN Rscript -e 'remotes::install_cran("pouetpouet")'
 ---> Running in c1e4ba816fc5
Installing 1 packages: pouetpouet
Installing package into '/usr/local/lib/R/site-library'
(as 'lib' is unspecified)
Warning message:
package 'pouetpouet' is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages 
Removing intermediate container c1e4ba816fc5
 ---> caaeea9ce5aa
Successfully built caaeea9ce5aa
Successfully tagged pouet:latest

vs

[node1] (local) root@192.168.0.13 ~
$ echo "FROM rocker/tidyverse:latest" >> Dockerfile
[node1] (local) root@192.168.0.13 ~
$ echo "RUN Rscript -e 'options(warn=2);remotes::install_cran(\"pouetpouet\")'" >> Dockerfile
[node1] (local) root@192.168.0.13 ~
$ docker build -t pouet .
Sending build context to Docker daemon     47MB
Step 1/2 : FROM rocker/tidyverse:latest
 ---> b17fba18db1d
Step 2/2 : RUN Rscript -e 'options(warn=2);remotes::install_cran("pouetpouet")'
 ---> Running in 7a0ce0031ffa
Installing 1 packages: pouetpouet
Installing package into '/usr/local/lib/R/site-library'
(as 'lib' is unspecified)
Error: Failed to install 'pouetpouet' from CRAN:
  (converted from warning) package 'pouetpouet' is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Execution halted
The command '/bin/sh -c Rscript -e 'options(warn=2);remotes::install_cran("pouetpouet")'' returned a non-zero code: 1
[node1] (local) root@192.168.0.13 ~
statnmap commented 3 years ago

Not sure it will be enough for all.

RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
# Add option to warn and stop
RUN R -e 'options(warn = 2);remotes::install_local(upgrade="never")'
RUN rm -rf /build_zone

image

Docker continues...

Same with Rscript

Step 46/52 : RUN Rscript -e 'options(warn = 2);remotes::install_local(upgrade="never")'
 ---> Running in 09e43edd13e4
Error : Could not copy `/build_zone` to `/tmp/Rtmpv66clL/file771f45e69`
Removing intermediate container 09e43edd13e4
 ---> 1653bab57384
Step 47/52 : RUN rm -rf /build_zone
 ---> Running in 4ad3b57dfd3a

Well, my error is already an error. Do not have to convert warning to error... But this error does not lead to stop building container

statnmap commented 3 years ago

Maybe you can use this at the beginning of the Dockerfile:

# Transform warns as errors
RUN echo "options(warn = 2);" >> $R_HOME/etc/Rprofile.site

Then set back by removing the last line

# Remove option to warn and stop
RUN head -n -1 $R_HOME/etc/Rprofile.site
# or this one if you are not sure other lines are added during the installation process
RUN echo "options(warn = -1);" >> $R_HOME/etc/Rprofile.site