This topic describes how to deploy a Hexo application to Function Compute. Function Compute provides a method different from traditional deployment methods. You can deploy a traditional Hexo application to Function Compute and use the application for production without performing operations such as purchasing a server. The deployed Hexo application can use the auto scaling, pay-as-you-go, and O&M-free features of Function Compute.

Prerequisites

The following operations are complete:

Procedure

  1. Run the following command in the specified directory to initialize a project:
    s init devsapp/start-hexo
    The -d parameter specifies the project name. In this example, the project name is start-hexo.
    Note Skip this step if the item exists.
    Sample command output:
     Serverless Awesome: https://github.com/Serverless-Devs/package-awesome
    
     devsapp!start-hexo@0.0.12.zip file decompression completed
     Do you want to install dependencies? No
     please select credential alias default
    
         _   _
        | | | |
        | |_| | _____  _____
        |  _  |/ _ \ \/ / _ \
        | | | |  __/>  < (_) |
        \_| |_/\___/_/\_\___/
    
    
        Welcome to the start-hexo 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 Hexo project:
             Full yaml configuration: https://github.com/devsapp/hexo#%E5%AE%8C%E6%95%B4yaml
             Hexo development docs  : https://hexo.io/zh-cn/
         This application homepage: https://github.com/devsapp/start-hexo
    
    
     Thanks for using Serverless-Devs
     You could [cd /test/start-hexo] 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
  2. Run the following command to go to the project directory:
    cd start-hexo
  3. Run the following command to deploy the project:
    s deploy
    Sample command output:
    [2021-08-30T15:19:02.244] [INFO ] [S-CLI] - Start ...
    [2021-08-30T15:19:02.253] [INFO ] [S-CLI] - Start the pre-action
    [2021-08-30T15:19:02.253] [INFO ] [S-CLI] - Action: npm install --production
    npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
    npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
    
    > ejs@2.7.4 postinstall /test/start-hexo/node_modules/ejs
    > node ./postinstall.js
    
    Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)
    
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN hexo-application@1.0.0 scripts['server'] should probably be scripts['start'].
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    
    added 186 packages from 159 contributors in 4.765s
    
    15 packages are looking for funding
      run `npm fund` for details
    
    [2021-08-30T15:19:07.446] [INFO ] [S-CLI] - End the pre-action
     devsapp!hexo@0.1.9.zip 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-30T15:19:22.649] [WARN ] [WEB-EXPRESS] - The startup file is not found, create a [start.sh] as the startup file.
     web-framework.zip 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.
    (node:10072) [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)
     End of request
     Deployed.
     End of request
    [2021-08-30T15:19:51.818] [INFO ] [FC-DEPLOY] - Using region: cn-shenzhen
    [2021-08-30T15:19:51.819] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-08-30T15:19:51.819] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-08-30T15:19:51.820] [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-30T15:19:52.498] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-hexo exists
    [2021-08-30T15:19:52.703] [INFO ] [FC-DEPLOY] - Setting role: AliyunFCDefaultRole
    [2021-08-30T15:19:53.058] [INFO ] [RAM] - Checking Role AliyunFCDefaultRole exists
    [2021-08-30T15:19:53.239] [INFO ] [RAM] - Updating role: AliyunFCDefaultRole
    [2021-08-30T15:19:53.335] [INFO ] [RAM] - Checking Plicy AliyunFCDefaultRolePolicy exists
    [2021-08-30T15:19:53.464] [INFO ] [FC-DEPLOY] - Using vpcConfig: auto: fc will try to generate related vpc resources automatically
    [2021-08-30T15:19:54.308] [INFO ] [VPC] - Getting vpc: fc-deploy-component-generated-vpc-cn-shenzhen
    [2021-08-30T15:19:54.421] [INFO ] [VPC] - Getting vswitch: fc-deploy-component-generated-vswitch-cn-shenzhen
    [2021-08-30T15:19:54.554] [INFO ] [VPC] - Getting securityGroup: fc-deploy-component-generated-securityGroup-cn-shenzhen
    [2021-08-30T15:19:54.744] [INFO ] [FC-DEPLOY] - Generated vpcConfig:
    securityGroupId: sg-wz92ctigpi221smc****
    vSwitchId: vsw-wz9qnuult4q5g4f7n****
    vpcId: vpc-wz9x9bzs0wtvjgt6n****
    
    [2021-08-30T15:19:54.745] [INFO ] [FC-DEPLOY] - Using nasConfig: auto: fc will try to generate related nas file system automatically
    [2021-08-30T15:20:19.750] [INFO ] [FC-DEPLOY] - Generated nasConfig:
    groupId: 10003
    mountPoints:
      - fcDir: /mnt/auto
        nasDir: /serverless-devs-hexo
        serverAddr: example.com
    userId: 10003
    
    [2021-08-30T15:20:19.752] [INFO ] [FC-DEPLOY] - Checking Function hexo exists
    [2021-08-30T15:20:19.861] [WARN ] [FC-DEPLOY] - Image registry.cn-shenzhen.aliyuncs.com/web-framework/nodejs12:0.0.1 dose not exist locally.
    Maybe you need to run 's build' first if it dose not exist remotely.
    [2021-08-30T15:20:19.864] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-hexo exists
    [2021-08-30T15:20:19.978] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-hexo exists
    [2021-08-30T15:20:20.109] [INFO ] [FC-DEPLOY] - Creating service: serverless-devs-hexo
    [2021-08-30T15:20:20.109] [INFO ] [FC-DEPLOY] - Creating function: hexo
    [2021-08-30T15:20:20.109] [INFO ] [FC-DEPLOY] - Creating triggers: ["serverless-devs-hexo"]
     Make service serverless-devs-hexo success.
     Make function serverless-devs-hexo/hexo success.
     Make trigger serverless-devs-hexo/hexo/serverless-devs-hexo success.
    [2021-08-30T15:20:23.100] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-hexo exists
    [2021-08-30T15:20:23.185] [INFO ] [FC-DEPLOY] - Checking Function hexo exists
    [2021-08-30T15:20:23.312] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-hexo exists
    [2021-08-30T15:20:23.518] [INFO ] [FC-DEPLOY] - Creating custom domain: hexo.serverless-devs-hexo.188077086902****.cn-shenzhen.fc.devsapp.net
    [2021-08-30T15:20:24.225] [INFO ] [FC-DOMAIN] - Creating custom domain: hexo.serverless-devs-hexo.188077086902****.cn-shenzhen.fc.devsapp.net
    
    There is auto config in the service: serverless-devs-hexo
    [2021-08-30T15:20:24.932] [INFO ] [WEB-FRAMEWORK] - nas component get src is: .
    Packing ...
    file /test/start-hexo/.s is ignored.
    Package complete.
     Start uploading file: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-hexo/hexo/start-hexo.zip
     File uploaded successfully: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-hexo/hexo/start-hexo.zip
     upload done
    [2021-08-30T15:21:49.373] [INFO ] [FC-NAS] - unzipping file
    [2021-08-30T15:21:59.204] [INFO ] [FC-NAS] - unzip done
     Try container acceleration
    framework-test:
      region: cn-shenzhen
      serviceName: serverless-devs-hexo
      functionName: hexo
      customDomains:
        - >-
          http://hexo.serverless-devs-hexo.188077086902****.cn-shenzhen.fc.devsapp.net

Result

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:

curl http://hexo.serverless-devs-hexo.188077086902****.cn-shenzhen.fc.devsapp.net
Note The temporary domain name is used only for demonstration and development purposes. It is valid for a limited period of time. You must use a domain name that has obtained an Internet Content Provider (ICP) filing from Alibaba Cloud for production. For more information, see Configure a custom domain name.