Bundle 是供 Function 執行運作時所使用的壓縮檔,其中可能包含原始碼檔案或機器學習模型。

在 Function 初始化階段,Syntixi 會下載並解壓縮 Bundle 檔案至 Function Pod 的 /userfunc 路徑底下。
目前 CLI 支援使用本地檔案或公開可存取的 URL 來創建 Bundle。

如何建立一個 Bundle

單一檔案

可以使用 --code 參數來建立一個僅包含單一檔案的 Bundle,並利用 CLI 上傳至伺服器端

  curl https://raw.githubusercontent.com/syntixi/examples/master/environments/nodejs/hello.js > hello.js
syntixi bundle create --name hello --code hello.js
  

多個檔案

如須建立包含多檔案的 Bundle 時,需要先把所有檔案放到一個資料夾底下。 舉例來說,目標資料夾的結構如下:

  demo/
├── foo
│   └── bar
│       └── log.js
└── entry.js
  

用 CLI 指令並使用 --code 參數指定資料夾以建立 Bundle 並上傳至伺服器端

  # Equivalent to "zip -r <name>.zip <directory>"  
syntixi bundle create --name demo --code demo/
  

當 Function 初始化階段,該 Bundle 會被解壓縮後放在 /userfunc/<directory-name>

以前面資料夾結構作為舉例,解壓縮後會放在 /userfunc/demo/ 路徑下,可以使用下面方式存取

  node /userfunc/demo/entry.js 
  

ZIP 壓縮檔

使用 ZIP 指令建立檔案壓縮檔,並使用 --archive 參數來建立 Bundle

  zip -r <name>.zip <directory>
syntixi bundle create --name hello --archive <name>.zip
  

建議再度確認壓縮檔內的資料夾結構是否符合預期

  zip -sf <name>.zip
  

在上傳之前 CLI 會計算 SHA256 校驗碼來確保檔案完整性,然而在這個階段會耗費較長的時間。可以使用 --checksum 指定校驗碼或是 --insecure 來避免計算校驗碼

  syntixi bundle create --name hello --archive <name>.zip --checksum <sha256-checksum>
syntixi bundle create --name hello --archive <name>.zip --insecure
  

可以使用以下指令來確定 zip 檔案的結構

URL 連結

使用 URL 來建立 Bundle 有以下兩個限制

  1. 該 URL 必須可以在 Kubernetes 叢集內部所連線存取
  2. 該 URL 下載的檔案必須是 .zip 格式
  syntixi bundle create --name hello --archive <url-to-zip-file> --checksum <sha256-checksum>

# Use "--insecure" to skip file integrity check before uploading and during function initialization.
# It improves the function startup time, however, it also brings potential security issue if you cannot 
# control the content of URL points to.
syntixi bundle create --name hello --archive <url-to-zip-file> --insecure
  
Was this page helpful?