Skip to main content

Using in the Continuous Integration (CI) Environment

Continuous Integration automates unit testing, code analysis, build, and integration testing for each code commit, then automates deployment and release through continuous deployment, reducing developers' workload, minimizing unnecessary repetitive tasks, and improving development efficiency.

Mainstream Continuous Integration platforms include Jenkins, Github Actions, GitLab CI, Coding, etc.

You can integrate the CloudBase Framework in these platforms to achieve automated building and deployment.

1. Prepare the Build Environment

Method 1:

You need to prepare the following environments in the build environment.

  • Prepare the Node.js environment
  • Install CloudBase CLI globally
npm install -g @cloudbase/cli@latest

Method 2: Use the CloudBase Base Build Image

If using Docker images as the runtime environment for Continuous Integration (CI), it is recommended to use the Docker image tencentcloudbase/cloudbase-framework-runner:latest, officially provided by CloudBase, as the base image.

The CloudBase base build image comes with all necessary dependencies pre-installed, eliminating the need for installation during each build process, thereby accelerating build and deployment speed.

  • Pre-installed environments including Node.js/ npm, etc.
  • Pre-installed with the latest version of CloudBase CLI and CloudBase Framework
  • Pre-installed with all official plugins of CloudBase Framework

Image address

https://hub.docker.com/r/tencentcloudbase/cloudbase-framework-runner/tags

2. Set environment variables

Build environment variables

It is recommended to inject build context-dependent information via environment variables or Secrets. Mainstream CI platforms support setting injected environment variables when triggering builds.

Example:

  • CloudBase environment id `ENV_ID
  • Tencent Cloud secret key
  • Other environment variables used in .env files

CI Environment Variables

In a CI environment, the CI environment variable should be set to true.

By setting the CI environment variable, CloudBase Framework can recognize the current CI environment, avoiding user interaction that would block the build.

For example, in a Linux environment, you can set environment variables using the following command:

export CI=true

3. Log in to CloudBase CLI

Before deploying with CloudBase Framework, you need to log in to CloudBase CLI.

In CI builds, you can use the following method to log in directly via Tencent Cloud API keys, avoiding interactive input.

cloudbase login --apiKeyId xxx --apiKey xxx

You can also log in using Tencent Cloud temporary keys.

cloudbase login --apiKeyId xxx --apiKey xxx --token xxx

4. Invoke CloudBase Framework for One-Click Application Deployment

After logging in, you can invoke the following command for one-click deployment. The --verbose parameter prints additional build and deployment information to facilitate troubleshooting.

cloudbase framework deploy --verbose