Releases: WasmFunction/WasmFunction
v1.0.0 - Stable Release
This is a stable release of the WasmFunction project, focusing on refactoring and correcting previous design issues to ensure stability and correctness.
🛠️ Changes & Improvements
-
Enhanced Image Submission Logic
Continued support for two function submission methods:- Submitting an image URL
- Uploading a
.wasmexecutable file
The business logic has been redesigned to fix prior design flaws and guarantee correctness.
-
Removed Project Folder Submission Option
The previous option to submit entire source project folders (in other languages) has been removed.
Considering the complexity of different project build environments, supporting this method would require users to handle their own compilation process, which conflicts with the project's goal of simplifying function deployment. -
Removed Forced Environment Resource Adaptation Logic
The forced adaptation of environment resources has been removed.
Since Wasm functions do not require environment resources, this logic is no longer necessary and has been cleaned up to simplify the execution process.
For usage instructions, please refer to the organization's homepage.
v0.0.3-updated a new feature
增加了新的功能:提交其他语言的项目后,编译成 .wasm 文件,并创建相应的 wasm env (通过 env --wasm-builder 参数实现)。
example:
fission env create --name hello-wasm --image wasm_project --wasm-builder docker.io/amnesia1997/wasm-builder:latest
- 我们约定 --image 参数的内容为项目文件夹名称,如 wasm_project。
- 我们约定 --wasm-builder 参数的内容为 builder 的镜像地址。
- 镜像内容:由开发者自行决定如何编译,但需要遵守三个规则:项目文件夹必须复制到 hostpath 中,生成的 .wasm 文件,文件名为:你的项目名称.wasm,如 wasm_project.wasm;需要在 builder 中将生成的 .wasm 文件放入 hostpath 中。
- 将编译过程包装在名为 build_wasm.sh 的脚本中。
- 具体如何做? 请看下面的小例子:
以 wasm_project 为例:
- 首先,我们将该项目复制到 hostpath: /var/lib/kaniko/workplace/ 下
- 项目结构和文件内容如下:
wasm_project/
├── CMakeLists.txt # CMake 配置文件
├── include/ # 头文件目录
│ └── greeter.hpp # 示例头文件
├── src/ # 源代码目录
│ └── greeter.cpp # 示例源文件
└── main.cpp # 主程序入口
wasm_project/CMakeLists.txt
cmake_minimum_required(VERSION 3.19)
project(wasm_project)
set(CMAKE_CXX_STANDARD 17)
# 设置 em++ 为 C++ 编译器
set(CMAKE_CXX_COMPILER em++)
# 设置 .wasm 后缀
set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
# 设置 include 路径
include_directories(include)
# 添加可执行文件
add_executable(wasm_project main.cpp src/greeter.cpp)
# 链接库(如果有的话,可以根据需求增加)
# target_link_libraries(wasm_project PRIVATE some_library)wasm_project/main.cpp
#include <iostream>
#include "greeter.hpp"
int main() {
Greeter greeter;
greeter.say_hello();
return 0;
}wasm_project/include/greeter.hpp
#ifndef GREETER_HPP
#define GREETER_HPP
class Greeter {
public:
void say_hello();
};
#endifwasm_project/src/greeter.cpp
#include <iostream>
#include "greeter.hpp"
void Greeter::say_hello() {
std::cout << "Hello, WebAssembly!" << std::endl;
}- 项目的 dockerfile如下
# 使用 emscripten 官方镜像
FROM emscripten/emsdk:latest
# 设置工作目录(暂时必须设置成 /workspace 我们的 pod 挂载这个目录)
WORKDIR /workspace
# 添加构建脚本
COPY build_wasm.sh /usr/local/bin/build_wasm.sh
RUN chmod +x /usr/local/bin/build_wasm.sh
# 默认运行构建脚本
ENTRYPOINT ["build_wasm.sh"]- 注意到 dockerfile 中使用了 build_wasm 来控制我们的编译过程,脚本内容如下:
#!/bin/bash
set -e
# 获取项目名称,默认为 "wasm_project"
PROJECT_NAME=${PROJECT_NAME:-"wasm_project"}
PROJECT_PATH="/workspace/${PROJECT_NAME}"
# 确保项目路径存在
if [ ! -f "$PROJECT_PATH/CMakeLists.txt" ]; then
echo "Error: CMakeLists.txt not found in $PROJECT_PATH. Please check your project structure."
exit 1
fi
# 创建构建目录
BUILD_DIR="$PROJECT_PATH/build"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# 配置和编译项目
emcmake cmake .. -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
emmake make
# 检查是否生成 .wasm 文件
WASM_FILE="$BUILD_DIR/${PROJECT_NAME}.wasm"
if [ ! -f "$WASM_FILE" ]; then
echo "Error: ${PROJECT_NAME}.wasm not generated."
exit 1
fi
# 移动 .wasm 文件到 /workspace/
mv "$WASM_FILE" "/workspace/${PROJECT_NAME}.wasm"
# 成功提示
echo "Build successful. ${PROJECT_NAME}.wasm is now located in /workspace/."- 基于这个 dockerfile 构建的镜像就是一个合法的镜像。总结合法条件如下:
- 您只需要保证将编译好的 .wasm 文件移动或复制到 /workspace/,并且名称为 项目名称 .wasm 即可。
- 其中 /workspace/ 是该 pod 挂载的目录,PROJECT_NAME 变量会从 --image 参数中获得。
- 将编译过程包装在名为 build_wasm.sh 的脚本中。
生成的 pod 规格如下:
apiVersion: v1
kind: Pod
metadata:
name: wasm-builder
spec:
restartPolicy: Never
containers:
- name: wasm-builder
image: your-wasm-builder-image # --wasm-builder
env:
- name: PROJECT_NAME
value: your-env-image-name # --image
volumeMounts:
- name: dockerfile-storage
mountPath: /workspace
command:
- /bin/bash
- -c
- --
args:
- build_wasm.sh && exit 0 || exit 1
volumes:
- name: dockerfile-storage
persistentVolumeClaim:
claimName: dockerfile-claimv0.0.2 - Updated the WebAssembly (Wasm) function creation method
- 更新了 WebAssembly (Wasm) 函数的创建方式,保持与原方式同一。(Updated the WebAssembly (Wasm) function creation method to maintain consistency with the original approach.)
- 仍存在的问题和注意事项在组织的主页 readme 中更新。(Remaining issues and notes have been updated in the README on the organization's main page.) Click here to view README