serverless云函数初体验

    0

背景

之前个人项目都是部署在云服务器上,导致买了4台服务器才满足了场景 准备逐步迁移到serverless

serverless服务商

准备知识

我们使用阿里云函数来部署

文档

概要

  1. 迁移主要对已有的项目进行迁移,涵盖node项目、前端项目、java项目,计划用githubactionjenkins都可以cicdserverless
  2. 本着最小改动原则,我们对项目添加s.yaml配置文件+cicd工具进发布

node项目

yaml
edition: 1.0.0 access: "default" services: framework: # 业务名称/模块名称 component: fc # 组件名称 actions: pre-deploy: - run: pnpm i --frozen-lockfile path: ./ - run: pnpm run build path: ./ props: # 组件的属性值 region: cn-shanghai service: name: node-service description: "Serverless Devs Website Service" function: name: blog description: "Serverless Devs Website Docusaurus Function" runtime: custom codeUri: ./ timeout: 30 memorySize: 512 caPort: 9800 customRuntimeConfig: command: - npm args: - 'run' - 'start' triggers: - name: httpTrigger type: http config: authType: anonymous methods: - GET - POST - PUT - DELETE customDomains: - domainName: auto protocol: HTTP routeConfigs: - path: /*

纯前端静态资源项目

yaml
edition: 1.0.0 access: "default" services: framework: # 业务名称/模块名称 component: fc # 组件名称 actions: pre-deploy: - run: pnpm i --frozen-lockfile path: ./ - run: pnpm run doc:build path: ./ - plugin: website-fc props: # 组件的属性值 region: cn-shanghai service: name: web-service description: "Serverless Devs Website Service" function: name: design description: "Serverless Devs Website Docusaurus Function" codeUri: ./dist timeout: 30 memorySize: 512 triggers: - name: httpTrigger type: http config: authType: anonymous methods: - GET - POST - PUT - DELETE customDomains: - domainName: auto protocol: HTTP routeConfigs: - path: /*

java项目

yaml
#s.yaml edition: 1.0.0 access: "default" services: framework: # 业务名称/模块名称 component: fc # 组件名称 actions: pre-deploy: - run: mvn clean package -DskipTests path: ./ props: # 组件的属性值 region: cn-shanghai service: name: java-service description: "Serverless Devs Website Service" function: name: server description: "Serverless Devs Website Docusaurus Function" runtime: custom codeUri: ./ timeout: 30 memorySize: 512 caPort: 8080 customRuntimeConfig: command: - java args: - '-jar' - 'target/blog-server-1.0.0.jar' triggers: - name: httpTrigger type: http config: authType: anonymous methods: - GET - POST - PUT - DELETE customDomains: - domainName: auto protocol: HTTP routeConfigs: - path: /*

附件

评论区

共有评论 0

暂无评论