# Hybrid method 2: Manual Wasm mount

## Export the Wasm modules from Spark

The [Export](/spark-apis/impex-apis/export.md) API packages all of the files necessary to create a service into a Wasm bundle ZIP file.

1. Identify the Spark services to include in the deployment.
2. Ensure you have setup the appropriate [Export](/spark-apis/impex-apis/export.md#authorization) for the [Export](/spark-apis/impex-apis/export.md) API.
3. Start an Export job to fetch the required services into a Wasm bundle ZIP file. In this example we are fetching 2 services from `myenvironment` `mytenant` `Folder A`. Upon the successful posting of this job, it will return an `id`.

   ```sh
   curl --location --request POST 'https://excel.myenvironment.coherent.global/mytenant/api/v4/export' \
   --header 'Content-Type: application/json' \
   --header 'x-synthetic-key: 22f68e51-b04b-4a46-b0aa-a629a8a3fca8' \
   --header 'x-tenant-name: mytenant' \
   --data '{
       "file_filter": "onpremises",
       "inputs": {
           "services": ["Folder A/Service A", "Folder A/Service B"]
       }
   }'
   ```
4. Check the status of the Export job with the `id` from the previous step. When successful, the job `status` will be `closed` and there will be a link to download the Wasm bundle ZIP file.

   ```sh
   curl --location 'https://excel.myenvironment.coherent.global/mytenant/api/v4/export/fea5ba57-675b-4a16-be5e-cb6648f59b4b/status' \
   --header 'x-synthetic-key: 22f68e51-b04b-4a46-b0aa-a629a8a3fca8' \
   --header 'x-tenant-name: mytenant'
   ```
5. The resulting ZIP file will be structured as follows with a Tenant, Folder, Service, Service version hierarchy:

   ```
   mytenant
   ├── Folder A
   │   ├── Service A
   │   │   ├── 0.1.0
   │   │   │   ├── 3deb2c18-fc05-44d9-b77b-119758a7ef91.zip
   │   │   │   ├── DefaultValidations.json
   │   │   │   ├── ModelMetadata.json
   │   │   │   └──WASMMetadata.json
   │   ├── Service B
   │   │   ├── 1.0.0
   │   │   │   ├── c16d9b89-92c4-430f-a30e-9b04805fcb78.zip
   │   │   │   ├── DefaultValidations.json
   │   │   │   ├── ModelMetadata.json
   │   │   │   └──WASMMetadata.json
   │   ├── ...
   └── ...
   ```

## Run Wasm modules using the `nodegen-server`

To configure `nodegen-server` to run exported Wasm modules, you need to set the following environment variables.

| Environment variable |                                                                                                                                                                                                               |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `USE_SAAS`           | <p><code>false</code></p><p>This must always be set as <code>false</code>. The setting of <code>true</code> is for Coherent deployments on our SaaS environments. The default value is <code>true</code>.</p> |
| `MODEL_LOCATION`     | <p><code>/models</code></p><p>The location within the container used to store models.</p>                                                                                                                     |
| `UPLOAD_ENABLED`     | <p><code>true</code></p><p>This allows users to upload additional WASM modules without having to restart the container. The default value is <code>false</code>.</p>                                          |

1. Ensure that the Docker engine/daemon is up and running.
2. Navigate to your desired working directory and move the exported ZIP to this location.
3. [`unzip`](https://linux.die.net/man/1/unzip) the ZIP to a folder that contains the above contents. In this example we are extracting `runner_example.zip` the to a folder called `model_zip`.

   ```sh
   unzip runner_example.zip -d model_zip
   ```
4. [`pull`](https://docs.docker.com/reference/cli/docker/image/pull/) the [`nodegen-server`](https://github.com/orgs/Coherent-Partners/packages/container/package/nodegen-server) Docker image using the following command:

   ```sh
   docker pull ghcr.io/coherent-partners/nodegen-server
   ```
5. [`run`](https://docs.docker.com/engine/reference/commandline/run/) the service and create a container called `wasm-server`.

   1. Mount the local unzipped folder `./model_zip` to the `wasm-server` container `/models` path. Be mindful of the file paths. Read more about [Docker bind mounts](https://docs.docker.com/storage/bind-mounts/#start-a-container-with-a-bind-mount) for more details on how to mount files and directories on Windows, Linux, and macOS.

   ```sh
   docker run --name wasm-server -p 3000:3000 -d -it \
     -e USE_SAAS=false \
     -e MODEL_LOCATION=/models \
     -e UPLOAD_ENABLED=true \
     -v ./model_zip:/models \
     ghcr.io/coherent-partners/nodegen-server
   ```
6. Test the service using the `healthcheck` endpoint. You should receive the message `{"msg":"ok"}`.

   ```sh
   curl 'http://localhost:3000/healthcheck'
   ```
7. Execute a request similar to that in the [API Tester](/navigation/api-tester.md).

   * Note the change in the URI to `localhost:3000` and make sure to update `mytenant` in the URI to your tenant name.
   * See [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md) for more information on the [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md#request_data) and [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md#request_meta) structure and options.
     * The `service_id` and `version_id` should match those from the tenant you exported the Wasm ZIP bundle.
     * Also see the [Hybrid Runner API reference](/hybrid-runner/hybrid-runner-api-reference.md) for alternative endpoints available from the runner.

   ```sh
   curl --location --request POST 'http://localhost:3000/mytenant/api/v3/execute' \
   --header 'Content-Type: application/json' \
   --data '{
       "request_data": {
           "inputs": { "A": 1 , "B": 2 }
       },
       "request_meta": {
           "version_id": "c16d9b89-92c4-430f-a30e-9b04805fcb78",
           "call_purpose": "Offline",
           "source_system": "Hybrid Runner"
       }
   }'
   ```
8. It is good practice to [`stop`](https://docs.docker.com/engine/reference/commandline/stop/) and [`remove`](https://docs.docker.com/engine/reference/commandline/rm/) containers when you are finished.

   ```bash
   # stop the container
   docker stop wasm-server

   # remove the container
   docker rm wasm-server
   ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coherent.global/hybrid-runner/setup-the-hybrid-runner/hybrid-method-2-manual-wasm-mount.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
