這篇文章給大家分享的是Serverless實現(xiàn)移動應(yīng)用包分發(fā)服務(wù)的過程。小編覺得挺實用的,因此分享給大家學(xué)習(xí)。如下資料是關(guān)于Serverless實現(xiàn)移動應(yīng)用包分發(fā)服務(wù)的步驟。
創(chuàng)新互聯(lián)公司長期為近1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為潤州企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計、成都做網(wǎng)站,潤州網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
nvm install 8
npm install @alicloud/fun -g
fun 工具的某些子命令可能會用到 docker,所以你需要安裝好 docker,具體參考文檔:Fun 安裝教程。
在這個實驗中,我們會使用一個示例的 apk 包,可以從這里下載 qq-v2.apk。
下載 qq-v2.apk ,上傳到自己的 oss bucket中
快速開始:
使用 fun init
命令可以快捷的將本模板項目初始化到本地,執(zhí)行命令 :
$ 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 表示要作為文件夾生成的項目名稱。默認(rèn)值是 fun-app。更多fun init 命令格式選項說明請參考云棲文章開發(fā)函數(shù)計算的正確姿勢 —— 使用 Fun Init 初始化項目。
執(zhí)行 fun init
后會提示:輸入一個 oss 的 bucket,注意 oss Bucket 是全球唯一的,如已經(jīng)被占用了,請換一個新的名稱或者一個已經(jīng)創(chuàng)建好的(已經(jīng)創(chuàng)建好的,請確保 region 一致)。
ps: 輸入的內(nèi)容和 apk 包準(zhǔn)備中提到的 oss bucket name 是同一個,本示例為:sunfeiyu
在模版項目的根目錄下執(zhí)行 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
開發(fā)函數(shù)計算的正確姿勢 —— 使用 Fun Build 構(gòu)建函數(shù)。
在模版項目的的根目錄下執(zhí)行 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
提供兩種方式:
fun invoke apk
命令遠(yuǎn)端調(diào)用:$ 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 查看已經(jīng)生成新的 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}
已寫入,成功!
關(guān)于Serverless實現(xiàn)移動應(yīng)用包分發(fā)服務(wù)的過程就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。