Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
# wasm-packs
# Example of Cloud Native Buildpacks for Wasm

This repository contains a set of build packs and example Wasm applications to demonstrate how to build and run Wasm applications using Cloud Native Buildpacks.

## The Parts
### Base Images
The `base-images` directory contains the Dockerfiles for the base images used by the buildpacks. The `build.sh` script builds the base images used for build
and run in the buildpacks. They are based on the Heroku stack images.

### Builders
The `builders` directory contains the builder for the Wasm buildpacks.

### Buildpacks
The `buildpacks` directory contains the buildpacks used in the builder.

#### Meta-buildpacks
The `meta-buildpacks` directory contains the meta-buildpacks used in the builder.

### Apps
The `apps` directory contains the example Wasm applications. The `js` directory contains a simple Wasm application written in Rust and compiled to Wasm. The `compose` directory contains a multi-component Wasm microservice application using both JS and Golang to demonstrate the use of multiple languages in a single application.

## Building and Running the Example
```bash
./base-images/build.sh wasm
pack builder create wasm/demo-builder:wasm --config ../builders/wasm/builder.toml
pack build test-wasm-js --builder wasm/demo-builder:wasm --path apps/js/
docker run --rm -it -p 8080:8080 test-wasm-js
pack build wasm-compose --builder wasm/demo-builder:wasm --path apps/compose/
docker run --rm -it -p 8080:8080 -e OPENAI_API_KEY wasm-compose
```
3 changes: 2 additions & 1 deletion apps/compose/app-js/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ router
})
.get("/chat", (request) => {
let prompt = request.query["prompt"];
let model = request.query["model"];
let chatRequest = {
model: "gpt-4o-mini",
model: model ?? "gpt-4o-mini",
messages: [
{
role: "user",
Expand Down
3 changes: 2 additions & 1 deletion apps/compose/service-go/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func init() {
Message: chatErr.Message,
})
}
return cm.OK[cm.Result[chat.ChatResponseShape, chat.ChatResponse, chat.Error]](res)
cmOk := cm.OK[cm.Result[chat.ChatResponseShape, chat.ChatResponse, chat.Error]](res)
return cmOk
}

}
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/wac-composer/bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ cat > "${CNB_LAYERS_DIR}/launch.toml" << EOL
[[processes]]
type = "web"
command = ["wasmtime"]
args = ["serve", "-S", "cli", "--env", "OPENAI_API_KEY", "--allow-precompiled", "${wasm_component_layer}/composed.cwasm"]
args = ["serve", "-S", "cli", "--env", "--allow-precompiled", "${wasm_component_layer}/composed.cwasm"]
default = true
EOL