Preface
Firstly, several important concepts emerged in this paper are introduced.
Function Compute: Function Compute is an event-driven service. Through function computing, users do not need to manage the operation of servers, etc. They only need to write code and upload it. Function computing prepares computing resources and runs user code in a flexible and scalable manner, while users only need to pay for the resources consumed by running the actual code. Function calculation for more information.
Funcraft: Funcraft is a tool to support the deployment of Serverless applications. It can help you easily manage functions computing, API gateways, log services and other resources. It assists you in developing, building and deploying operations through a resource configuration file (template.yml). More documentation for Funcraft.
LibreOffice: LibreOffice is a free and open source office suite developed by the Document Foundation. The Library Office suite includes word processors, spreadsheets, presentation programs, vector graphics editors and graphics tools, database management programs, and applications for creating and editing mathematical formulas. See Wikipedia entry
Note: The techniques described in this article require the Funcraft version to be greater than or equal to 3.0.0-beta.7.
Dependency tool
This project is developed under MacOS, and the tools involved are platform independent. It should also be applicable to Linux and Windows desktop systems. Before starting this example, make sure that the following tools are installed correctly, updated to the latest version, and configured correctly.
- Docker
- Funcraft
Fun tools rely on docker to simulate local environments.
For MacOS users, homebrew can be used to install:
brew cask install docker brew tap vangie/formula brew install fun
For Windows and Linux user installations, please refer to:
- https://github.com/aliyun/fun/blob/master/docs/usage/installation.md
Once installed, remember to perform fun config to initialize the configuration first.
Note that if you have installed funcraft, make sure that the version of funcraft is above 3.0.0-beta.7.
$ fun --version 3.0.0-beta.7
Initialization
Using the fun init command, you can quickly initialize this template project to local.
$ fun init vangie/libreoffice-example
Installation dependency
$ fun install Installing recursively on fun.yml skip pulling image aliyunfc/runtime-nodejs8:build-1.6.1... Task => [UNNAMED] => apt-get update (if need) => apt-get install -y -d -o=dir::cache=/code/.fun/tmp/install libnss3 --reinstall => bash -c for f in $(ls /code/.fun/tmp/install/archives/*.deb); do dpkg -x $f /code/.fun/root; mkdir -p /code/.fun/tmp/install/deb-control/${f%.*}; dpkg -e $f /code/.fun/tmp/install/deb-control/${f%.*}; if [ -f "/code/.fun/tmp/install/deb-control/${f%.*}/postinst" ]; then FUN_INSTALL_LOCAL=true /code/.fun/tmp/install/deb-control/${f%.*}/postinst configure; fi; done; => bash -c 'rm -rf /code/.fun/tmp/install/archives' Task => [UNNAMED] => bash -c 'npm install --production && mkdir -p .fun/nas/auto-default/libreoffice/ && mv ./node_modules/fc-libreoffice/bin/lo.tar.br .fun/nas/auto-default/libreoffice/' info looking for cached prebuild @ /root/.npm/_prebuilds/95f620-iltorb-v2.4.3-node-v57-linux-x64.tar.gz http request GET https://github.com/MayhemYDG/iltorb/releases/download/v2.4.3/iltorb-v2.4.3-node-v57-linux-x64.tar.gz http 200 https://github.com/MayhemYDG/iltorb/releases/download/v2.4.3/iltorb-v2.4.3-node-v57-linux-x64.tar.gz info downloading to @ /root/.npm/_prebuilds/95f620-iltorb-v2.4.3-node-v57-linux-x64.tar.gz.152-11c561798275d.tmp info renaming to @ /root/.npm/_prebuilds/95f620-iltorb-v2.4.3-node-v57-linux-x64.tar.gz info unpacking @ /root/.npm/_prebuilds/95f620-iltorb-v2.4.3-node-v57-linux-x64.tar.gz info unpack resolved to /code/node_modules/iltorb/build/bindings/iltorb.node info unpack required /code/node_modules/iltorb/build/bindings/iltorb.node successfully info install Successfully installed iltorb binary! npm WARN libreoffice-example@1.0.0 No description npm WARN libreoffice-example@1.0.0 No repository field.
deploy
$ fun deploy using template: template.yml using region: cn-shanghai using accountId: ***********4733 using accessKeyId: ***********EUz3 using timeout: 60 Waiting for service libreoffice to be deployed... make sure role 'aliyunfcgeneratedrole-cn-shanghai-libreoffice' is exist role 'aliyunfcgeneratedrole-cn-shanghai-libreoffice' is already exist attaching police 'AliyunECSNetworkInterfaceManagementAccess' to role: aliyunfcgeneratedrole-cn-shanghai-libreoffice attached police 'AliyunECSNetworkInterfaceManagementAccess' to role: aliyunfcgeneratedrole-cn-shanghai-libreoffice using 'VpcConfig: Auto', Fun will try to generate related vpc resources automatically vpc already generated, vpcId is: vpc-uf6jphcirs45lekbtw59k vswitch already generated, vswitchId is: vsw-uf6gmxg7cyl3dlohlck9p security group already generated, security group is: sg-uf6hkd156qntmzxr51h3 generated auto VpcConfig done: {"vpcId":"vpc-uf6jphcirs45lekbtw59k","vswitchIds":["vsw-uf6gmxg7cyl3dlohlck9p"],"securityGroupId":"sg-uf6hkd156qntmzxr51h3"} using 'NasConfig: Auto', Fun will try to generate related nas file system automatically nas file system already generated, fileSystemId is: 3f95748ba7 nas file system mount target is already created, mountTargetDomain is: 3f95748ba7-ips53.cn-shanghai.nas.aliyuncs.com generated auto NasConfig done: {"UserId":10003,"GroupId":10003,"MountPoints":[{"ServerAddr":"3f95748ba7-ips53.cn-shanghai.nas.aliyuncs.com:/libreoffice","MountDir":"/mnt/auto"}]} Checking if nas directories /libreoffice exists, if not, it will be created automatically Checking nas directories done ["/libreoffice"] Waiting for function word2pdf to be deployed... Waiting for packaging function word2pdf code... The function word2pdf has been packaged. A total of 1019 files files were compressed and the final size was 6.36 MB function word2pdf deploy success service libreoffice deploy success
implement
$ fun invoke word2pdf using template: template.yml ========= FC invoke Logs begin ========= FC Invoke Start RequestId: 20e7c0e4-d674-4be0-854f-bd876dc00043 load code for handler:index.handler Error: source file could not be loaded 2019-09-17T13:57:35.716Z 20e7c0e4-d674-4be0-854f-bd876dc00043 [verbose] convert success. FC Invoke End RequestId: 20e7c0e4-d674-4be0-854f-bd876dc00043 Duration: 4741.22 ms, Billed Duration: 4800 ms, Memory Size: 640 MB, Max Memory Used: 578.54 MB ========= FC invoke Logs end ========= FC Invoke Result: pdf save to /tmp/example.pdf
PDF files are written to the / tmp directory. If you want to see the results, you can upload the files to OSS and download them from OSS.
Reference reading
- Five Minutes Online-Function Computing Word to PDF Cloud Service
- https://github.com/awesome-fc/fc-libreoffice
- Template project
This article is the original content of Yunqi Community, which can not be reproduced without permission.