# Cloud Foundry Integration

SeaLights node agent is integrated into the Cloud Foundry [nodejs buildpack](https://github.com/cloudfoundry/nodejs-buildpack). So you can use it in your application by performing the following simple steps:

1. Create SeaLights service configuration
2. Push an application
3. Bind an application with the service
4. Restage an application

### Create Service Configuration <a href="#create-service-configuration" id="create-service-configuration"></a>

To manage application integrations with third-party services Cloud Foundry has the mechanism of the [User-Provided Services](https://docs.cloudfoundry.org/devguide/services/user-provided.html). So the first step is to create such a service with the configuration. Here is the command “[create-user-provided-service](https://cli.cloudfoundry.org/en-US/v7/create-user-provided-service.html)“ that does that:

{% code overflow="wrap" lineNumbers="true" %}

```
cf cups sealights-nodejs -p '{"token":"ey…"}'
```

{% endcode %}

It is also possible to provide a token file

{% code overflow="wrap" lineNumbers="true" %}

```
cf cups sealights-nodejs -p '{"tokenfile":"/path/to/sltoken.txt"}'
```

{% endcode %}

Note: you have to escape `"` character in the windows commands line, so the command will look like this:

{% code overflow="wrap" lineNumbers="true" %}

```
cf cups sealights-nodejs -p '{\"token\":\"ey…\"}'
```

{% endcode %}

You will be able to change the parameters later with the command “[update-user-provided-service](https://cli.cloudfoundry.org/en-US/v7/update-user-provided-service.html)”

See below the complete list of the available parameters

### Push an application <a href="#push-an-application" id="push-an-application"></a>

You can push an application as usual with the command “[push](https://cli.cloudfoundry.org/en-US/v7/push.html)”

{% code overflow="wrap" lineNumbers="true" %}

```
cf push
```

{% endcode %}

Note: you can use a [manifest.yml](https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html) file to simplify an application deployment

### Bind Application with the service <a href="#bind-application-with-the-service" id="bind-application-with-the-service"></a>

Now you can bind your published application with the service

{% code overflow="wrap" lineNumbers="true" %}

```
cf bind-service [app name] sealights-nodejs
```

{% endcode %}

### Restage Application <a href="#restage-application" id="restage-application"></a>

In order to apply changes you have to publish your application again, or just restage it with a command [restage](https://cli.cloudfoundry.org/en-US/v7/restage.html) once the Sealights service bound the test listener will be triggered

{% code overflow="wrap" lineNumbers="true" %}

```
cf restage [app name]
```

{% endcode %}

### Sealights env vars <a href="#sealights-env-vars" id="sealights-env-vars"></a>

Sealights test listener args are provided by env vars as the following

<table><thead><tr><th width="247.3333740234375">Parameter name</th><th>Description</th></tr></thead><tbody><tr><td><code>SL_LAB_ID</code></td><td>Allow to determine customer lab id - unique ID for a set of test labs in case multiple labs are running simultaneously</td></tr><tr><td><code>SL_BUILD_SESSION_ID</code></td><td>Sealights build session id</td></tr><tr><td><code>SL_BUILD_SESSION_ID_FILE</code></td><td>File that contains Sealights session id.</td></tr><tr><td><code>SL_PROXY</code></td><td>Address of proxy to run connection through</td></tr><tr><td><code>SL_PROJECT_ROOT</code></td><td>The root dir will be used to resolve path against it, default is CWD</td></tr><tr><td><code>SL_TEST_STAGE</code></td><td>Name of the test stage</td></tr></tbody></table>

### How it works <a href="#how-it-works" id="how-it-works"></a>

Sealights use the AfterCompile hook in the nodejs-buildpack to install an agent and all required dependencies in the target container. So once the application is pushed to the cloud foundry service the following steps occur:

1. Sealights hook verifies that the application is bound with the sealights service
2. Install the agent from the npm repository
3. Modify target application start command


---

# 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.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/advanced-features/cloud-foundry-integration.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.
