Code packages
A code package is a way of organizing a set of dependent files in a folder structure. Each code package has a main executable file that in turn accesses other files in the code package. For example, a code package can contain a notebook file that calls other notebook files or functions in scripts in the folder structure in a notebook job. With code packages, you can start a job on a collection of dependent files and not on one file only.
Currently, you can use code packages in deployment spaces only. Also, you cannot create a code package through the UI in projects or deployment spaces. To use code packages in a deployment space, you must create a ZIP file with one or more files or directories. These can be files that you created in JupyterLab or RStudio in Cloud Pak for Data or from files you created elsewhere, for example using PyCharm on your local machine.
After you have created the ZIP file, you can use CPDCTL, a command-line interface to create a code package asset in a deployment space. You can give the code package asset the same name as the ZIP file or a new name. The code package asset contains all the code files that were archived in the ZIP file. After the code package asset is created in your deployment space, you can create a job, select the code package asset and run the files in the code package.
Creating and registering code package assets by using CPDCTL
You can use CPDCTL to create a code package asset (ZIP file) in a deployment space.
To create a code package asset in a deployment space by using CPDCTL:
-
Prepare the contents of your ZIP file.
-
Download, install and configure the CPDCTL command-line interface for your operating system. Refer to CPDCTL.
-
Enable the code package module in CPDCTL:
export CPDCTL_ENABLE_CODE_PACKAGE=1
-
Upload the ZIP 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 ZIP file in the storage associated with the deployment space
- LOCAL_FILE_PATH: The path to the ZIP file to be uploaded
- SPACE_ID: The ID of the deployment space
-
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 ZIP 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
The ZIP file is added as a code package asset on the Assets page in your deployment space.
-
With the code package registered as an asset in your deployment space, you can now create a job to run the files in the code package. You can do this:
- Manually by selecting the code package asset on the Assets page of your deployment space and clicking Deploy or New job from the Actions menu ().
- Programmatically by using CPDCTL commands in your CICD pipeline to create and run a job.
Useful links:
- Reference to more CPDCTL commands
- A Jupyter notebook example of how to create a code package with CPDCTL commands in a deployment space
Parent topic: Adding assets to a deployment space