### Reviewer Configuration File Example Source: https://docs.cnb.cool/en/build/internal-steps An example of a JSON configuration file that maps file paths to reviewer usernames. ```JSON { "./src": "name1,name2", ".cnb.yml": "name3" } ``` -------------------------------- ### Dockerfile for Docker Cache Source: https://docs.cnb.cool/en/build/internal-steps An example Dockerfile used with the `docker:cache` plugin. It sets up a Node.js environment, copies project files, and installs dependencies using `npm ci`, preparing a cache image. ```dockerfile # Choose a Base image FROM node:14 # Set working directory WORKDIR /space # Copy the file list from 'by' COPY . . # Install dependencies based on the copied files RUN npm ci # Set the required environment variables ENV NODE_PATH=/space/node_modules ``` -------------------------------- ### Install Latest code-server Version Source: https://docs.cnb.cool/en/workspaces/question Installs the latest stable version of code-server using a curl command. This is the standard method for setting up code-server for WebIDE. ```shell curl -fsSL https://code-server.dev/install.sh | sh ``` -------------------------------- ### Text File Example Source: https://docs.cnb.cool/en/build/file-reference An example of a plain text configuration file used for referencing in CNB pipelines. It contains key-value pairs for account and password information. ```text SOME_ACCOUNT=some-account SOME_PASSWORD=some-password ``` -------------------------------- ### YAML Trigger Configuration Example Source: https://docs.cnb.cool/en/build/trigger-rule An example of a `.cnb.yml` file demonstrating trigger rules for the 'push' event on the 'main' branch, including multiple pipelines. ```yaml # .cnb.yml main: # Trigger branch push: # Trigger event, corresponding to a build, can contain multiple Pipelines. It can be either an array or an object. - stages: # Pipeline 1 - echo "do some job" - stages: # Pipeline 2 - echo "do some job" ``` -------------------------------- ### YAML File Example Source: https://docs.cnb.cool/en/build/file-reference An example of a YAML configuration file used for referencing in CNB pipelines. It demonstrates key-value pairs for account and password information. ```yaml SOME_ACCOUNT: some-account SOME_PASSWORD: some-password ``` -------------------------------- ### Install VSCode Extension via VSX File Source: https://docs.cnb.cool/en/workspaces/usage-tips Installs a VSCode extension by providing the path to its VSX package file. This is useful for extensions not available in the default source. ```Shell code-server --install-extension ms-python.vscode-pylance.vsix ``` -------------------------------- ### Pull Artifacts with pip Source: https://docs.cnb.cool/en/artifact/pypi Demonstrates how to install Python packages from a private PyPI Artifact Registry using pip. It shows the general command and an example of specifying the index URL with credentials. ```Shell #Example 1: pip install requests #Example 2: Pull a specific version pip install requests==2.30.1 pip install # Example, pull from a temporary source pip install -i https://cnb:29bGg84xqRf3ZweNpYlL92e7tDv@pypi.cnb.cool/cnb-demo/pypi-demo/-/packages/simple requests pip install -i https://cnb:@ ``` -------------------------------- ### JSON File Example Source: https://docs.cnb.cool/en/build/file-reference An example of a JSON configuration file used for referencing in CNB pipelines. It shows account and password details in a JSON format. ```json { "SOME_ACCOUNT": "some-account", "SOME_PASSWORD": "some-password" } ``` -------------------------------- ### Runner CPU Configuration Example (YAML) Source: https://docs.cnb.cool/en/build/grammar Demonstrates configuring the number of CPU cores for a build runner. This example sets the CPU to 1 core, which implies 2GB of memory, for a specific job. ```yaml # cpus = 1, memory = 2G main: push: - runner: cpus: 1 stages: - name: echo script: echo "hello world" ``` -------------------------------- ### Full Pipeline Configuration Example (YAML) Source: https://docs.cnb.cool/en/build/grammar Provides a comprehensive example of a CNB pipeline configuration in YAML. It includes pipeline name, docker settings, git options, services, environment variables, imports, labels, stages, failStages, endStages, conditional execution, retries, and failure handling. ```yaml name: Pipeline name docker: image: node build: dev/Dockerfile volumes: - /root/.npm:copy-on-write git: enable: true submodules: true lfs: true services: - docker env: TEST_KEY: TEST_VALUE imports: - https://cnb.cool//-/blob/main/xxx/envs.yml - ./env.txt label: type: MASTER class: MAIN stages: - name: stage 1 script: echo "stage 1" - name: stage 2 script: echo "stage 2" - name: stage 3 script: echo "stage 3" failStages: - name: fail stage 1 script: echo "fail stage 1" - name: fail stage 2 script: echo "fail stage 2" endStages: - name: end stage 1 script: echo "end stage 1" - name: end stage 2 script: echo "end stage 2" ifModify: - a.txt - "src/**/*" retry: 3 allowFailure: false ``` -------------------------------- ### Build Docker Plugin Image Source: https://docs.cnb.cool/en/build/create-plugin Command to build the Docker image for the Cloud Native Build plugin, tagging it as 'cnbcool/hello-world'. ```Shell docker build -t cnbcool/hello-world . ``` -------------------------------- ### Reference Tag Example Source: https://docs.cnb.cool/en/build/configuration Demonstrates the use of the '!reference' tag to dynamically insert values from other parts of the configuration. This example shows referencing a simple string and a nested value. ```yaml .val1: echo1: echo hello .val2: friends: - one: name: tom say: !reference [.val1, echo1] ``` ```yaml include: - ./a.yml .val3: size: 100 main: push: - stages: - name: echo hello script: !reference [.val2, friends, "0", say] - name: echo size env: SIZE: !reference [".val3", "size"] script: echo my size ${SIZE} ``` ```yaml main: push: - stages: - name: echo hello script: echo hello - name: echo size env: SIZE: 100 script: echo my size ${SIZE} ``` -------------------------------- ### Example Environment Variable Transformation Source: https://docs.cnb.cool/en/build/create-plugin Illustrates how input parameters defined in YAML are transformed into environment variables for the plugin container. The parameter names are uppercased and prefixed with 'PLUGIN_'. ```Shell PLUGIN_TEXT="hello world" ``` -------------------------------- ### Dockerfile for Plugin Image Source: https://docs.cnb.cool/en/build/create-plugin This Dockerfile sets up an Alpine Linux environment, copies the entrypoint script, makes it executable, and sets it as the container's entrypoint. ```Dockerfile FROM alpine ADD entrypoint.sh /bin/ RUN chmod +x /bin/entrypoint.sh ENTRYPOINT /bin/entrypoint.sh ``` -------------------------------- ### Example: Configure and Push NuGet Artifact in Cloud Native Build Source: https://docs.cnb.cool/en/artifact/nuget An example demonstrating the configuration of NuGet repository, packaging, and pushing of a NuGet artifact to CNB. ```yaml main: push: - docker: image: mcr.microsoft.com/dotnet/sdk:9.0 stages: - name: Configure nuget repository address, username, and password script: dotnet nuget add source https://nuget.cnb.cool/cnb/nuget/-/packages/v3/index.json --name cnb.nuget --username cnb --password cnb_token --store-password-in-clear-text - name: Build nuget artifact script: dotnet pack mynupkg.csproj --configuration Release --output nupkgs - name: Push nuget artifact to CNB script: dotnet nuget push nupkgs/*.nupkg --source cnb.nuget ``` -------------------------------- ### Install VSCode Extension via Extension ID Source: https://docs.cnb.cool/en/workspaces/usage-tips Installs a VSCode extension using its unique identifier. This method is used when the extension is available in the default extension source. ```Shell code-server --install-extension ${extension id} ``` -------------------------------- ### Install Helm Chart from Registry Source: https://docs.cnb.cool/en/artifact/helm Installs a Helm chart from the CNB Helm Artifact Registry to a Kubernetes cluster, specifying a release name, OCI path, and version. ```bash helm install {my-release} oci://helm.cnb.cool/{artifact-path} --version {version} ``` -------------------------------- ### Install Specific code-server Version Source: https://docs.cnb.cool/en/workspaces/question Installs a specific version of code-server, useful for temporary solutions when a particular version has bugs affecting WebIDE functionality. Replace '4.100.3' with the desired version. ```shell # Install a specific version, for example 4.100.3 curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.100.3 ``` -------------------------------- ### Pull Artifacts with Pip Source: https://docs.cnb.cool/en/artifact/pypi Installs Python packages using Pip. It shows how to install a specific version and how to pull packages from a temporary source using the CNB repository with token authentication. ```shell pip install ``` ```shell pip install -i https://cnb:${CNB_TOKEN}@ ``` -------------------------------- ### Cloud Quick Initialization Source: https://docs.cnb.cool/en/guide/first-repo Initialize a repository using Cloud Native Development by migrating the repository or creating new files. ```text You can execute relevant commands in Cloud Native Development to migrate the repository or directly create new files to complete the repository initialization. ``` -------------------------------- ### Dockerfile: Install JetBrains IDEs and SSH Source: https://docs.cnb.cool/en/workspaces/jetbrains This Dockerfile installs the OpenSSH server and downloads/installs multiple JetBrains IDEs into the /ide_cnb directory. It uses a base Node.js image and prepares the environment for remote development via JetBrains Gateway. ```Dockerfile FROM node:22 WORKDIR /root # Install SSH service RUN apt-get update && apt-get install -y wget unzip openssh-server # Create /ide_cnb directory for installing IDEs, note that the installation path must be this one for automatic detection of supported IDEs RUN mkdir -p /ide_cnb # Choose to install one or more IDEs from below # Install GoLand RUN wget https://download.jetbrains.com/go/goland-2024.3.3.tar.gz RUN tar -zxvf goland-2024.3.3.tar.gz -C /ide_cnb # Install IntelliJ IDEA RUN wget https://download.jetbrains.com/idea/ideaIU-2024.3.5.tar.gz RUN tar -zxvf ideaIU-2024.3.5.tar.gz -C /ide_cnb # Install PhpStorm RUN wget https://download.jetbrains.com/webide/PhpStorm-2024.3.3.tar.gz RUN tar -zxvf PhpStorm-2024.3.3.tar.gz -C /ide_cnb # Install PyCharm RUN wget https://download.jetbrains.com/python/pycharm-professional-2024.3.5.tar.gz RUN tar -zxvf pycharm-professional-2024.3.5.tar.gz -C /ide_cnb # Install RubyMine RUN wget https://download.jetbrains.com/ruby/RubyMine-2024.3.3.tar.gz RUN tar -zxvf RubyMine-2024.3.3.tar.gz -C /ide_cnb # Install WebStorm RUN wget https://download.jetbrains.com/webstorm/WebStorm-2024.3.3.tar.gz RUN tar -zxvf WebStorm-2024.3.3.tar.gz -C /ide_cnb # Install CLion RUN wget https://download.jetbrains.com/cpp/CLion-2024.3.3.tar.gz RUN tar -zxvf CLion-2024.3.3.tar.gz -C /ide_cnb # Install RustRover RUN wget https://download.jetbrains.com/rustrover/RustRover-2024.3.5.tar.gz RUN tar -zxvf RustRover-2024.3.5.tar.gz -C /ide_cnb # Install Rider RUN wget https://download.jetbrains.com/rider/JetBrains.Rider-2024.3.5.tar.gz RUN tar -zxvf JetBrains.Rider-2024.3.5.tar.gz -C /ide_cnb # Install code-server (VSCode WebIDE support) RUN curl -fsSL https://code-server.dev/install.sh | sh \ && code-server --install-extension cnbcool.cnb-welcome \ && code-server --install-extension redhat.vscode-yaml \ && code-server --install-extension orta.vscode-jest \ && code-server --install-extension dbaeumer.vscode-eslint \ && code-server --install-extension waderyan.gitblame \ && code-server --install-extension mhutchie.git-graph \ && code-server --install-extension donjayamanne.githistory ENV LANG C.UTF-8 ``` -------------------------------- ### Customize Double Container Mode with Dockerfile Source: https://docs.cnb.cool/en/workspaces/double-container This example demonstrates customizing a development environment for double container mode using a Dockerfile. It starts from a base Node.js image, updates package lists, installs necessary tools like git, wget, unzip, and openssh-server, and sets environment variables for language and character set. ```dockerfile # .ide/Dockerfile # You can replace node with your required base image FROM node:20 # Install software as needed RUN apt-get update && apt-get install -y git wget unzip openssh-server # Specify character set to support Chinese input in command line (choose character set as needed) ENV LANG C.UTF-8 ENV LANGUAGE C.UTF-8 ``` -------------------------------- ### CNB: Basic Push Pipeline Source: https://docs.cnb.cool/en/build/quick-start A simple Cloud Native Build pipeline configuration that triggers on a push event to the main branch and executes an 'echo hello world' script. ```yaml # Branch name main: # Event name push: # Tasks to execute - stages: - name: echo script: echo "hello world" ``` -------------------------------- ### Install pnpm Packages with Artifact Registry Source: https://docs.cnb.cool/en/artifact/npm This snippet explains how to use pnpm for package installation by replacing 'npm' with 'pnpm' in the commands. It assumes a similar setup to npm regarding registry configuration. ```text Refer to npm, just replace `npm` with `pnpm` in the commands. ``` -------------------------------- ### Create Repository Source: https://docs.cnb.cool/en/guide/first-repo Steps to create a new repository by clicking the '+' icon, selecting 'Create Repository', choosing the parent organization, filling in the repository name, and setting visibility before clicking 'Create'. ```text Click the `+` in the top right corner, select `Create Repository`, choose the parent organization, fill in the repository name, and select the repository visibility as needed, then click `Create` to complete the repository creation. ``` -------------------------------- ### Preview Helm Chart Manifests Source: https://docs.cnb.cool/en/artifact/helm Generates a preview of the Kubernetes manifests for a Helm chart from the CNB Helm Artifact Registry, allowing for review before installation. ```bash helm template {my-release} oci://helm.cnb.cool/{artifact-path} --version {version} ``` -------------------------------- ### Create Organization Source: https://docs.cnb.cool/en/guide/first-repo Steps to create a new organization by clicking the '+' icon, selecting 'Create Organization', filling in the name and description, and then clicking 'Create'. ```text Click the `+` in the top right corner, select `Create Organization`, fill in the organization name and description, then click `Create` to complete the organization creation. ``` -------------------------------- ### Get Build Information Source: https://docs.cnb.cool/en/build/build-in-env Retrieves details about the current build, including its ID, web URL, start time, triggerer, stage, job name, and workspace. ```Shell echo "Build ID: $CNB_BUILD_ID" ``` ```Shell echo "Build Web URL: $CNB_BUILD_WEB_URL" ``` ```Shell echo "Build Start Time: $CNB_BUILD_START_TIME" ``` ```Shell echo "Build User: $CNB_BUILD_USER" ``` ```Shell echo "Build User ID: $CNB_BUILD_USER_ID" ``` ```Shell echo "Build Stage Name: $CNB_BUILD_STAGE_NAME" ``` ```Shell echo "Build Job Name: $CNB_BUILD_JOB_NAME" ``` ```Shell echo "Build Job Key: $CNB_BUILD_JOB_KEY" ``` ```Shell echo "Build Workspace: $CNB_BUILD_WORKSPACE" ``` -------------------------------- ### Local Initialization Methods Source: https://docs.cnb.cool/en/guide/first-repo Initialize a repository locally using methods such as bare repository migration, branch migration, or empty repository initialization. Specific commands are available in the target repository interface. ```text You can initialize the repository using any of these methods: bare repository migration, branch migration, or empty repository initialization. Specific commands can be viewed in the target repository interface as shown below: ``` -------------------------------- ### cnb:await - Simple Wait Source: https://docs.cnb.cool/en/build/internal-steps A basic example of `cnb:await` waiting for a simple notification from `cnb:resolve`. It uses a `key` to synchronize with a resolve task. ```yaml - name: ready type: cnb:await options: key: i-am-ready ``` -------------------------------- ### Start Workspace with GPU Access Source: https://docs.cnb.cool/en/build/saas/build-node This example shows how to initiate a workspace for remote development with GPU access by specifying a GPU-enabled build node (`cnb:arch:amd64:gpu`) in the pipeline configuration. ```yaml $: vscode: - runner: tags: cnb:arch:amd64:gpu services: - vscode ``` -------------------------------- ### Workspaces with VS Code and Docker Source: https://docs.cnb.cool/en/build/intro Sets up a workspace configuration for VS Code, including resource allocation, services, Docker image, volumes, and build stages. ```yaml $: vscode: - runner: cpus: 64 services: - vscode docker: image: node:20 volumes: - node_modules:copy-on-write stages: - npm install ``` -------------------------------- ### Configure Multiple Web Triggers for Branches Source: https://docs.cnb.cool/en/build/web-trigger Sets up different sets of web trigger buttons for branches matching specific regular expressions. This example shows configurations for branches starting with 'release' and 'dev'. ```yaml branch: - reg: "^release" buttons: - name: Button Name 1 description: Button Description event: web_trigger_one - reg: "^dev" buttons: - name: Button Name 2 description: Button Description event: web_trigger_two - name: Button Name 3 description: Button Description event: web_trigger_three ``` -------------------------------- ### Docker Ecosystem Based Plugins Source: https://docs.cnb.cool/en/build/intro Illustrates using Docker images as plugins for build tasks, specifying a custom image for a 'hello world' stage. ```yaml main: push: - stages: - name: hello world image: cnbcool/hello-world ``` -------------------------------- ### Include Configuration Example Source: https://docs.cnb.cool/en/build/configuration Demonstrates how to include external configuration files using a URL or a local path. It shows the merging of configurations from 'template.yml' into '.cnb.yml', highlighting how keys are overwritten and arrays are appended. ```yaml # template.yml main: push: pipeline_2: env: ENV_KEY1: xxx ENV_KEY3: inner services: - docker stages: - name: echo script: echo 222 ``` ```yaml # .cnb.yml include: - https://cnb.cool//-/blob/main/xxx/template.yml main: push: pipeline_1: stages: - name: echo script: echo 111 pipeline_2: env: ENV_KEY2: xxx ENV_KEY3: outer stages: - name: echo script: echo 333 ``` ```yaml main: push: pipeline_1: # Key does not exist, added during merge stages: - name: echo script: echo 111 pipeline_2: env: ENV_KEY1: xxx ENV_KEY2: xxx # Key does not exist, added during merge ENV_KEY3: outer # Same key, overwritten during merge services: - docker stages: # Arrays are appended during merge - name: echo script: echo 222 - name: echo script: echo 333 ``` -------------------------------- ### VSCode Service: Remote Development Setup Source: https://docs.cnb.cool/en/build/grammar Declares the VSCode service for remote development needs. This example shows how to use both the 'vscode' and 'docker' services together, running a 'uname -a' command within an Alpine Docker image. ```yaml $: vscode: - services: - vscode - docker docker: image: alpine stages: - name: uname script: uname -a ``` -------------------------------- ### Configure Automatic Environment Creation on Branch Creation Source: https://docs.cnb.cool/en/workspaces/custom-dev-pipeline Set up automatic development environment creation based on trigger events using `.cnb.yml`. This configuration triggers environment creation when a branch is created (`branch.create`), using the `vscode` service and a custom Dockerfile, and executes `npm install` and `npm run start` scripts. ```YAML # .cnb.yml # Match all branches (**): # Create development environment when creating branch branch.create: - name: vscode services: # Declare using vscode service - vscode docker: # Custom development environment build: .ide/Dockerfile stages: - name: Execute custom scripts script: - npm install - npm run start ``` -------------------------------- ### Install openssh-server in Dockerfile Source: https://docs.cnb.cool/en/workspaces/vscode-likes This snippet shows how to install the openssh-server package within a Dockerfile, which is a prerequisite for enabling remote development with VSCode/Cursor clients. ```Dockerfile # .ide/Dockerfile FROM your-image # Note: Installation methods may vary depending on the base image. Use appropriate installation method based on actual situation apt-get update apt-get install -y openssh-server ``` -------------------------------- ### Initialize package.json for Push Source: https://docs.cnb.cool/en/artifact/npm Example package.json structure for initializing a package before pushing it to an Artifact Registry. Includes fields like name, version, description, main, author, and license. ```json { "name": "", "version": "", "description": "", "main": "index.js", "author": "", "license": "MIT" } ``` -------------------------------- ### CNB: Pull Request Pipeline with Lint and Test Source: https://docs.cnb.cool/en/build/quick-start A Cloud Native Build pipeline configuration for pull requests to the main branch. It includes 'lint' and 'test' stages and a 'notify' stage for when the primary stages fail. ```yaml #Branch name main: # Event name pull_request: # Array type indicates multiple pipelines possible - name: pr-check # Multiple tasks under pipeline stages: # Tasks to execute - name: lint script: echo "lint job" - name: test script: echo "test job" # Tasks to execute when stages fail failStages: - name: lint script: echo "notify to some chat group" ``` -------------------------------- ### CNB Apply Configuration with Sync and configFrom Source: https://docs.cnb.cool/en/build/internal-steps This example configures the CNB apply command to use a specified configuration file and enables synchronous execution. It includes the configuration file path and the event to trigger. ```yaml main: push: - stages: - name: trigger type: cnb:apply options: configFrom: .xxx.yml event: api_trigger_test sync: true ``` -------------------------------- ### Test Plugin with Filesystem Access Source: https://docs.cnb.cool/en/build/create-plugin Runs the plugin container locally, mounting the current directory as a volume and setting it as the working directory. This allows the plugin to access the build process workspace. ```Shell docker run --rm \ -e PLUGIN_TEXT="hello world" \ -v $(pwd):$(pwd) \ -w $(pwd) \ cnbcool/hello-world ``` -------------------------------- ### Install npm Packages with Artifact Registry Source: https://docs.cnb.cool/en/artifact/npm This snippet shows how to install npm packages using a specified registry URL. It requires Node.js and assumes the registry is configured. ```yaml main: push: - docker: image: node:22 stages: - name: npm install script: - npm install --registry= ``` -------------------------------- ### Execute Plugin Task with Settings Source: https://docs.cnb.cool/en/build/grammar Illustrates how to use plugin tasks, which are Docker images, for flexible execution environments. This example shows passing environment variables for authentication and specifying a registry. ```yaml - name: npm publish image: plugins/npm imports: https://cnb.cool//-/blob/main/xxx/npm.json settings: username: $NPM_USER password: $NPM_PASS email: $NPM_EMAIL registry: https://mirrors.xxx.com/npm/ folder: ./ ``` ```json { "username": "xxx", "password": "xxx", "email": "xxx@emai.com", "allow_slugs": ["cnb/**/**"], "allow_images": ["plugins/npm"] } ``` -------------------------------- ### Build and Publish Artifacts with poetry Source: https://docs.cnb.cool/en/artifact/pypi Shows the commands to build a Python package using poetry and then publish it to a configured remote repository named 'cnb-pypi'. ```Shell poetry build poetry publish -r cnb-pypi ``` -------------------------------- ### Docker Image and Build Configuration (YAML) Source: https://docs.cnb.cool/en/build/grammar Shows how to configure Docker settings for a pipeline, including specifying the environment image and a Dockerfile for building a custom image. It also demonstrates volume mounting for caching. ```yaml docker: image: node build: dev/Dockerfile volumes: - /root/.npm:copy-on-write ``` -------------------------------- ### RAG Mini Application with JavaScript and OpenAI Source: https://docs.cnb.cool/en/ai/knowledge-base This JavaScript example shows a simple RAG application that retrieves information from the CNB knowledge base and uses OpenAI to generate an answer. It includes initializing the OpenAI client, fetching data from the CNB API, and constructing a prompt for the LLM. ```javascript import OpenAI from 'openai'; // Configuration const CNB_TOKEN = 'your-cnb-token'; // Replace with your CNB access token, requires permission: `repo-code:r` (read repository code) const OPENAI_API_KEY = 'your-openai-api-key'; // Replace with your OpenAI API key const OPENAI_BASE_URL = 'https://api.openai.com/v1'; // Or your proxy address const REPO_SLUG = 'cnb/docs'; // Replace with your repository slug // Initialize OpenAI client const openai = new OpenAI({ apiKey: OPENAI_API_KEY, baseURL: OPENAI_BASE_URL }); async function simpleRAG(question) { // 1. Call CNB knowledge base retrieval const response = await fetch(`https://api.cnb.cool/${REPO_SLUG}/-/knowledge/base/query`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${CNB_TOKEN}` }, body: JSON.stringify({ query: question }) }); const knowledgeResults = await response.json(); // 2. Extract knowledge content (assuming we take all results here) const knowledge = knowledgeResults .map(item => item.chunk) .join('\n\n'); // 3. Call OpenAI to generate answer const completion = await openai.chat.completions.create({ model: "gpt-4.1-2025-04-14", messages: [ { role: "user", content: `Question: ${question}\n\nKnowledge Base: ${knowledge}\n\nPlease answer the question based on the knowledge base.`, }, ], }); return completion.choices[0].message.content; } // Usage example const answer = await simpleRAG("How to develop a plugin?"); // Output answer combined with knowledge base console.log(answer); ``` -------------------------------- ### Configure Yarn >1.x Command-line Setup Source: https://docs.cnb.cool/en/artifact/npm Configure Yarn versions greater than 1.x using command-line setup. This sets the npmPublishRegistry, npmRegistryServer, and the npmAuthToken for the Artifact Registry, generating a .yarnrc.yml file. ```yarn yarn config set npmPublishRegistry # Address for pushing packages yarn config set npmRegistryServer # Address for pulling packages yarn config set 'npmRegistries[].npmAuthToken' ``` -------------------------------- ### Docker as Task Execution Environment Source: https://docs.cnb.cool/en/build/intro Demonstrates using Docker as a task execution environment, specifying different Node.js versions for running commands. ```yaml main: push: - stages: - name: run with node 20 image: node:20 script: node -v - name: run with node 21 image: node:21 script: node -v ``` -------------------------------- ### Make GET Request to CNB API Source: https://docs.cnb.cool/en/openapi This snippet demonstrates how to make a GET request to the CNB API to retrieve user groups. It includes necessary headers for authentication and content type, and specifies pagination parameters. ```curl curl -X "GET" \ -H "accept: application/json" \ -H "Authorization: Bearer 1Z00000000000000000000000vA" \ "https://api.cnb.cool/user/groups?page=1&page_size=10" ``` -------------------------------- ### Simple JSON Configuration Example Source: https://docs.cnb.cool/en/build/grammar A basic JSON file structure for storing configuration values like tokens and passwords. This serves as a simple data store for environment-specific settings. ```json // env.json { "token": "private token", "password": "private password" } ``` -------------------------------- ### CNB Knowledge Base Query API Request Example Source: https://docs.cnb.cool/en/ai/knowledge-base This is an example of a JSON request body to query the CNB knowledge base. It includes the 'query' parameter for keywords or questions and optionally 'top_k' for the number of results. ```json { "query": "云原生开发配置自定义按钮" } ``` -------------------------------- ### Execute Plugin Task with SettingsFrom Source: https://docs.cnb.cool/en/build/grammar Demonstrates using 'settingsFrom' to load plugin task parameters from a remote file, with local 'settings' overriding or supplementing them. It also shows how to reference settings from a Dockerfile. ```yaml - name: npm publish image: plugins/npm settingsFrom: https://cnb.cool//-/blob/main/xxx/npm-settings.json settings: # username: $NPM_USER # password: $NPM_PASS # email: $NPM_EMAIL registry: https://mirrors.xxx.com/npm/ folder: ./ ``` ```json { "username": "xxx", "password": "xxx", "email": "xxx@emai.com", "allow_slugs": ["cnb/cnb"], "allow_images": ["plugins/npm"] } ``` ```dockerfile FROM node:20 LABEL cnb.cool/settings-from="https://cnb.cool//-/blob/main/xxx/settings.json" ``` -------------------------------- ### Configure pip Source (Linux/macOS) Source: https://docs.cnb.cool/en/artifact/pypi Configures the pip package installer to use a private PyPI Artifact Registry by adding a source configuration to the pip.conf file. This allows for easy installation of packages from the specified repository. ```INI [global] # TOKEN: Access token password; REPO_URL: Artifact Registry address # Example: index-url = https://cnb:29bGg84xqRf3ZweNpYlL92e7tDv@pypi.cnb.cool/cnb-demo/pypi-demo/-/packages/simple index-url = https://cnb:@ ``` -------------------------------- ### Runner Tags Configuration Example (YAML) Source: https://docs.cnb.cool/en/build/grammar Illustrates how to configure runner tags within a pipeline trigger. This example specifies the 'cnb:arch:amd64' tag for the build node, ensuring the job runs on a compatible runner. ```yaml main: push: - runner: tags: cnb:arch:amd64 stages: - name: uname script: uname -a ``` -------------------------------- ### Basic Pipeline Trigger Example (YAML) Source: https://docs.cnb.cool/en/build/grammar Demonstrates a basic pipeline trigger configuration using YAML. It specifies the trigger branch ('main') and event ('push'), and defines a pipeline with stages and jobs. ```yaml main: # Trigger branch push: # Trigger event, corresponding to a build, can contain multiple pipelines. Can be an array or an object. - name: pipeline-1 # Pipeline structure stages: - name: stage-1 # Stage structure jobs: - name: job-1 # Job structure script: echo ``` -------------------------------- ### Install Yarn Packages with Artifact Registry Source: https://docs.cnb.cool/en/artifact/npm This snippet details the steps to set up and use Yarn for installing packages, including enabling corepack and activating a specific Yarn version. It also includes commented-out lines for command-line registry configuration. ```yaml main: push: - docker: image: node:22 stages: - name: yarn install script: - npm install -g corepack - corepack enable - corepack prepare yarn@1.22.22 --activate # If Yarn version > 1.x and using command-line setup, include the following two lines # - yarn config set npmRegistryServer # - yarn config set 'npmRegistries[].npmAuthToken' ${CNB_TOKEN} - yarn install ``` -------------------------------- ### Include Syntax Variations Source: https://docs.cnb.cool/en/build/configuration Illustrates different ways to use the 'include' directive, including direct file paths, objects with 'path' and 'ignoreError' options, and embedding configuration directly using the 'config' key. ```yaml include: # 1. Directly pass the configuration file path - "https://cnb.cool//-/blob/main/xxx/template.yml" - "template.yml" # 2. Pass an object. # path: Configuration file path # ignoreError: Whether to throw an error if the file is not read. true: no error; false: throw error. Default is false - path: "template1.yml" ignoreError: true # 3. Pass an object # config: Pass YAML configuration - config: main: push: - stages: - name: echo script: echo "hello world" ``` -------------------------------- ### Get VSCode Web URL Source: https://docs.cnb.cool/en/build/build-in-env Provides the address for VSCode workspaces when 'services : vscode' is declared. ```Shell echo "$CNB_VSCODE_WEB_URL" ``` -------------------------------- ### Initialize ohpm Package Configuration Source: https://docs.cnb.cool/en/artifact/ohpm Initializes the package.json5 file for an ohpm package, defining essential metadata such as package name, version, description, main file, author, and license. ```json { "name": "", "version": "", "description": "", "main": "index.js", "author": "", "license": "MIT" } ``` -------------------------------- ### Unit Test Coverage Calculation (Golang) Source: https://docs.cnb.cool/en/build/internal-steps This configuration example for the 'testing:coverage' task is tailored for Golang coverage reports. It highlights the use of the 'lang' parameter set to 'go' to ensure correct parsing and includes options for breaking the build if no coverage is found. ```yaml testing:coverage # Example configuration for Golang coverage report # pattern: "coverage.out" # lang: "go" # breakIfNoCoverage: true ``` -------------------------------- ### Get Comment Body Source: https://docs.cnb.cool/en/build/build-in-env Returns the content of a comment for comment events. Returns an empty string otherwise. ```Shell echo "$CNB_COMMENT_BODY" ``` -------------------------------- ### Get Issue Priority Source: https://docs.cnb.cool/en/build/build-in-env Provides the priority of an issue for 'issue.*' triggers. Returns an empty string otherwise. ```Shell echo "$CNB_ISSUE_PRIORITY" ``` -------------------------------- ### Execute Gradle Publish Command Source: https://docs.cnb.cool/en/artifact/maven This command executes the Gradle wrapper to publish the artifacts. Ensure your Gradle environment is set up correctly. ```bash ./gradlew publish ``` -------------------------------- ### Get Issue Description Source: https://docs.cnb.cool/en/build/build-in-env Retrieves the description of an issue for 'issue.*' triggers. Returns an empty string otherwise. ```Shell echo "$CNB_ISSUE_DESCRIPTION" ``` -------------------------------- ### Build and Push Artifacts with Twine Source: https://docs.cnb.cool/en/artifact/pypi Builds Python package distributions (sdist and wheel) using the 'build' package and then uploads them to the configured repository using Twine. ```shell python -m build twine upload -r cnb-pypi dist/* ``` -------------------------------- ### Get Issue Title Source: https://docs.cnb.cool/en/build/build-in-env Returns the title of an issue for 'issue.*' triggers. Returns an empty string otherwise. ```Shell echo "$CNB_ISSUE_TITLE" ``` -------------------------------- ### Get Pipeline Information Source: https://docs.cnb.cool/en/build/build-in-env Retrieves the name, key, ID, Docker image, and status of the current pipeline. ```Shell echo "Pipeline Name: $CNB_PIPELINE_NAME" ``` ```Shell echo "Pipeline Key: $CNB_PIPELINE_KEY" ``` ```Shell echo "Pipeline ID: $CNB_PIPELINE_ID" ``` ```Shell echo "Pipeline Docker Image: $CNB_PIPELINE_DOCKER_IMAGE" ``` ```Shell echo "Pipeline Status: $CNB_PIPELINE_STATUS" ``` -------------------------------- ### Configure Gradle Plugins for AAR Publishing Source: https://docs.cnb.cool/en/artifact/maven Sets up the necessary Gradle plugins for AAR packaging and Maven publishing in the `libs.versions.toml` file. ```toml [versions] agp = "8.11.1" [plugins] android-library = { id = "com.android.library", version.ref = "agp" } ``` -------------------------------- ### Customize Startup Pipeline and Development Environment (.cnb.yml) Source: https://docs.cnb.cool/en/workspaces/custom-dev-env Customize both the startup process and the development environment by defining both a .cnb.yml file and an .ide/Dockerfile. The .cnb.yml specifies the build context for the Dockerfile, allowing for a fully tailored environment. ```yaml # .cnb.yml $: vscode: - docker: build: .ide/Dockerfile # Optionally define both build and image # In this case, .ide/Dockerfile will be used to build the image first # If .ide/Dockerfile build fails, the image specified will be used to ensure the environment can start successfully # image: cnbcool/default-dev-env:latest services: - vscode - docker # Tasks to execute after the development environment starts stages: - name: ls script: ls -al ``` -------------------------------- ### Get Repository ID and URL Source: https://docs.cnb.cool/en/build/build-in-env Provides the unique identifier (`id`) and the HTTPS URL for the target repository. ```Shell echo "Repo ID: $CNB_REPO_ID" ``` ```Shell echo "Repo URL (HTTPS): $CNB_REPO_URL_HTTPS" ``` -------------------------------- ### Metadata Storage Format Example Source: https://docs.cnb.cool/en/repo/annotations Illustrates the key:value format for storing metadata associated with tags or commits in CNB repositories. ```plaintext key1: value1 key2: value2 # ... ```