Building custom images to install R and Python packages

You can build a custom image to use R and Python packages. Custom images are based on the SPSS Modeler runtime image available in Watson Studio.

Before you begin

Cluster administrator A cluster administrator must perform this task.

Note: If you use custom images, it is your responsibility to update your custom images with all the latest updates that are made to the available runtime images in Watson Studio. You are responsible for installing new fix packs, security updates, or any other updates. When new versions of Cloud Pak for Data are released, rebuilding all of your custom images is the best way to keep them updated.

About this task

You can use a custom image to optimize the standard configuration of an SPSS Modeler runtime. You can also use custom images in air-gapped environments that cannot expose any operations to the internet.

Procedure

  1. Prepare to build a new image.
    1. Get the registry URL to use for Docker commands and in scripts.

      The SPSS Modeler runtime images are stored in a Docker image registry. Use a private registry. You can use the URL to the registry that was used during the installation of Cloud Pak for Data. You can use a different registry, but then you need to configure Red Hat OpenShift so it can pull images from that registry. The registry that you use can be outside of the Red Hat OpenShift cluster.

      Use the same URL for all commands and in all the scripts that you run.

    2. Download the configuration file for the SPSS Modeler runtime image that you want to customize. For more information, see Downloading the runtime configuration.
    3. Download the image in the configuration. For more information, see Downloading the runtime image.
    4. Download the build-image-for-python-r-packages.zip that contains the Dockerfile and scripts for installing R and Python packages.
      The archive contains the following files:
      • install-packages.R is the main script to install R packages.
      • install-Python-packages.sh is the main script to install Python packages.
      • Dockerfile is the main entry to build the custom image.

  2. Create the custom runtime image with the files that you downloaded, and add your R or Python packages.
    1. Add customizations and build a new image. See Creating a custom image.
    2. In Dockerfile from the archive, update <spss-modeler-base-image> with the tag of the actual spss-modeler base image that you pulled from the IBM Entitled registry or a private Container Registry.
      Example of the Dockerfile:
      FROM <spss-modeler-base-image> as custom-runtime-for-python-r-packages
      
      USER modeler-user:modeler-user
      
      COPY --chown=modeler-user install-packages.R /tmp/install/
      COPY --chown=modeler-user install-Python-packages.sh /tmp/install/
      
      RUN umask 002 \
       && /opt/r/lib/R/bin/Rscript /tmp/install/install-packages.R \
       && bash /tmp/install/install-Python-packages.sh \
       && rm -rf /tmp/install
    3. If you are installing R packages, add all your package names to the list in install-packages.R. Every package name must be in double quotation marks.
      install.packages(c(
      "pkg-name1",
      "pkg-name2",
       ...),
      repos='http://cran.rstudio.com')
    4. If you are installing Python packages, add all your package names after the pip install command in install-Python-packages.sh.
      set -e -o pipefail
      MODELER_HOME=/opt/IBM/SPSS/ModelerServer/Cloud/
      LD_LIBRARY_PATH=$MODELER_HOME/python/lib $MODELER_HOME/python_venv/bin/pip install \
        pkg-name1 \
        pkg-name2 \
        ...
    5. If you want to install only R packages or only Python packages, comment out the line in Dockerfile for the installation that you want to skip.
      By default, Dockerfile invokes both install-packages.R and install-Python-packages.sh to install the R and Python packages together.
      • To install only R packages, comment out && bash /tmp/install/install-Python-packages.sh \.
      • To install only Python packages, comment out && /opt/r/lib/R/bin/Rscript /tmp/install/install-packages.R \.
  3. Push the image to the container server to register it.
    For more information, see Pushing the image to the registry.
  4. Change and upload the configuration file to use the new custom image.
    For more information, see Uploading the custom configuration.