Sign inSign up

ralflorent/wasm-service

By ralflorent

•Updated 6 months ago

Standalone API service for running WebAssembly (or WASM) modules generated by Coherent Spark.

Image
Integration & delivery
API management
1

967

ralflorent/wasm-service repository overview

⁠WASM Service

Standalone API service for running WebAssembly (or WASM⁠) modules generated by Coherent Spark⁠.

NOTE: This Docker repository/image is intended for Coherent Spark users only.

⁠Getting Started

Coherent Spark (or simply Spark) enables some powerful features for your Excel models. Among them is the ability to convert them to web assembly modules. That is, once an Excel model is uploaded to Spark, Spark generates a WASM representation of it that you can later download and use in your own application independently.

Visit the Coherent Spark's User Guide⁠ for more details.

šŸ‘‹ Just a heads-up:

This Docker image isn't officially supported by Coherent. It originally started as a sample API service I built for demo purposes. I then thought, "Why not share it with the community?" So, here we are!

If you encounter any bumps while using it, please report them by creating a GitHub issue⁠.

⁠Usage

Once the Docker engine/daemon is up and running, follow these steps:

  • Pull the Docker image using the following commands:
docker pull ralflorent/wasm-service
  • Run the service:
docker run --name wasm-service -p 8080:8080 -d ralflorent/wasm-service

PROTIPS: You may use a named volume to persist the data. Otherwise, the data will be lost when the container is removed.

docker run --name wasm-service -p 8080:8080 -v ws-data:/app/uploads -d ralflorent/wasm-service

⁠API Reference

Below is a quick reference of the API endpoints. For more details, please refer to the API documentation (OpenAPI 3.0 - Swagger UI) at http://localhost:8080/docs or http://localhost:8080/docs-json, assuming that the base URL is http://localhost:8080.

The service is also shipped with a built-in WASM bundle (volume of cylinder) that you may use to test the service.

Use CasesResources
API DocumentationGET /docs or GET /docs-json
Health checkGET /health
Get current configurationGET /v1/config
List all WASM modulesGET /v1/services
Upload a WASM modulePUT /v1/services[/{version_id}]
Add WASM module by URLPATCH /v1/services[/{version_id}]
Execute a WASM modulePOST /v1/services/{version_id}/execute
Fetch WASM validationsPOST /v1/services/{version_id}/validate
Get WASM execution historyGET /v1/services/{version_id}/history
Delete execution historyDELETE /v1/services/{version_id}/history
Download a WASM moduleGET /v1/services/{version_id}
Delete a WASM moduleDELETE /v1/services/{version_id}

For batch operations, use the following endpoints:

Use CasesResources
Create a batchPOST /v1/batch/{service_id}
Get a batch statusGET /v1/batch/{batch_id}/status
Get a batch resultGET /v1/batch/{batch_id}/results
Delete 1+ batch resultsDELETE /v1/batch

NOTE: Keep in mind that batch operations are asynchronous and memory-intensive. You should use them with caution.

As a bonus, you can use web sockets (Socket.IO)⁠ and listen to these events to get the batch status and results:

  • batch:completed
  • batch:failed

Example of connection URL: ws://localhost:8080.

⁠Configuration

To customize the behavior of the service, you can use a YAML-based configuration file. By default, the service uses the following configuration (see its schema⁠ for more details):

⁠Default configuration
name: wasm-service
description: API service for running WASM files

service:
  port: 8080
  contextPath: /
  uploadPath: uploads
  bodyLimit: 50mb
  connectivity:
    enabled: false

performance:
  history:
    enabled: false
  spark:
    cacheSize: 8
    threads: 1
    replicas: 1
  health:
    indicators:
      disk: 0.75
      wasm: 512
      memory: 1024
⁠Custom configuration

To load a custom configuration file:

  • specify its path in the environment variable as WS_CONFIG_PATH
  • then mount the file to the container.
# on the host machine, create a directory for the config file
$ mkdir -p /local/path/to/config
$ cd /local/path/to/config

# create and edit the custom config file
$ vim custom-config.yml

# run the service with docker and mount the config file
$ docker run --name wasm-service -p 8080:8080 -v ws-data:/app/uploads -d \
  -v /local/path/to/config:/config \
  -e WS_CONFIG_PATH=/config/custom-config.yml \
  ralflorent/wasm-service

⁠Support and Feedback

If you have any questions or feedback, feel free to reach out to me directly or create a new issue on GitHub⁠.

Tag summary

Content type

Image

Digest

sha256:2f6763969…

Size

164.1 MB

Last updated

6 months ago

docker pull ralflorent/wasm-service