EdgeOne CLI
Overview
The Edgeone CLI provides a method of managing Pages Functions and the ability to quickly deploy. With the aid of the CLI, you can generate, configure, and debug functions in a project, and also upload the built product as a folder or Zip package to the Pages platform.
Preparations
Quickly register and sign in to the Tencent Cloud console with a Gmail account.
Enable the Pages Service in the console, create a new Pages Project, and clone it to local.
Quick Start
1. Installing
During the preparation stage, install the CLI through npm in the cloned project.
npm install -g edgeone
Use the
edgeone -v command to check whether installed successfully. Use the edgeone -h command to view all commands.
2. Log In
Execute the login command, select
Global (International) or China as prompted. It is recommended to select Global to ensure accurate data and information are obtained, and then complete the login in the pop-up browser window.edgeone login
After completing login, you can execute
edgeone whoami to view the current logged-in account info.
3. Initializing
After successfully logged in, execute the initialization command to initialize the basic environment for Edgeone Pages in the project.
edgeone pages init
During initialization, based on the instructions and your needs, the
edge-functions or node-functions folder and example functions will be generated in the project root directory. Subsequently, you can continuously add new and develop functions under this folder. For detailed usage of functions, see the documentation.
4. Local Development
After initialization, enter the local development stage:
edgeone pages dev
Note:
This command will first read the devCommand parameter in edgeone.json to start the dev service. If this configuration is not found, it will read the dev command in package.json to start up. Do not configure edgeone pages dev in edgeone.json or package.json!
Edge Functions debug service has a limit on the number of times it can start up, so try to avoid frequently exiting and starting the dev service (hot updates in the dev service will not increase the startup count).
For environments where executing
edgeone login is inconvenient, add parameter -t, --token (method for obtaining API Token is at the end of the document).The execution command starts a service locally on port 8088 by default. Both the Pages Function service and the Pages project service run on the same port without the need for additional proxying.
You can confirm it by
http://localhost:8088/ to access the front-end page. In the front-end project, use the Fetch API for direct use. The access path is the path of function files in folder edge-functions, node-functions.// ./node-functions/api/my-functions.jsfetch('/api/my-functions', {method: 'POST',body: JSON.stringify({ data: 'example' }),})
5. Associate Project
If you need to use KV storage capacity or synchronize environment variables set in the console to local debugging, you can execute the associate project command, enter the project name as required. The project name here is the created Pages project name in preparation.
edgeone pages link
Note:
For environments where executing
edgeone login is inconvenient, add the parameter -t, --token (method for obtaining API Token is at the end).If you need to link a project that does not exist, you can also create a new project directly under the CLI guide.
6. Submit Deployment
After local development and debugging is done, push the project code to the Git remote to trigger the CI build and deployment in the Pages backend, completing the entire development process.
7. Local Deployment
You can also choose to deploy via the deploy command for local build. If you need to link an existing project, it must be a direct upload type.
edgeone pages deploy
Parameter Description
<directoryOrZip>: folder or ZIP package path to deploy
-n, --name: project name to deploy, creates new project automatically if it does not exist
-e, --env: deployment target environment, available values: production or preview (default production)
Note:
When executing deploy, the CLI will auto-build and deploy to Pages without the need to specify a directory. For manual building, place the Pages Functions related files and package.json into the output directory (e.g., dist), then rerun
edgeone pages deploy ./dist.
Local Deployment Example
# Production environment deploymentedgeone pages deploy# Preview environment deploymentedgeone pages deploy -e preview
8. Switching Accounts
Switch to another Tencent Cloud account, execute the following commands then log in again:
edgeone switch
CI/CD Pipeline Integration
Alternatively, you can integrate EdgeOne CLI into the CI/CD pipeline to realize automatic deployment.
Note:
Installing EdgeOne CLI can be found in "Quick Start - Installation".
CI Pipeline Deployment Command
deploy command supports direct package deployment from CI/CD pipeline to EdgeOne Pages via folder or ZIP, independent of Git.edgeone pages deploy [<directoryOrZip>] -n <projectName> -t <token> [-e <env>]
Parameter Description
<directoryOrZip>: folder or ZIP package path to deploy
-n, --name: project name to deploy, creates new project automatically if it does not exist (required)
-t, --token: API Token for CI/CD pipeline (required)
-e, --env: deployment target environment, available values: production or preview (default production)
Note:
When executing deploy, the CLI will auto-build and deploy the project. For manual building, place the Pages Functions related files and package.json into the output directory (such as dist), then rerun
edgeone pages deploy ./dist.
CI Pipeline Example
# Production environment deploymentedgeone pages deploy -n project-name -t $EDGEONE_API_TOKEN# Preview environment deploymentedgeone pages deploy -n project-name -e preview -t $EDGEONE_API_TOKEN
API Token Method for Obtaining
Before using the deployment command in the CI/CD pipeline, generate an API Token in the EdgeOne Pages console. For more information, see API Token.
Environment Variable Management
// List all environment variables in console configurationedgeone pages env ls// Pull console environment variables to a local fileedgeone pages env pull// Pull environment variables can specify local fileedgeone pages env pull -f .env.prod// Add new environment variableedgeone pages env add ENV_VAR_KEY env_var_value// Delete environment variableedgeone pages env rm ENV_VAR_KEY
