Serverless实现移动应用包分发服务的过程-创新互联

这篇文章给大家分享的是Serverless实现移动应用包分发服务的过程。小编觉得挺实用的,因此分享给大家学习。如下资料是关于Serverless实现移动应用包分发服务的步骤。

成都创新互联公司一直通过网站建设和网站营销帮助企业获得更多客户资源。 以"深度挖掘,量身打造,注重实效"的一站式服务,以网站设计制作、成都做网站、移动互联产品、全网整合营销推广服务为核心业务。十余年网站制作的经验,使用新网站建设技术,全新开发出的标准网站,不但价格便宜而且实用、灵活,特别适合中小公司网站制作。网站管理系统简单易用,维护方便,您可以完全操作网站资料,是中小公司快速网站建设的选择。

准备工作:

1.安装 node

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
nvm install 8

2.安装 fun 工具

npm install @alicloud/fun -g

fun 工具的某些子命令可能会用到 docker,所以你需要安装好 docker,具体参考文档:Fun 安装教程。

3.apk 包准备

在这个实验中,我们会使用一个示例的 apk 包,可以从这里下载 qq-v2.apk。

下载 qq-v2.apk ,上传到自己的 oss bucket中

快速开始:

1.通过 fun 模板生成项目骨架

使用 fun init 命令可以快捷的将本模板项目初始化到本地,执行命令 :

$ fun init -n apk https://github.com/coco-super/package-distribution-service-for-serverless
start cloning...
Cloning into '.fun-init-cache-2fc2d680-eeff-11e9-a930-6fd4d1ac6506'...
remote: Enumerating objects: 23, done.
remote: Counting objects: 100% (23/23), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 23 (delta 0), reused 18 (delta 0), pack-reused 0
Unpacking objects: 100% (23/23), done.
finish clone.
? Please input a oss bucket name? sunfeiyu
Start rendering template...
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/.funignore
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/pom.xml
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/src
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/src/main
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/src/main/java
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/src/main/java/example
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/src/main/java/example/App.java
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/target
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/target/classes
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/target/classes/example
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/target/classes/example/App.class
+ /Users/ellison/simple-fc-uncompress-service-for-oss/apk/template.yml
finish rendering template.

其中 -n 表示要作为文件夹生成的项目名称。默认值是 fun-app。更多fun init 命令格式选项说明请参考云栖文章开发函数计算的正确姿势 —— 使用 Fun Init 初始化项目。

执行 fun init后会提示:输入一个 oss 的 bucket,注意 oss Bucket 是全球唯一的,如已经被占用了,请换一个新的名称或者一个已经创建好的(已经创建好的,请确保 region 一致)。

ps: 输入的内容和 apk 包准备中提到的 oss bucket name 是同一个,本示例为:sunfeiyu

4. 编译

在模版项目的根目录下执行 fun build 命令编译:

$ fun build 
using template: template.yml
start building function dependencies without docker

building apk/apk
running task flow MavenTaskFlow
running task: MavenCompileTask
running task: MavenCopyDependencies
running task: CopyMavenArtifacts

Build Success

Built artifacts: .fun/build/artifacts
Built template: .fun/build/artifacts/template.yml

Tips for next step
======================
* Invoke Event Function: fun local invoke
* Invoke Http Function: fun local start
* Deploy Resources: fun deploy

开发函数计算的正确姿势 —— 使用 Fun Build 构建函数。

5.服务部署

在模版项目的的根目录下执行 fun deploy 部署到云端。

$ fun deploy
using template: .fun/build/artifacts/template.yml
using region: cn-shanghai
using accountId: ***********8320
using accessKeyId: ***********mTN4
using timeout: 60

Waiting for service apk to be deployed...
     make sure role 'aliyunfcgeneratedrole-cn-shanghai-apk' is exist
     role 'aliyunfcgeneratedrole-cn-shanghai-apk' is already exist
     attaching policies AliyunOSSFullAccess to role: aliyunfcgeneratedrole-cn-shanghai-apk
     attached policies AliyunOSSFullAccess to role: aliyunfcgeneratedrole-cn-shanghai-apk
     Waiting for function apk to be deployed...
         Waiting for packaging function apk code...
         The function apk has been packaged. A total of 15 files files were compressed and the final size was 3.13 MB
     function apk deploy success
service apk deploy success

6.执行函数

提供两种方式:

  1. 登陆云函数计算控制台,手动执行。
  1. 项目根目录下 fun invoke apk 命令远端调用:
$ fun invoke apk
using template: template.yml
========= FC invoke Logs begin =========
FC Invoke Start RequestId: 23f34cc4-0cd3-40e0-9a04-f6586cf29be6
2019-10-14 17:06:35.971 [INFO] [23f34cc4-0cd3-40e0-9a04-f6586cf29be6] cmd: java -jar /code/walle-cli-all.jar put -c aliyun-fc /tmp/input.apk /tmp/output.apk
2019-10-14 17:06:36.152 [INFO] [23f34cc4-0cd3-40e0-9a04-f6586cf29be6] Success!

FC Invoke End RequestId: 23f34cc4-0cd3-40e0-9a04-f6586cf29be6

Duration: 666.13 ms, Billed Duration: 700 ms, Memory Size: 1024 MB, Max Memory Used: 254.55 MB
========= FC invoke Logs end =========

FC Invoke Result:
Success

查看结果

登陆 oss 查看已经生成新的 apk 包:

将 oss 中 qq-v2-signed.apk 下载到本地。

查看渠道信息是否写入:

~/Downloads                                                                       ⍉
$ java -jar /Users/ellison/Downloads/walle-cli-all.jar show qq-v2-signed.apk
/Users/ellison/Downloads/qq-v2-signed.apk : {channel=aliyun-fc}

渠道信息 {channel=aliyun-fc} 已写入,成功!

关于Serverless实现移动应用包分发服务的过程就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站名称:Serverless实现移动应用包分发服务的过程-创新互联
URL标题:http://ybzwz.com/article/dpcchs.html