This directory contains the stable OpenFaaS R templates.
The templates follow a similar structure:
.
├── Dockerfile
├── README.md
├── Rprofile.site
├── function
│ ├── DESCRIPTION
│ └── handler.R
├── index.R
├── install.R
└── template.yml
./Dockerfile
: the container is based on this file,./README.md
: description and examples for the template,./Rprofile.site
: R startup options, e.g. repositories, etc.,./function/DESCRIPTION
: R package dependencies for the handler to be edited by the user,./function/handler.R
: R handler to be edited by the user,./index.R
: this is the R entry point receiving the request and outputting the response,./install.R
: utility function used to handle dependencies in theDockerfile
,./template.yml
: stack file specifying the language for the template and the init process for your container, see the YAML reference for additional details.
The files the users are supposed to edit are inside the function folder,
users might put other files here that will be copied into the /home/app
folder of the Docker image. The handler file usually contains a function called
handler
that the index.R
entry point calls. See the template readme file
for specific instructions.
The Dockerfile
install script handles dependencies as specified in the
DESCRIPTION
file in this order:
SystemRequirements:
list OS specific sysreqs here, comma separated, these are then installed by the OS's package manager,- CRAN packages listed in
Depends:
,Imports:
,LinkingTo:
fields are installed byremotes::install_deps()
, Remotes:
fields are installed according to remotes specs, make sure to list the package inImports:
as well, the location specified inRemotes:
will be used to get the package from,VersionedPackages:
this field can be used to pin package versions usingremotes::install_version()
, do not list these packages in other fields (spaces after operators and commas inside parenthesis are important).
An example DESCRIPTION
file might look like this:
Package: OpenFaaS
Version: 0.0.1
Imports:
jsonlite,
vegan
Remotes:
vegandevs/vegan
SystemRequirements:
git-core,
libssl-dev,
libcurl4-gnutls-dev
VersionedPackages:
devtools (>= 1.12.0, < 1.14),
mypackage (0.1.0)
You can also modify the Dockerfile
in the template if specific
R version or further customization is needed. The R parent image is defined as a Docker ARG
called R_IMAGE
that you can override. I.e. use the versioned Rocker Debian image using custom build arguments: --build-arg R_IMAGE=rocker/r-base:4.0.0
, etc. You can also edit the stack YAML file.
The templates are using the following parent images:
- Debian-based
rocker/r-base
Docker image from the rocker project for bleeding edge, - Ubuntu-based
rocker/r-ubuntu
Docker image from the rocker project for long term support (uses RSPM binaries), - Alpine-based
rhub/r-minimal
Docker image the r-hub project for smallest image sizes.
System requirements for the same packages might be different across Linux distros. This is a grey area of the R package ecosystem, see rstudio/r-system-requirements, r-hub/sysreqsdb, and https://r-universe.dev/ for help. The maketools R package makes it easy to determine run-time and build-time dependencies for the packages.