本文介绍如何将expressCart应用部署到函数计算。与传统的部署方法相比,您可将传统的expressCart应用一键部署至远端直接用于生产,跳过购买机器等步骤的同时,还拥有了弹性伸缩、按量付费和免运维等特性。

前提条件

您已完成以下操作:

背景信息

expressCart应用是基于expressCart开源购物网站的组件,使用该组件可以快速完成自身电商购物网站的部署。

操作步骤

  1. 在目标目录中执行以下命令初始化项目。
    s init  start-expresscart
    输出示例:
    Serverless Awesome: https://github.com/Serverless-Devs/package-awesome
    
     Please input your project name (init dir) start-expresscart//系统已默认为您设置了文件夹名称,可按需修改。
     file decompression completed
     please input mongodb 的连接地址: mongodb://[username:password@]host[:port]//根据实际情况设置云数据库MongoDB Serverless的接入地址。
    
     Thanks for using Serverless-Devs
     You could [cd /test/start-expresscart] 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. 执行以下命令,进入项目目录。
    cd start-expresscart
  3. 执行以下命令,部署应用。
    s deploy
    输出示例:
    [2021-09-29T16:33:04.081] [INFO ] [S-CLI] - Start ...
    [2021-09-29T16:33:04.095] [INFO ] [S-CLI] - Start the pre-action
    [2021-09-29T16:33:04.095] [INFO ] [S-CLI] - Action: npm i
    npm WARN EBADENGINE Unsupported engine {
    npm WARN EBADENGINE   package: 'express-cart@1.1.19',
    npm WARN EBADENGINE   required: { node: '10.16.0' },
    npm WARN EBADENGINE   current: { node: 'v14.17.4', npm: '7.22.0' }
    npm WARN EBADENGINE }
    
    up to date in 2s
    [2021-09-29T16:33:05.993] [INFO ] [S-CLI] - End the pre-action
    ./expresscart path
    Sending build context to Docker daemon  1.883MB
     ......
     ---> Running in 748152961ece
    Removing intermediate container 748152961ece
     ---> 4556acb235f7
    Step 17/17 : ENTRYPOINT ["npm", "start"]
     ---> Running in 03c34e906857
    Removing intermediate container 03c34e906857
     ---> 050e32da9f30
    Successfully built 050e32da9f30
    Successfully tagged expresscart:latest
    execute build pack successfuly
    Login Succeeded
    
    login acr successfuly
    docker tag successfuly
    The push refers to repository [registry.cn-hangzhou.aliyuncs.com/serverlessdevs188077086902****/expresscart]
    
    ......
    84c62e276f70: Layer already exists
    
    1b3c69acba41: Layer already exists
    
    055415e8286d: Layer already exists
    
    721384ec99e5: Layer already exists
    
    a8ff54d4d483: Pushed
    
    
    a3a0a84ce2fd: Pushed
    
    1632904390344: digest: sha256:6a6a07bbfcc99fbacded28385d45410d7649a8439808ceb28faa079727d16e0d size: 3247
    
    docker push execute successfuly
    expressCart:
      serviceName:  expresscart-test
      functionName: express-cart
      domain:       60657313-188077086902****.test.functioncompute.com

执行结果

成功部署该项目后,您可以在执行输出中查看到函数计算生成的临时域名,通过该临时域名可以访问刚部署的应用,例如执行以下命令访问应用:

curl 60657313-188077086902****.test.functioncompute.com
说明 临时域名仅用作演示以及开发,具有时效性。如需用作生产,请绑定已经在阿里云备案的域名。详细信息,请参见绑定自定义域名