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

Implementing an Operating System #2

Android’s New Dessert: Android Q

Optimizing Jenkins shared library loading on controllers

What engineers can learn from dancing

Mixin and treats

8 Effective Ways to Boost Your Child’s Financial IQ

I wrote an automated trading bot within 3 months, here is how you can do it too

How Does Alibaba Implement CI/CD Based on Kubernetes

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

How to Analysis or Audit your Elasticsearch Requests #

Using Search Template — ElasticSearch

ELK Enhanced Search Operations | Part6

How we migrated from RDS MySql to RDS Aurora and stopped suffering from lags