Workspace

Workspace is a remote development solution built on cloud-native principles, supporting remote connections via web and VSCode clients.

# Design Principles

  • Declarative: Based on the Docker ecosystem, Dockerfile declares the development environment and manages it alongside the code.
  • Fast Startup: Even for large repositories, it is possible to prepare the code and environment within seconds.
  • On-Demand Usage: Development resources are acquired as needed and quickly reclaimed during idle times to avoid resource waste

# One-Click Creation of Development Environment

You can click the "Workspace" button in the branch page to create a development environment with a single click. No configuration is required, and it will directly open a default development environment using cnbcool/default-dev-env:latest as the base image.

# Customizing the Development Environment

If you want to start a custom development environment when clicking the "Workspace" button on the branch page, you can add a .ide/Dockerfile file in the root directory of the repository. In the Dockerfile, you can freely customize the development environment. When starting the development environment, a custom image will be built using the .ide/Dockerfile as the base image.

# .ide/Dockerfile
FROM node:20

# Install additional software as needed
# RUN apt-get update && apt-get install -y git

# Install code-server and commonly used VSCode extensions
RUN curl -fsSL https://code-server.dev/install.sh | sh \
  && code-server --install-extension redhat.vscode-yaml \
  && code-server --install-extension dbaeumer.vscode-eslint \
  && code-server --install-extension eamodio.gitlens \
  && code-server --install-extension tencent-cloud.coding-copilot \
  && echo done

# Install SSH service to support Remote-SSH access to the development environment from the VSCode client
RUN apt-get update && apt-get install -y wget unzip openssh-server

# Specify character set to support inputting Chinese characters in the command line
# (choose the appropriate character set as needed)
ENV LANG C.UTF-8
ENV LANGUAGE C.UTF-8

# Customizing the Creation Process

If you want to use a custom YAML pipeline configuration when clicking the "Workspace" button on the branch page, you can add a .cnb.yml file in the root directory of the repository and add the following configuration:

# .cnb.yml
$:
  # VSCode event: specifically for starting remote development from the page
  vscode:
    - docker:
        # Use a custom image as the development environment
        image: node:20
      services:
        - vscode
        - docker
      stages:
        - name: ls
          script: ls -al

# Customizing Resource Specifications

You can declare the required development resources using runner.cpus, with a maximum of 64 cores and memory equal to cpus x 2(GB).




 










# .cnb.yml
$:
  vscode:
    - runner:
        cpus: 64
      docker:
        build: .ide/Dockerfile
      services:
        - vscode
        - docker
      stages:
        - name: ls
          script: ls -al

# Custom Startup Events

By using .cnb.yml, you can declare the automatic creation of a development environment when specific events are triggered. The recommended trigger events are:

  • vscode: Create a development environment when you click the Launch Cloud Native Development button on the repository page
  • branch.create: Create a development environment when creating a branch
  • api_trigger: Custom event triggers the creation of a development environment
  • web_trigger: Web page custom event triggers the creation of a development environment




 













# .cnb.yml
# Match all branches
(**):
  # Create a development environment when creating a branch
  branch.create:
    - name: vscode
      services:
        # Declare the use of the vscode service
        - vscode
      docker:
        # Custom development environment
        build: .ide/Dockerfile
      stages:
        - name: Execute custom script
          script:
            - npm install
            - npm run start

# Custom Availability Time

The default availability time for Cloud Native Development is after the pipeline preparation (prepare) stage is completed (code-server code service starts during the preparation stage) and before the stages task is executed.

If you want to enter the development environment after executing certain tasks, that is, delay the time to enter the development environment, you can use the vscode:go built-in task. With this task, after starting Cloud Native Development, the loading page will delay entering the Cloud Native Development entry selection page. You can only enter the entry selection page after the vscode:go task is executed.

Note that using the vscode:go task will increase the waiting time. You can put tasks that must be executed before entering the development environment before vscode:go, and tasks that are executed after entering the development environment after vscode:go. If there is no task that must be executed before entering the development environment, there is no need to use vscode:go.

When the stages task execution fails, whether the remote development ends:

  • Using vscode:go: If the task before vscode:go fails, the development environment will be destroyed.
  • Using vscode:go: If the task after vscode:go fails, the development environment will not be destroyed.
  • Not using vscode:go: If the stages task execution fails, the development environment will not be destroyed.