This topic describes how to deploy an Egg.js application to Function Compute. Function Compute provides a method different from traditional deployment methods. You can deploy a traditional Egg.js application to Function Compute and use the application for production without performing operations such as purchasing a server. The deployed Egg.js application can use the auto scaling, pay-as-you-go, and O&M-free features of Function Compute.
Egg.js is designed to build enterprise frameworks and applications, and provides developers with core features for web development and a plug-in mechanism that has high extensibility. The developers develop applications based on a unified agreement. This reduces development and maintenance costs. For more information, see What is Egg?
- Run the following command in the specified directory to initialize a project:
s init devsapp/start-egg -d start-eggThe -d parameter specifies the project name. In this example, the project name is start-egg.Sample command output:Note Skip this step if the item exists.
Serverless Awesome: https://github.com/Serverless-Devs/package-awesome firstname.lastname@example.org file decompression completed Do you want to install dependencies? No please select credential alias default _____ | ___| | |__ __ _ __ _ | __|/ _` |/ _` | | |__| (_| | (_| | \____/\__, |\__, | __/ | __/ | |___/ |___/ Welcome to the start-egg application This application requires to open these services: FC : https://fc.console.aliyun.com/ ACR: https://cr.console.aliyun.com/ This application can help you quickly deploy the Egg project: Full yaml configuration: https://github.com/devsapp/egg#%E5%AE%8C%E6%95%B4yaml Egg.js development docs: https://start-egg.org/zh-cn/tutorials/index.html This application homepage: https://github.com/devsapp/start-egg Thanks for using Serverless-Devs You could [cd /test/start-egg] and enjoy your serverless journey! ️ If you need help for this example, you can use [s -h] after you enter folder. Document Star: https://github.com/Serverless-Devs/Serverless-Devs
- Run the following command to go to the project directory:
- Run the following command to deploy the project:
Sample command output:
[2021-08-17T14:31:03.383] [INFO ] [S-CLI] - Start ... [2021-08-17T14:31:03.392] [INFO ] [S-CLI] - Start the pre-action [2021-08-17T14:31:03.392] [INFO ] [S-CLI] - Action: npm install --production npm WARN deprecated email@example.com: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates. npm WARN deprecated firstname.lastname@example.org: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797) npm WARN deprecated email@example.com: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.) npm WARN deprecated firstname.lastname@example.org: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js. npm WARN deprecated email@example.com: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated firstname.lastname@example.org: Please see https://github.com/lydell/urix#deprecated [ ......] - extract:component-emitter: sill extract component-emitter@^1.2.1 extracted to /test/start-egg/node_modules/.staging/component-emitter-009e97c5 (1358ms) [ ......] - extract:component-emitter: sill extract component-emitter@^1.2.1 extracted to /test/start-egg/node_modules/.staging/component-emitter-009e97c5 (1358ms) npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN email@example.com requires a peer of mocha@>=1.18 <6 but none is installed. You must install peer dependencies yourself. npm WARN firstname.lastname@example.org requires a peer of acorn@^6.0.0 || ^7.0.0 || ^8.0.0 but none is installed. You must install peer dependencies yourself. added 552 packages from 387 contributors in 50.881s 14 packages are looking for funding run `npm fund` for details [2021-08-17T14:31:55.200] [INFO ] [S-CLI] - End the pre-action email@example.com file decompression completed Using web framework type: nas, If you want to deploy with container, you can [s cli fc-default set web-framework container] to switch. [2021-08-17T14:32:10.242] [WARN ] [EGG] - The startup file is not found, create a [start.sh] as the startup file. core-0.0.146.tgz file decompression completed Using web framework type: nas, If you want to deploy with container, you can [s cli fc-default set web-framework container] to switch. End of request Deployed. End of request (node:18629) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) [2021-08-17T14:32:22.474] [INFO ] [FC-DEPLOY] - Using region: cn-shenzhen [2021-08-17T14:32:22.474] [INFO ] [FC-DEPLOY] - Using access alias: default [2021-08-17T14:32:22.475] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902**** [2021-08-17T14:32:22.475] [INFO ] [FC-DEPLOY] - Using accessKeySecret: ldHUiJLoGto**** Using fc deploy type: sdk, If you want to deploy with pulumi, you can [s cli fc-default set deploy-type pulumi] to switch. [2021-08-17T14:32:23.193] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-egg exists [2021-08-17T14:32:23.637] [INFO ] [FC-DEPLOY] - Setting role: fcDeployDefaultRole-serverless-devs-egg [2021-08-17T14:32:24.423] [INFO ] [RAM] - Checking Role fcDeployDefaultRole-serverless-devs-egg exists [2021-08-17T14:32:24.585] [INFO ] [RAM] - Creating role: fcDeployDefaultRole-serverless-devs-egg [2021-08-17T14:32:24.685] [INFO ] [RAM] - Checking Plicy AliyunECSNetworkInterfaceManagementAccess exists [2021-08-17T14:32:24.755] [INFO ] [RAM] - Checking Plicy AliyunContainerRegistryReadOnlyAccess exists [2021-08-17T14:32:25.056] [INFO ] [FC-DEPLOY] - Using vpcConfig: auto: fc will try to generate related vpc resources automatically [2021-08-17T14:32:26.375] [INFO ] [VPC] - Getting vpc: fc-deploy-component-generated-vpc-cn-shenzhen [2021-08-17T14:32:26.477] [INFO ] [VPC] - Getting vswitch: fc-deploy-component-generated-vswitch-cn-shenzhen [2021-08-17T14:32:26.636] [INFO ] [VPC] - Getting securityGroup: fc-deploy-component-generated-securityGroup-cn-shenzhen [2021-08-17T14:32:26.842] [INFO ] [FC-DEPLOY] - Generated vpcConfig: securityGroupId: sg-wz92ctigpi221smc**** vSwitchId: vsw-wz9qnuult4q5g4f7n**** vpcId: vpc-wz9x9bzs0wtvjgt6n**** [2021-08-17T14:32:26.843] [INFO ] [FC-DEPLOY] - Using nasConfig: auto: fc will try to generate related nas file system automatically upload done [2021-08-17T14:32:53.524] [INFO ] [FC-DEPLOY] - Generated nasConfig: groupId: 10003 mountPoints: - fcDir: /mnt/auto nasDir: /serverless-devs-egg serverAddr: example.com userId: 10003 [2021-08-17T14:32:53.721] [INFO ] [FC-DEPLOY] - Checking Function egg exists [2021-08-17T14:32:54.014] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-egg exists [2021-08-17T14:32:54.233] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-egg exists [2021-08-17T14:32:54.408] [INFO ] [FC-DEPLOY] - Creating service: serverless-devs-egg [2021-08-17T14:32:54.409] [INFO ] [FC-DEPLOY] - Creating function: egg [2021-08-17T14:32:54.409] [INFO ] [FC-DEPLOY] - Creating triggers: ["serverless-devs-egg"] Make service serverless-devs-egg success. Make function serverless-devs-egg/egg success. Make trigger serverless-devs-egg/egg/serverless-devs-egg success. [2021-08-17T14:32:58.095] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-egg exists [2021-08-17T14:32:58.617] [INFO ] [FC-DEPLOY] - Checking Function egg exists [2021-08-17T14:32:59.122] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-egg exists [2021-08-17T14:32:59.336] [INFO ] [FC-DEPLOY] - Creating custom domain: egg.serverless-devs-egg.188077086902****.cn-shenzhen.fc.devsapp.net [2021-08-17T14:33:00.983] [INFO ] [FC-DOMAIN] - Creating custom domain: egg.serverless-devs-egg.188077086902****.cn-shenzhen.fc.devsapp.net There is auto config in the service: serverless-devs-egg [2021-08-17T14:33:01.494] [INFO ] [WEB-FRAMEWORK] - nas component get src is: . upload done Packing ... file /test/start-egg/.s/zip is ignored. Package complete. Start uploading file: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-egg/egg/start-egg.zip File uploaded successfully: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-egg/egg/start-egg.zip upload done [2021-08-17T14:33:58.326] [INFO ] [FC-NAS] - unzipping file [2021-08-17T14:34:10.528] [INFO ] [FC-NAS] - unzip done Try container acceleration function-test: region: cn-shenzhen serviceName: serverless-devs-egg functionName: egg customDomains: - http://egg.serverless-devs-egg.188077086902****.cn-shenzhen.fc.devsapp.net
After the project is deployed, you can view the temporary domain name generated by Function Compute in the execution output. The temporary domain name can be used to access the newly deployed application. For example, run the following command to access the application: