Serverless microservice practice - Mobile application package distribution service

Keywords: Java Docker Mobile network


Alibaba cloud functional computing is an event driven fully hosted computing service. Through function calculation, you don't need to manage infrastructure such as servers, just write code and upload it. Function calculation will prepare computing resources for you, run your code in a flexible and reliable way, and provide log query, performance monitoring, alarm and other functions. With function computing, you can quickly build any type of application and service without management and operation and maintenance. Moreover, you only need to pay for the resources consumed by the actual running of the code, and there is no charge if the code is not running.The packaging and distribution of mobile applications show obvious peak valley utility. Users often need to prepare a large number of resources in a short time to ensure the real-time distribution. After the distribution, they need to release resources in time to reduce costs. Here we provide a fun Template, help us build a faster Function calculation Build the package distribution service of Serverless architecture, and achieve a good balance between the development and operation efficiency, performance and cost.

In the subcontracting process, download / modify / upload is a relatively resource consuming task, which needs to consume a lot of computing / network resources. And the subcontracting task only occurs when the application releases a new version, which needs to be completed in the shortest possible time. For this kind of scene with obvious peaks and troughs, it is very suitable to use function calculation. What's more, this service is elastic and highly available.

apk subcontract introduction

More reference Function calculation -- Serverless microservice practice mobile application package distribution service.


1. Install node

curl -o- | bash
nvm install 8

2. Install the fun tool

npm install @alicloud/fun -g

Some subcommands of the fun tool may use docker, so you need to install docker. For details, please refer to the document: Fun installation tutorial.

3.apk package preparation

In this experiment, we will use a sample apk package, which can be downloaded from here qq-v2.apk.

download qq-v2.apk , upload to your oss bucket:

Quick start:

1. Generate project skeleton through fun template

Use the fun init command to quickly initialize the template project to the local area, execute the command:

$ fun init -n apk
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...
finish rendering template.

Where - n represents the name of the project to build as a folder. The default is fun app. For more descriptions of the command format options of fun init, please refer to the cloud habitat article Developing the correct posture of function calculation -- initializing the project with Fun Init.

After performing fun init, you will be prompted: enter an oss Bucket. Note that oss Bucket is unique in the world. If it has been occupied, please change a new name or create one (the created one, please make sure that the region is consistent).

ps: the input content is the same as oss bucket name mentioned in apk package preparation. This example is: sunfeiyu

4. compilation

Execute the fun build command in the root directory of the template project to compile:

$ 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

Please refer to yunqi article for details about the function of Fun build Developing the correct posture of function calculation -- using Fun Build to build function.

5. Service deployment

Perform the fun deploy deployment to the cloud under the root directory of the template project.

$ 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. Execute function

There are two ways:

  1. Log in to Alibaba cloud function computing Console , manually.

  1. In the root directory of the project, the fun invoke apk command is called remotely:
$ 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:

View results

Log in to oss to see if a new apk package has been generated:

Download qq-v2-signed.apk from oss to local.

To check whether channel information is written:

~/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 information {channel = aliyun FC} has been written, success!

Reference reading

  1. Fun (Fun with Serverless) tool
  2. Fun Init custom template

"Alibaba cloud native Pay attention to microservices, Serverless, containers, Service Mesh and other technology fields, focus on cloud native popular technology trends, cloud native large-scale landing practice, and become the technology circle that most understands cloud native developers. "

228 original articles published, 39 praised, 20000 visitors+
Private letter follow

Posted by faizanno1 on Wed, 15 Jan 2020 23:25:45 -0800