Skip to main content

How to extend the dependencies of code blocks

Persistence of Dependency Libraries

The following operations need to be performed while the service is running and only need to be completed once. There is no need to repeat these steps when installing additional extension libraries.

  1. Create a mount directory for the dependency library (the actual directory can be customized), for example:

    mkdir -p /data/mingdao/script/volume/command/package/python-3.6/
    mkdir -p /data/mingdao/script/volume/command/package/nodejs-10.18.0/
  2. Get the pre-installed dependency libraries

    docker cp $(docker ps | grep command | awk '{print $1}'):/usr/local/lib/python3.6/site-packages/ /data/mingdao/script/volume/command/package/python-3.6/
    docker cp $(docker ps | grep command | awk '{print $1}'):/usr/local/node-10.18.0/lib/node_modules/ /data/mingdao/script/volume/command/package/nodejs-10.18.0/
  3. Modify the docker-compose.yaml file to mount the host's dependency library directory into the container

    services:
    command:
    volumes:
    - ./volume/command/package/python-3.6/site-packages/:/usr/local/lib/python3.6/site-packages/
    - ./volume/command/package/nodejs-10.18.0/node_modules/:/usr/local/node-10.18.0/lib/node_modules/
  4. Execute the following command in the root directory of the manager and restart the service

    bash ./service.sh restartall

Online Installation of Extension Library

Note
  • You must complete the "Persistence of Dependency Libraries" steps above first, mounting the directory of dependency libraries in the container to the host, otherwise the extension libraries will need to be reinstalled after container restart.
  • Online installation of extension libraries requires ensuring that the server can access the internet.

Python

Taking the installation of the python-dateutil extension library as an example:

  1. Enter the command container

    docker exec -it $(docker ps | grep command | awk '{print $1}') bash 
  2. Install the python-dateutil extension library in the command container

    pip3 install --target=/usr/local/lib/python3.6/site-packages/ python-dateutil

After installation, you can find the newly installed extension library in the default path /data/mingdao/script/volume/command/package/python-3.6/site-packages/ on the host.

JavaScript (Based on Nodejs)

Taking the installation of the dayjs extension library as an example:

  1. Enter the command container

    docker exec -it $(docker ps | grep command | awk '{print $1}') bash 
  2. Install the dayjs extension library in the command container

    /usr/local/node-10.18.0/bin/npm -g install dayjs

After installation, you can find the newly installed extension library in the default path /data/mingdao/script/volume/command/package/nodejs-10.18.0/node_modules/ on the host.

Offline Installation of Extension Library

Note
  • You must first complete the "Persistence of Dependency Libraries" steps above to persistently mount the directory of dependency libraries in the container to the host. Otherwise, the extension library will need to be reinstalled after the container restarts.
  • This process is applicable when the server cannot access the internet or when offline packages are provided for the extension library.

Python

Taking the installation of the pycryptodome extension library as an example:

  1. When internet access is available, get the offline file of the extension library

    pip3 download pycryptodome -d "/package"
    • An offline file for the pycryptodome dependency library will be generated in the /package directory.
  2. Upload the offline file to the server where the HAP service is located

  3. Copy the offline file into the container and install it

    1. Copy the offline file of the pycryptodome dependency library to the /tmp path in the command container

      docker cp pycryptodome-3.15.0-cp35-abi3-manylinux1_x86_64.whl $(docker ps | grep command | awk '{print $1}'):/tmp
    2. Enter the command container

    docker exec -it $(docker ps | grep command | awk '{print $1}') bash 
    1. Install the offline package of the pycryptodome extension library in the command container

      pip3 install --target=/usr/local/lib/python3.6/site-packages/ /tmp/pycryptodome-3.15.0-cp35-abi3-manylinux1_x86_64.whl

JavaScript (based on Nodejs)

Taking the installation of the dayjs extension library as an example:

  1. When internet access is available, get the offline files for the extension library

    npm install dayjs -save
    • This will generate a directory node_modules/dayjs for the dependency library in the current directory
  2. Package the directory for the dayjs extension library

    cd node_modules
    tar czf dayjs.tar.gz dayjs
  3. Upload the packaged file dayjs.tar.gz of the extension library to the server where the HAP service is running.

  4. Unzip the offline files to the path where the dependency library is operated for persistence.

    tar xf dayjs.tar.gz -C /data/mingdao/script/volume/command/package/nodejs-10.18.0/node_modules
    • If the default data path in HAP has been modified, the unzip path should be based on the actual environment path.