Preview Mode Only
About 866 wordsAbout 3 min
Preview Mode is a derivative capability of cloud-native development. In this mode, clicking the Cloud Native Development button opens the preview page directly instead of WebIDE, providing a faster preview experience.
Notes
- This feature is in beta; related configurations and usage methods are subject to change in the future.
- Preview Mode does not support WebIDE. Use Custom Buttons to create a Cloud Development button entry with WebIDE support.
- To use SSH connections, please install openssh in the image yourself.
- Preview Mode does not support proxy. The
$CNB_VSCODE_PROXY_URIenvironment variable is not available. Use standard Cloud Development Mode if proxy is needed.
How to Configure?
Minimal configuration:
$:
vscode:
- docker:
build: .ide/Dockerfile
services:
- name: vscode
options:
onlyPreview: true
launch: node index.jsComplete configuration (with all optional parameters):
$:
vscode:
- docker:
build: .ide/Dockerfile
services:
- docker # Optional: additionally mount the docker service
- name: vscode
options:
onlyPreview: true # Required: enable preview-only mode
launch: node index.js # Required: command to start the business service
keepAliveTimeout: 10m # Optional: offline keep-alive time, default 10 minutes
daemon: true # Optional: daemon mode
backup: true # Optional: backup/restore user data
stages:
- name: prepare # Optional: custom preparation step before startup
script: ls -alSee Parameter Details below for detailed explanations of each option.
Parameter Details
onlyPreview
- Type:
Boolean - Description: Whether to enable Preview Mode only.
- Effect: When set to
true, clicking the Cloud-Native Development button will open the preview page instead of WebIDE. To use SSH connections, install openssh in the image yourself.
launch
- Type:
String - Description: The command to start the business service.
- Note: The business service must be started on port
8686. - Examples:
node index.js,npm start,python app.py, etc.
keepAliveTimeout
- Type:
Number|String(unit defaults to: milliseconds) - Default Value:
600000(10 minutes) - Description: The offline keep-alive time for the development environment. If no HTTP connection is detected within the specified duration, the environment will automatically shut down.
- Example:
7200000represents 2 hours.
You can write a number directly (milliseconds), or a string with units, such as 10m for 10 minutes. Supported units:
ms: milliseconds (default)s: secondsm: minutesh: hours
daemon
- Type:
Boolean - Default Value:
false - Description: The execution mode of the
launchcommand (daemon mode)
daemon: false (non-daemon mode, default)
The platform runs the launch command in the foreground inside the preview environment:
- The startup logs of
launchare visible in real time, which helps with troubleshooting; - The platform waits for the
launchcommand to exit before continuing to check whether the service is ready; - Therefore, the
launchscript should exit by itself after the service is started and the port is ready (it is recommended to move the service to the background inside the script before exiting); - If
launchdoes not exit for a long time (for example, a service running in the foreground for more than 5 minutes without exiting), the execution will fail due to a timeout.
daemon: true (daemon mode)
The platform runs the launch command in the background (detached) mode:
- The service started by
launchruns directly in the background, anddocker execreturns immediately without waiting forlaunchto exit; - Because it runs in the background, the startup logs of
launchare not visible.
Recommendation
Keep daemon: false by default. Implement this inside your launch script instead: after the service is started and the port is ready, move the service to the background and let the script exit. This way you can view the startup logs for troubleshooting without blocking the flow because the script never exits.
Regardless of the mode, after launch finishes, the platform periodically (every 10 seconds, for up to about 200 seconds) checks whether port 8686 inside the container is being listened on, and only opens the preview page once the service is confirmed ready. Make sure launch ultimately starts the business service on port 8686.
backup
- Type:
Boolean - Default Value:
false - Description: Whether to backup/restore user data (only effective in Preview Mode). When set to
true:- On startup: Restore previous user roaming data and uncommitted code changes.
- During runtime: Periodically backup uncommitted code changes.
- On shutdown: Backup user roaming data and uncommitted code changes.
Usage Process
- Create a
.cnb.ymlfile in the project root directory. - Configure it according to the example above.
- Ensure the business service listens on port
8686. - Click the Cloud-Native Development button.
- The system will automatically start the development environment and open the preview page.
How to Use SSH Connections in Preview Mode?
Install openssh in your custom development environment. Configure it in .ide/Dockerfile as follows:
FROM node:20
RUN apt-get update && apt-get install -y git wget unzip openssh-server
ENV LANG C.UTF-8
ENV LANGUAGE C.UTF-8Once the preview workspace is ready, it opens the preview page directly without showing the client selection page. For client connections, find the entry under Avatar → My Cloud Native Development.