Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install dependencies in interactive mode under MacOS

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

How to install dependencies in interactive mode under MacOS? I believe that most people have not yet learned this skill, in order to let you learn, to give you a summary of the following content, do not say much, let's move on.

Rely on the tool DockerFun

The Fun and Fcli tools rely on docker to simulate the local environment.

For MacOS users, you can use homebrew to install:

Brew cask install dockerbrew tap vangie/formulabrew install fun

For Windows and Linux user installation, please refer to:

After installation, remember to initialize the configuration by executing fun config first.

Note that if you have already installed fun, make sure that the version of fun is above 3.0.0-beta.1.

$fun-version3.0.0-beta.1 background

The function evaluates to the Zip zip file format as the agreed deliverable, which usually contains code and dependent library files. These dependent library files are usually divided into system dependencies (libraries installed using apt-get packages) and language runtime dependencies (using language-dependent package managers such as npm, pip installed libraries).

System dependencies are usually not portable

Usually, the system depends on the environment. For example, we want to call the brotli command in the function to extract the file. If we install the brotil command using brew install brotli on the development machine mac, and then package and publish it to the function computing platform, it will not work. Sometimes even if the development machine is linux, it may not be possible. This is because the executable programs and dynamic link libraries installed through the package management tools provided by the system are strongly related to the type and version of the system. These programs and files installed on different systems are not portable.

There are also cases where language dependency is not portable.

In general, language dependencies are platform-independent, such as installing a nodejs dependency using npm install jszip, which can run on different operating systems and different nodejs versions. Dependencies on language platforms are usually portable, with exceptions. For example, npm install node-pty is an example of a native binding (native binding). During the installation of the node-pty module, we rely on some cAccord code, which will be compiled during installation. We know that although the code is platform portable, the compiled product is not portable.

The deficiency of DSL script

Fun version 2.0 supports dependent installation of DSL files fun.yml,fun.yml provides batch mode for dependent installations. Daily development provides a command mode, such as fun install-- package-type pip tensorflow. In Fun 3.0, we provide a new DSL file, Funfile. Funfile can be understood as a subset of the syntax of Dockerfile, allowing developers familiar with docker to get started quickly.

But both fun.yml and Funfile, as well as command mode, have a pain point for developers. That is not knowing the current state of the environment:

What are the contents and properties of the files in a certain directory of the installed software?

Developers need a sandbox environment that can interact with each other. This feature is not available in Fun 2.0, and users often use the fcli sbox command instead, or launch a container directly using the image provided by the fc-docker project. Docker run-- rm-it-v $(pwd): / code aliyunfc/runtime-python2.7:build bash but these complex commands and parameters require the user to have sufficient background knowledge of docker and knowledge of how function computation works.

In order to better solve the above problems and improve the user's development experience, we provide the fun install sbox subcommand in Fun 3.0.

Command line parameter $fun install sbox-- helpUsage: fun install sbox [- f |-- function] [- r |-- runtime] [- I |-- interactive] [- e |-- env key=val.] [- e |-- cmd] Start a local sandbox for installation dependencies or configurationOptions:-f,-- function Specify which function to execute installation task. R,-- runtime function runtime, avaliable choice is: nodejs6, nodejs8, nodejs10, python2.7, python3, java8, php7.2, custom-I,-- interactive run as interactive mode. Keep STDIN open and allocate a pseudo-TTY when in an interactive shell. (default: false)-e,-env environment variable, ex. -e PATH=/code/bin (default: [])-c,-- cmd command with arguments to execute inside the installation sandbox. -h,-- help output usage information start quickly

Let's take the project pyzbar_example as an example. The pyzbar_example project contains the following files

$tree.. ├── fun.yml ├── index.py ├── qrcode.png └── template.yml0 directories, 4 files

The content of template.yml file is as follows

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:. Start the interactive mode sbox$ fun install sbox-f pyzbar-fun-iusing template: template.ymlroot@fc-python3:/code# lsfun.yml index.py qrcode.png template.ymlroot@fc-python3:/code# exitexit$

Execute fun install sbox in the project directory where template.yml is located, where the parameters

The-f/--function parameter specifies the function to start sbox. In this example, the runtime set by the function is python3, so the sandbox environment of the python3 environment will be started, and the CodeUri directory corresponding to the function pyzbar-fun will be mounted to the / code directory inside the sandbox environment. This is confirmed by the list of files returned by the ls command in the sandbox environment in the above example. The-i/--interactive parameter means to start the interactive mode. For the purpose of the non-interactive mode, please see the following example.

If the template.yml file does not exist, or if the function in the template.yml configuration file has not been configured, you can start the interactive mode with the-- runtime parameter, and the current directory will be mounted to the / code directory of the sandboxed environment.

$fun install sbox-r nodejs10-iroot@fc-nodejs10:/code# lsfun.yml index.py qrcode.png template.ymlroot@fc-nodejs10:/code# exitexit$

The above method is suitable for temporarily starting a sbox to do some hands-on experiments.

Use fun-install to install apt and pip dependencies $fun install sbox-f pyzbar-fun-iusing template: template.ymlroot@fc-python3:/code# fun-install apt-get install libblas3Task = > [UNNAMED] = > apt-get update (if need) = > apt-get install-y-d-o=dir::cache=/code/.fun/tmp libblas3 = > bash-c for f in $(ls / code/.fun/tmp/archives/*.deb); do dpkg-x $f / code/.fun/root Mkdir-p / code/.fun/tmp/deb-control/$ {f% .*}; dpkg-e $f / code/.fun/tmp/deb-control/$ {f% .*}; if [- f "/ code/.fun/tmp/deb-control/$ {f% .*} / postinst"]; then FUN_INSTALL_LOCAL=true / code/.fun/tmp/deb-control/$ {f% .*} / postinst configure Fi; done; = > bash-c'rm-rf / code/.fun/tmp/archives'root@fc-python3:/code# fun-install-- helpUsage: fun local [options] [command] build function codes or install related depedencies for Function ComputeOptions:-h,-help output usage informationCommands: apt-get install apt depencies pip install pip depencies build build function codes for Function Compute help [cmd] display help for [cmd] use sbox in non-interactive mode

Print out the pre-installed deb package in the sbox of the pyzbar-fun function using the following one-line command.

$fun install sbox-f pyzbar-fun-c 'dpkg-l'using template: template.ymlDesired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend | / Err?= (none) / Reinst-required (Status) Err: uppercase=bad) | | / Name Version Architecture Description+++-==-==-=-====ii acl 2.2.52-2 amd64 Access control list utilitiesii adduser 3.113+nmu3 all Add and remove users and groupsii apt 1.0.9.8.4 amd64 commandline package managerii apt-utils 1.0.9.8.5 amd64 package management related utility programsii autoconf 2.69-8 All automatic configure script builderii automake 1purl 1.14.1-4+deb8u1 all Tool for generating GNU Standards-compliant Makefiles... (many lines have been omitted here)

You can also pass the contents of external commands to the inside through pipes.

$echo hello | fun install sbox-r nodejs10-I-c 'cat -' hello

Note that the-I parameter cannot be omitted here, which means that standard input is accepted.

Summary

Fun install sbox is an alternative tool for fcli sbox. In addition to supporting interactive mode, it not only uses the specified runtime to start sbox, but also implements the fun-style specified function to start sbox, which is more convenient. At the same time, it also supports the use of non-interactive modes such as inline commands and pipes, which provides better support for scripting.

These are the details of installing dependencies in interactive mode, and the code examples are simple and straightforward, if you encounter this problem in your daily work. Through this article, I hope you can get something. For more details, please follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report