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

前提条件

您已完成以下操作:

操作步骤

  1. 在目标目录中执行以下命令,初始化项目。
    s init devsapp/start-pyramid -d start-pyramid
    -d用于指定项目名称,本示例以项目名称start-pyramid为例,介绍如何迁移pyramid到函数计算。
    说明 若已存在该项目则跳过此步骤。
    输出示例:
     Serverless Awesome: https://github.com/Serverless-Devs/package-awesome
    
     devsapp!start-pyramid@0.0.6.zip file decompression completed
     please select credential alias default
    
        ______                          _     _
        | ___ \                        (_)   | |
        | |_/ /   _ _ __ __ _ _ __ ___  _  __| |
        |  __/ | | | '__/ _` | '_ ` _ \| |/ _` |
        | |  | |_| | | | (_| | | | | | | | (_| |
        \_|   \__, |_|  \__,_|_| |_| |_|_|\__,_|
               __/ |
              |___/
    
    
        Welcome to the start-pyramid 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 Pyramid project:
             Full yaml configuration : https://github.com/devsapp/pyramid#%E5%AE%8C%E6%95%B4yaml
             Pyramid development docs: https://trypyramid.com/documentation.html
         This application homepage: https://github.com/devsapp/start-pyramid
    
    
    ‍ Thanks for using Serverless-Devs
     You could [cd /test/start-pyramid] 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-pyramid
  3. 执行以下命令,部署项目。
    s deploy
    输出示例:
    [2021-08-31T11:00:59.574] [INFO ] [S-CLI] - Start ...
    [2021-08-31T11:00:59.583] [INFO ] [S-CLI] - Start the pre-action
    [2021-08-31T11:00:59.583] [INFO ] [S-CLI] - Action: pip3 install -t . -r requirements.txt
    WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
    Collecting pyramid==2.0 (from -r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/38/05/c75c59a1d8a3e44d3cb7d9ef9969bd4ff6dc18d860519dd1ef0cd547139f/pyramid-2.0-py3-none-any.whl (246kB)
        100% |████████████████████████████████| 256kB 15.9MB/s
    Collecting setuptools (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/bd/25/5bdf7f1adeebd4e3fa76b2e2f045ae53ee208e40a4231ad0f0c3007e4353/setuptools-57.4.0-py3-none-any.whl (819kB)
        100% |████████████████████████████████| 819kB 8.4MB/s
    Collecting translationstring>=0.4 (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/3b/98/36187601a15e3d37e9bfcf0e0e1055532b39d044353b06861c3a519737a9/translationstring-1.4-py2.py3-none-any.whl
    Collecting plaster (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/61/29/3ac8a5d03b2d9e6b876385066676472ba4acf93677acfc7360b035503d49/plaster-1.0-py2.py3-none-any.whl
    Collecting zope.deprecation>=3.5.0 (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/f9/26/b935bbf9d27e898b87d80e7873a0200cebf239253d0afe7a59f82fe90fff/zope.deprecation-4.4.0-py2.py3-none-any.whl
    Collecting plaster-pastedeploy (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/11/c4/0470056ea324c7a420c22647be512dec1b5e32b1b6e77e27c61838d2811c/plaster_pastedeploy-0.7-py2.py3-none-any.whl
    Collecting venusian>=1.0 (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/43/92/3d522a710867168ee422a0ffbd712c425ece937aaeec4381497a59e24faf/venusian-3.0.0-py3-none-any.whl
    Collecting zope.interface>=3.8.0 (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/67/67/8178e511cd4f0a481082aac1c0e2d64c520a5ee92ea8ce42d8297a4fca7e/zope.interface-5.4.0-cp36-cp36m-manylinux1_x86_64.whl (251kB)
        100% |████████████████████████████████| 256kB 425kB/s
    Collecting webob>=1.8.3 (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/62/9c/e94a9982e9f31fc35cf46cdc543a6c2c26cb7174635b5fd25b0bbc6a7bc0/WebOb-1.8.7-py2.py3-none-any.whl (114kB)
        100% |████████████████████████████████| 122kB 1.9MB/s
    Collecting hupper>=1.5 (from pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/9a/cb/d30896ad0d288358bbae60576556df78422179fc08c630f863258a7800ea/hupper-1.10.3-py2.py3-none-any.whl
    Collecting PasteDeploy>=2.0 (from plaster-pastedeploy->pyramid==2.0->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/8f/0b/d47ea894587f3155f8c4520aa74d57c856189d0bbe27e831881d655a3386/PasteDeploy-2.1.1-py2.py3-none-any.whl
    Installing collected packages: setuptools, translationstring, plaster, zope.deprecation, PasteDeploy, plaster-pastedeploy, venusian, zope.interface, webob, hupper, pyramid
    Successfully installed PasteDeploy-2.1.1 hupper-1.10.3 plaster-1.0 plaster-pastedeploy-0.7 pyramid-2.0 setuptools-57.4.0 translationstring-1.4 venusian-3.0.0 webob-1.8.7 zope.deprecation-4.4.0 zope.interface-5.4.0
    Target directory /test/start-pyramid/src/zope already exists. Specify --upgrade to force replacement.
    [2021-08-31T11:01:04.322] [INFO ] [S-CLI] - End the pre-action
      devsapp!pyramid@0.0.6.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:14083) [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-31T11:01:28.838] [INFO ] [FC-DEPLOY] - Using region: cn-shenzhen
    [2021-08-31T11:01:28.840] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-08-31T11:01:28.841] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-08-31T11:01:28.841] [INFO ] [FC-DEPLOY] - Using accessKeySecret: KdcUEJLoGto****
      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-31T11:01:29.465] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-pyramid exists
    [2021-08-31T11:01:29.726] [INFO ] [FC-DEPLOY] - Setting role: AliyunFCDefaultRole
    [2021-08-31T11:01:30.115] [INFO ] [RAM] - Checking Role AliyunFCDefaultRole exists
    [2021-08-31T11:01:30.291] [INFO ] [RAM] - Updating role: AliyunFCDefaultRole
    [2021-08-31T11:01:30.399] [INFO ] [RAM] - Checking Plicy AliyunFCDefaultRolePolicy exists
    [2021-08-31T11:01:30.627] [INFO ] [FC-DEPLOY] - Using vpcConfig: auto: fc will try to generate related vpc resources automatically
    [2021-08-31T11:01:31.411] [INFO ] [VPC] - Getting vpc: fc-deploy-component-generated-vpc-cn-shenzhen
    [2021-08-31T11:01:31.519] [INFO ] [VPC] - Getting vswitch: fc-deploy-component-generated-vswitch-cn-shenzhen
    [2021-08-31T11:01:31.644] [INFO ] [VPC] - Getting securityGroup: fc-deploy-component-generated-securityGroup-cn-shenzhen
    [2021-08-31T11:01:31.793] [INFO ] [FC-DEPLOY] - Generated vpcConfig:
    securityGroupId: sg-wz92ctigpi221smc****
    vSwitchId: vsw-wz9qnuult4q5g4f7n****
    vpcId: vpc-wz9x9bzs0wtvjgt6n****
    
    [2021-08-31T11:01:31.793] [INFO ] [FC-DEPLOY] - Using nasConfig: auto: fc will try to generate related nas file system automatically
    [2021-08-31T11:01:57.879] [INFO ] [FC-DEPLOY] - Generated nasConfig:
    groupId: 10003
    mountPoints:
      - fcDir: /mnt/auto
        nasDir: /serverless-devs-pyramid
        serverAddr: example.com
    userId: 10003
    
    [2021-08-31T11:01:57.881] [INFO ] [FC-DEPLOY] - Checking Function pyramid exists
    [2021-08-31T11:01:57.991] [WARN ] [FC-DEPLOY] - Image registry.cn-shenzhen.aliyuncs.com/web-framework/python3:0.0.1 dose not exist locally.
    Maybe you need to run 's build' first if it dose not exist remotely.
    [2021-08-31T11:01:57.994] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-pyramid exists
    [2021-08-31T11:01:58.089] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-pyramid exists
    [2021-08-31T11:01:58.173] [INFO ] [FC-DEPLOY] - Creating service: serverless-devs-pyramid
    [2021-08-31T11:01:58.174] [INFO ] [FC-DEPLOY] - Creating function: pyramid
    [2021-08-31T11:01:58.174] [INFO ] [FC-DEPLOY] - Creating triggers: ["serverless-devs-pyramid"]
      Make service serverless-devs-pyramid success.
      Make function serverless-devs-pyramid/pyramid success.
      Make trigger serverless-devs-pyramid/pyramid/serverless-devs-pyramid success.
    [2021-08-31T11:02:01.403] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-pyramid exists
    [2021-08-31T11:02:01.476] [INFO ] [FC-DEPLOY] - Checking Function pyramid exists
    [2021-08-31T11:02:01.602] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-pyramid exists
    [2021-08-31T11:02:01.777] [INFO ] [FC-DEPLOY] - Creating custom domain: pyramid.serverless-devs-pyramid.188077086902****.cn-shenzhen.fc.devsapp.net
    [2021-08-31T11:02:02.615] [INFO ] [FC-DOMAIN] - Creating custom domain: pyramid.serverless-devs-pyramid.188077086902****.cn-shenzhen.fc.devsapp.net
    
    There is auto config in the service: serverless-devs-pyramid
    [2021-08-31T11:02:03.348] [INFO ] [WEB-FRAMEWORK] - nas component get src is: ./src
    Packing ...
    Package complete.
      Start uploading file: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-pyramid/pyramid/src.zip
      File uploaded successfully: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-pyramid/pyramid/src.zip
      upload done
    [2021-08-31T11:02:44.846] [INFO ] [FC-NAS] - unzipping file
    [2021-08-31T11:02:47.997] [INFO ] [FC-NAS] - unzip done
      Try container acceleration
    framework-test:
      region: cn-shenzhen
      serviceName: serverless-devs-pyramid
      functionName: pyramid
      customDomains:
        - >-
          http://pyramid.serverless-devs-pyramid.188077086902****.cn-shenzhen.fc.devsapp.net

执行结果

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

curl http://pyramid.serverless-devs-pyramid.188077086902****.cn-shenzhen.fc.devsapp.net
说明 临时域名仅用作演示以及开发,具有时效性。如需用作生产,请绑定已经在阿里云备案的域名。详细信息,请参见绑定自定义域名