关于github:使用-Serverless-Devs-插件快速部署前端应用

7次阅读

共计 2064 个字符,预计需要花费 6 分钟才能阅读完成。

作者 | 邓超 Serverless Devs 开源贡献者

背景

咱们在 [上文 [Aliyun] [FC] 如何应用 @serverless-devs/s 部署动态网站到函数计算](https://blog.dengchao.fun/_po…) 中,具体的介绍了如何通过 @serverless-devs/s 将曾经开发好了的 动态网站 部署到阿里云函数计算(FC)上, 然而近期函数计算和 @serverless-devs/s 都更新了一系列的性能, 目前部署动态网站的步骤能够更为简洁了!

应用 website-fc 插件部署动态网站到 Custom Runtime 函数

假如咱们当初有如下构造的前端工程:

step 3. 装置 @serverless-devs/s 并编写 s.yaml

你问我步骤 1 和 2 去哪儿了? 当然是省掉了! 😂
增加 @serverless-devs/s 命令行工具到工程:

而后在根目录下创立一个根底的 s.yaml 配置文件:

# https://github.com/devsapp/fc/blob/main/docs/zh/yaml/
edition: 1.0.0
name: my-awesome-website-project
services:
  my-service: # 任意的名称
    actions:
      pre-deploy:
        - plugin: website-fc         # 在 pre-deploy 插槽中装置 website-fc 插件
    component: devsapp/fc             # 应用 fc 组件
    props:
      region: cn-shenzhen             # 部署到任意的可用区, 例如深圳.
      service:
        name: my-awesome-websites     # 深圳可用区的 my-awesome-websites 服务
      function:
        name: website-fc-plugin        # my-awesome-websites 服务下的一个函数
        runtime: custom                # 应用 custom 运行环境
        handler: dummy-handler         # 因为应用了 custom 运行环境, 所以这里能够轻易填
        codeUri: ./dist                # 部署 dist 文件夹下的全部内容
      triggers:
        - name: http
          type: http                # 创立一个 HTTP 类型的触发器, 以便客户端能够通过 HTTP 协定进行拜访
          config:
            authType: anonymous        # 容许匿名拜访
            methods: [HEAD, GET]    # 动态网站只须要解决 HEAD 和 GET 申请就够了

与上文中不同的中央在于:

actions:
      pre-deploy:
        - plugin: website-fc         # 在 pre-deploy 插槽中装置 website-fc 插件

在 pre-deploy 插槽中装置的 website-fc 插件能代替上文中的步骤 1 和步骤 2;
以及

当初不用将整个工程部署到函数中, 只须要部署构建好的动态文件了。

step 4. 部署到函数计算

配置好 AccessKey 和 AccessSecret 后 (opens new window), 详情参考:https://www.serverless-devs.com/serverless-devs/command/config,执行命令:

🎉 你的网站就部署下来啦。
接下来就是配置自定义域名了, 配置好当前就能够通过你本人的域名拜访到这个网站了。

step 5. 配置自定义域名

以自定义域名 deploy-static-website-with-website-fc-plugin.example.dengchao.fun 为例.
首先增加 CNAME 记录, 解析值填写 ${UID}.${REGION}.fc.aliyuncs.com. 因为咱们的 s.yaml 中设置的 region 是 cn-shenzhen, 所以对应的值就是 xxxxxx.cn-shenzhen.fc.aliyuncs.com .
接下来设置函数计算管制台上的自定义域名:

🎉 拜访一下试试看: http://deploy-static-website-with-website-fc-plugin.example.dengchao.fun(opens new window)

样本工程

本文中的样本工程曾经上传到 GitHub:
https://github.com/DevDengChao/deploy-static-website-with-website-fc-plugin-example(opens new window)

参考

  • 阿里云函数计算 - 产品简介(opens new window)

    • 资源应用限度(opens new window)
    • 自定义运行环境(opens new window)
    • 配置自定义域名(opens new window)
  • Serverless devs 官网(opens new window)

    • 配置 AccessKey 和 AccessSecret(opens new window)
  • website-fc 插件

更多内容关注 Serverless 微信公众号(ID:serverlessdevs),会集 Serverless 技术最全内容,定期举办 Serverless 流动、直播,用户最佳实际。

正文完
 0