Adding code packages to a deployment space

Use code packages to organize a set of dependent files in a folder structure. Each code package has a main executable file that that can accesses other files in the code package. Add code packages to your deployment space to deploy code developed inside and outside Cloud Pak for Data from your deployment space.

Creating code packages

To create a code package, you must create a ZIP archive with a one or more files or directories, or an exported Watson Studio project. These compressed files can include files created in JupyterLab or RStudio in Cloud Pak for Data or from code files that you created from outside of Cloud Pak for Data, such as code files created by using PyCharm on your local workstation.

Restriction:

You can add or import code package assets only from the user interface in a deployment space. You cannot create a code package from the user interface of a deployment space. You can only create a code package asset from a ZIP archive by using CPDCTL.

Creating code packages for code developed in Cloud Pak for Data

If you developed code in Cloud Pak for Data by creating code files created in JupyterLab or R Studio in a Project with default Git integration, you can import a ZIP archive from your Github repository to your deployment space to create a code package along with all the other assets in your Project.

The following diagram shows the options for use of IDEs with Git-based projects. You can import a code package into a deployment space on Cloud Pak for Data and deploy the code package or create a deployment job to run the code package.

Graphic shows the options for use of IDEs with Git-based projects. Import a code package into a deployment space, deploy a code package, or create a deployment job to run the code package

Creating code packages for code developed outside Cloud Pak for Data

If you developed code outside Cloud Pak for Data, for example, by using PyCharm on your local workstation, you can use a ZIP archive and create a code package asset in your deployment space by using CPDCTL.

Adding code packages to deployment spaces

You can deploy code developed within Cloud Pak for Data, such as Python code and notebooks created in JupyterLab, or R scipts created in RStudio with code packages. You can also deploy code developed outside Cloud Pak for Data, such as Python code or R Scripts with code packages.

Ways to add code packages

The code package asset is created automatically when you add a ZIP archive to a deployment space. You can add code packages to your deployment space from the user interface or programmatically by using IBM Cloud Pak for Data Command Line Interface (CPDCTL).

  • Adding code packages to a deployment space: You can add code packages to your deployment space during the process of creating a new deployment space from the user interface, or import code packages to an existing deployment space. For more information, see Adding code packages to a deployment space.
  • Adding code packages programmatically: Use the CPDCTL command line interface to create and register code package assets in a deployment space. For more information, see Adding code packages programmatically.

Adding code packages to a deployment space

You can add code packages to your deployment space during the process of creating a new deployment space, or import code packages to an existing deployment space.

Before you begin

You must have a ZIP archive file that contains your exported Project as a code package.

Creating a deployment space with code packages

Follow these instructions to add code packages to your deployment space:

  1. From the Deployments page, click New deployment space.

  2. Enter details for your deployment space.

  3. In the Upload space assets section, upload your ZIP archive file that contains your code package files.

    Screenshot showing how to upload code packages during deployment creation

  4. Click Create.

    Code package in a deployment space

Importing code packages to a deployment space

Follow these instructions to import code packages to an existing deployment space:

  1. From your deployment space, select the Import content from a project or space or export content icon Image of Import content from a project or space or export content icon and click Import space.

  2. In the Import assets to space window, upload your ZIP archive file that contains your code package files.

    Screenshot showing imported code package archive in a deployment space

  3. Click Done.

Adding code packages programmatically

You can create and register code packages programmatically by using IBM Cloud Pak for Data Command Line Interface (CPDCTL).

Creating and registering code package assets with CPDCTL

To create a code package asset in a deployment space by using CPDCTL, follow these steps:

  1. Commit or push any changes to the project that you are working on.
  2. Create a compressed file that contains all the assets that you want to move to the deployment space.
  3. Download, install, and configure the CPDCTL command line interface for your operating system. Refer to CPDCTL.
  4. Enable the code package module in CPDCTL:
    export CPDCTL_ENABLE_CODE_PACKAGE=1
    
  5. Upload the compressed file to the storage associated with the deployment space:
    cpdctl asset file upload --path code_package/${FILE_NAME} --file ${LOCAL_FILE_PATH} --space-id ${SPACE_ID}
    
    Input parameters include:
    • FILE_NAME: The name of the compressed file in the storage associated with the deployment space
    • LOCAL_FILE_PATH: The path to the compressed file to be uploaded
    • SPACE_ID: The ID of the deployment space
  6. Create a code package in the deployment space:
    cpdctl code-package create --file-reference code_package/${FILE_NAME} --name ${CODE_PACKAGE_NAME} --description ${CODE_PACKAGE_DESCRIPTION} --space-id ${SPACE_ID}
    
    Input parameters include:
    • FILE_NAME: The name of the compressed file in the storage associated with the deployment space
    • CODE_PACKAGE_NAME: The name of the code package in the deployment space
    • CODE_PACKAGE_DESCRIPTION: The description of the code package in the deployment space
    • SPACE_ID: The ID of the deployment space

Learn more

Parent topic: Assets in deployment spaces