alibaba / funcraft

(have) Fun with Serverless(API Gateway & Function Compute)
MIT License
941 stars 127 forks source link

执行部署命令后不停的重复打包上传 #930

Open CloudyAnt opened 4 years ago

CloudyAnt commented 4 years ago

因为包大小超过了 50M,部署时选择使用 NAS

第一次部署,命令行显示是成功的(调用函数报错说找不到 /code/boostrap,但这应该是别的问题了)

后面执行 fun build,再 fun deploy -y,就出现了重复打包上传的问题:

...
...
zipping /Users/chaijiaqi/todomato/user-service/target/lib
✔ upload done
unzipping file
✔ unzip done
✔ upload completed!

Fun has automatically uploaded your code dependency to NAS, then fun will use 'fun deploy todomato-user-service/user-function' to redeploy.
Waiting for service todomato-user-service to be deployed...
        make sure role 'aliyunfcgeneratedrole-cn-beijing-todomato-user-service' is exist
        role 'aliyunfcgeneratedrole-cn-beijing-todomato-user-service' is already exist
        attaching police 'AliyunECSNetworkInterfaceManagementAccess' to role: aliyunfcgeneratedrole-cn-beijing-todomato-user-service
        attached police 'AliyunECSNetworkInterfaceManagementAccess' to role: aliyunfcgeneratedrole-cn-beijing-todomato-user-service
        using 'VpcConfig: Auto', Fun will try to generate related vpc resources automatically
                vpc already generated, vpcId is: vpc-2zemuwbvjhwc7a4ptxaol
                vswitch already generated, vswitchId is: vsw-2zesmh8og9q73uz4h9nc7
                security group already generated, security group is: sg-2ze8mav2o3p0q0q3zeh7
        generated auto VpcConfig done:  {"vpcId":"vpc-2zemuwbvjhwc7a4ptxaol","vswitchIds":["vsw-2zesmh8og9q73uz4h9nc7"],"securityGroupId":"sg-2ze8mav2o3p0q0q3zeh7"}
        using 'NasConfig: Auto', Fun will try to generate related nas file system automatically
                nas file system already generated, fileSystemId is: 160df495cd
                nas file system mount target is already created, mountTargetDomain is: 160df495cd-cuu21.cn-beijing.nas.aliyuncs.com
        generated auto NasConfig done:  {"UserId":10003,"GroupId":10003,"MountPoints":[{"ServerAddr":"160df495cd-cuu21.cn-beijing.nas.aliyuncs.com:/todomato-user-service","MountDir":"/mnt/auto"}]}
        Checking if nas directories /todomato-user-service exists, if not, it will be created automatically
        Checking nas directories done ["/todomato-user-service"]
        Waiting for function user-function to be deployed...
                Waiting for packaging function user-function code...
                warning: funignore is not supported for your CodeUri: /Users/chaijiaqi/todomato/user-service
:zipping ███████[39[32m██████████████ 178/483 161 files/s, 36% 1.9s^C%  

后面会不停的重复 zipping ... uploading ...

这是一个 Spring Boot 项目,先前使用 fun deploy -y 转换成函数计算 template.yml:

ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
  todomato-user-service:
    Type: 'Aliyun::Serverless::Service'
    Properties:
      Description: Hello SpringBoot On FC
      NasConfig: Auto
    user-function:
      Type: 'Aliyun::Serverless::Function'
      Properties:
        Handler: index.handler
        Runtime: custom
        CodeUri: ./
        InstanceConcurrency: 5
        MemorySize: 1024
        Timeout: 60
        InitializationTimeout: 100
        EnvironmentVariables:
          CLASSPATH: /mnt/auto/java/*
      Events:
        http:
          Type: HTTP
          Properties:
            AuthType: ANONYMOUS
            Methods:
              - GET
              - POST
              - PUT
  Domain:
    Type: 'Aliyun::Serverless::CustomDomain'
    Properties:
      DomainName: todomato.lightmoov.com
      Protocol: 'HTTP,HTTPS'
      CertConfig:
        CertName: TodomatoCertificate
        PrivateKey: ./certificates/3951242_todomato.lightmoov.com.key.pem
        Certificate: ./certificates/3951242_todomato.lightmoov.com.pem
      RouteConfig:
        Routes:
          /users/*:
            ServiceName: todomato-user-service
            FunctionName: user-function
          /admins/*:
            ServiceName: todomato-user-service
            FunctionName: user-function
          /users:
            ServiceName: todomato-user-service
            FunctionName: user-function
          /admins:
            ServiceName: todomato-user-service
            FunctionName: user-function
          /user-operations:
            ServiceName: todomato-user-service
            FunctionName: user-function
          /token:
            ServiceName: todomato-user-service
            FunctionName: user-function
          /login:
            ServiceName: todomato-user-service
            FunctionName: user-function
          /login/*:
            ServiceName: todomato-user-service
            FunctionName: user-function

boostrap:

#!/usr/bin/env bash
export PORT=9000
export CLASSPATH="$CLASSPATH:./target/user-service-1.0.jar"
java -Dserver.port=$PORT org.springframework.boot.loader.PropertiesLauncher
DevDengChao commented 4 years ago

依赖库上传到 NAS 后, 用于启动函数的部分依然超过 50Mb, 就触发循环上传了. 建议把应用层的 Jar 直接上传到 NAS 或者 OSS, FC 这边只留一个 Initializer 用于启动 Jar.