Develop Function Compute by Installing Third-Party Dependencies

Background Information

Procedure

Use the Fun Install Init

$ fun install init
? Select runtime (Use arrow keys)
python2.7
python3
nodejs6
nodejs8
java8
php7.2
runtime: python2.7
tasks: []

Install pip package dependency

$ fun install --runtime python2.7 --package-type pip tensorflow
skip pulling image aliyunfc/runtime-python2.7:build-1.2.0...
Task => [UNNAMED]
=> PYTHONUSERBASE=/code/.fun/python pip install --user tensorflow
.fun
└── python
├── bin
│ ├── freeze_graph
│ ├── markdown_py
│ ├── pbr
│ ├── saved_model_cli
│ ├── tensorboard
│ ├── tflite_convert
│ ├── toco
│ └── toco_from_protos
└── lib
└── python2.7
└── site-packages
├── tensorboard
├── tensorboard-1.12.2.dist-info
├── tensorflow
├── tensorflow-1.12.0.dist-info
├── termcolor-1.1.0.dist-info
...
$ fun install env
LD_LIBRARY_PATH=/code/.fun/root/usr/lib/x86_64-linux-gnu:/code:/code/lib:/usr/local/lib
PATH=/code/.fun/root/usr/local/bin:/code/.fun/root/usr/local/sbin:/code/.fun/root/usr/bin:/code/.fun/root/usr/sbin:/code/.fun/root/sbin:/code/.fun/root/bin:/code/.fun/python/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin
PYTHONUSERBASE=/code/.fun/python

Use — save for Persistence

$ fun install --runtime python2.7 --package-type pip --save tensorflow
skip pulling image aliyunfc/runtime-python2.7:build-1.2.0...
Task => [UNNAMED]
=> PYTHONUSERBASE=/code/.fun/python pip install --user tensorflow
runtime: python2.7
tasks:
- pip: tensorflow
local: true
$ fun install
skip pulling image aliyunfc/runtime-python2.7:build-1.2.0...
Task => [UNNAMED]
=> PYTHONUSERBASE=/code/.fun/python pip install --user tensorflow

Use -v to Display Detailed Logs

$ fun install -v
skip pulling image aliyunfc/runtime-python3.6:build-1.2.0...
Task => [UNNAMED]
=> apt-get update (if need)
Ign http://mirrors.aliyun.com stretch InRelease
Get:1 http://mirrors.aliyun.com stretch-updates InRelease [91.0 kB]
Get:2 http://mirrors.aliyun.com stretch-backports InRelease [91.8 kB]
Get:3 http://mirrors.aliyun.com stretch/updates InRelease [94.3 kB]
Hit http://mirrors.aliyun.com stretch Release.gpg
Hit http://mirrors.aliyun.com stretch Release
Get:4 http://mirrors.aliyun.com stretch-updates/main Sources [3911 B]
....

Install apt package dependency

$ fun install --runtime python3 --package-type apt libzbar0
skip pulling image aliyunfc/runtime-python3.6:build-1.2.0...
Task => [UNNAMED]
=> apt-get update (if need)
=> apt-get install -y -d -o=dir::cache=/code/.fun/tmp libzbar0
=> bash -c 'for f in $(ls /code/.fun/tmp/archives/*.deb); do dpkg -x $f /code/.fun/root; done;'
=> bash -c 'rm -rf /code/.fun/tmp/archives'

Use fun.yml

runtime: python3
tasks:
- name: install libzbar0
apt: libzbar0
local: true
- name install Pillow by pip
pip: Pillow
local: true
- name: just test shell task
shell: echo '111' > 1.txt
Task => [UNNAMED]

apt/pip tasks

name: install libzbar0
apt: libzbar0
local: true
fun install --package-type apt libzbar0

shell tasks

name: install from source
shell: ./autogen.sh --disable-report-builder --disable-lpsolve --disable-coinmp

Examples

runtime: python3
tasks:
- apt: libzbar0
local: true
- pip: Pillow
local: true
- pip: pyzbar
local: true
$ fun install
skip pulling image aliyunfc/runtime-python3.6:build-1.2.0...
Task => [UNNAMED]
=> apt-get update (if need)
=> apt-get install -y -d -o=dir::cache=/code/.fun/tmp libzbar0
=> bash -c 'for f in $(ls /code/.fun/tmp/archives/*.deb); do dpkg -x $f /code/.fun/root; done;'
=> bash -c 'rm -rf /code/.fun/tmp/archives'
Task => [UNNAMED]
=> PYTHONUSERBASE=/code/.fun/python pip install --user Pillow
Task => [UNNAMED]
=> PYTHONUSERBASE=/code/.fun/python pip install --user pyzbar
ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
pyzbar-srv:
Type: 'Aliyun::Serverless::Service'
pyzbar-fun:
Type: 'Aliyun::Serverless::Function'
Properties:
Handler: index.handler
Runtime: python3
Timeout: 60
MemorySize: 128
CodeUri: .
from pyzbar.pyzbar import decode
from pyzbar.pyzbar import ZBarSymbol
from PIL import Image
def handler(event, context):
img = Image.open('./qrcode.png')
return decode(img, symbols=[ZBarSymbol.QRCODE])[0].data
fun local invoke pyzbar-fun
skip pulling image aliyunfc/runtime-python3.6:1.2.0...
Thalassiodracon
RequestId: 964980d1-1f1b-4f91-bfd8-eadd26a307b3 Billed Duration: 630 ms Memory Size: 1998 MB Max Memory Used: 32 MB

Summary

Original Source

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Samachar a news application using HMS Push Kit Client Side + Server Side (Part2)

Fastlane to Coroutines: Working with LiveData and Flow(Part II)

Learning Unity and C#

Why test environments should be single purpose (and how we did it at Flux)

How To Use Switch Statement in Azure Data Factory Pipeline

Azure Storage Explorer

A simpler, more reliable approach to high availability in the cloud

Server Side Swift & Concurrency: two sides of the same coin

100 Days of Code 2017 — Week 2 Recap

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

Historize elastic APM server data

kafkaVision: An open-source monitoring tool for Apache Kafka

Apache Kafka Deployments and Systems Reliability — Part 2

Manually Installing an ElasticSearch Cluster on GCP