Updating a custom image

Following an upgrade from certain versions of Cloud Pak for Data, you must update the custom image. This update applies only to upgrades from Cloud Pak for Data versions up to and including 4.0.6.

For Watson Machine Learning custom images, the runtime definition file ties the software specification with the custom image. This file maps the software specification to the custom image, and can be updated. To update the file, follow the steps in Updating the runtime definition file with the new image.

Note:

A compatible image must have package files accessible to users with group name condausers and group id 103000.

Updating a custom image from previous versions of Cloud Pak for Data

Updating a custom image from previous versions of Cloud Pak for Data to the latest version of Cloud Pak for Dataincreases the image size by more than 7 GB. The exact size depends on the number of files. Therefore, it is recommended to use a fresh base image with the latest version of Cloud Pak for Data.

Follow these steps to update a custom image:

  1. Update the Docker image, with the sample file and then run these commands:

    podman build  -t <custom_image_name_for_cpd40>:<new_tag> --build-arg base_image_tag=<custom_image_name_from_cpd3.5>:<tag> -f Dockerfile
    
  2. Customize, and then upload the Watson Machine Learning base image. For details, refer to Creating and uploading a custom image.

Sample Dockerfile

ARG  base_image_tag
FROM ${base_image_tag}


USER root:root
RUN groupmod -g 103000 condausers && \
    umask 000 & \
    mkdir -p \
        "/.local/lib/python3.9/site-packages" \
        /.cache && \
    chown -R wmlfuser:condausers \
        /.local \
        /.cache && \
    find / -path /proc -prune -false -o -group 1000320900 -exec chgrp -h condausers {} \; && \
    chmod -R 775 \
        /home

Patching the deployment and preserving the software specification from previous versions of Cloud Pak for Data

Follow these steps to update the runtime definition so that the software specification in previous versions of Cloud Pak for Data picks up the new image.

  1. Identify the runtime definition file for the software specification and update with the new image. For more information, see Updating the runtime definition file with the new image.
  2. Create a model with the software specification that was used in the previous version of Cloud Pak for Data.
  3. Patch the existing deployment with the new model.

Updating the runtime definition with the new image

Follow these steps to update the runtime definition file:

  1. Use the following code snippet to get the runtime definition files:

    response=curl -k '<CloudPakforData_URL>/v2/runtime_definitions/{runtime_definition_id}?include=launch_configuration' -H 'Authorization: Bearer $mytoken'
    runtime_definition_template=response.json()["entity"]
    
    
  2. Update the value of the image key in the JSON file with the new image. You can use the jq tool to get help with updating. Refer to this example code:

    # The new custom image is a fully qualified registry image
    # e.g <target_registry>/<new-image-name>:<new-image-tag>
    # NEW_CUSTOM_IMAGE=<new_custom_image>
    
    # take a backup
    cp $WML_RUNTIME_DEF_JSON $WML_RUNTIME_DEF_JSON.bkp
    
    # extract required fields from old configuration
    SOURCE_DISPLAY_NAME=$(jq -r ".displayName" $WML_RUNTIME_DEF_JSON)
    SOURCE_DESCRIPTION=$(jq -r ".description" $WML_RUNTIME_DEF_JSON)
    SOURCE_SW_SPEC_NAME=$(jq -r ".software_specification_name" $WML_RUNTIME_DEF_JSON)
    
    # re-write the configuration  with the template
    # and update it with required fields already extracted
    # e.g. for Python-based custom images
    # TEMPLATE_CONFIG_JSON=runtime_definition_template
    TEMPLATE_CONFIG_JSON=<>
    
    cp $TEMPLATE_CONFIG_JSON $WML_RUNTIME_DEF_JSON
    
    tmp=$(mktemp)
    
    jq  --arg dn "$SOURCE_DISPLAY_NAME" \
        --arg ds "$SOURCE_DESCRIPTION" \
        --arg sw "$SOURCE_SW_SPEC_NAME" \
        --arg img "$NEW_CUSTOM_IMAGE" \
    '.displayName = $dn | .description = $ds | .software_specification_name = $sw | .image = $img' \
        $CUSTOM_WML_RUN_DEF > "$tmp" && mv "$tmp" $CUSTOM_WML_RUN_DEF
    
    jq "." $WML_RUNTIME_DEF_JSON
    
  3. Use the following code snippet to check whether the file to be uploaded contains the required details.

    cat $WML_RUNTIME_DEF_JSON
    
  4. Use the following code snippet to update the runtime definition file so that the software specification now points to the new image.

    curl -k POST \
    '<CloudPakforData_URL>/v2/runtime_definitions?include=launch_configuration' \
    -H 'Authorization: Bearer $mytoken \
    -d $WML_RUNTIME_DEF_JSON
    
  5. Use the following code snippet to check whether the new runtime definition is available in REST endpoint by using GET /v2/runtime_definitions:

    curl -k -s -X GET \
    $CPDHOST/v2/runtime_definitions \
    -H "Authorization: Bearer $TOKEN"
    

Learn more

Parent topic: Customizing deployment runtime images