A Funfile contains the commands that specify the steps to produce Function Compute deliverables such as the content that must be published after you develop, package, and compile a project. Funcraft runs the commands in the Funfile to produce the deliverables. This topic describes how to use a Funfile to install third-party dependencies.
Syntax supported by Funfiles
Funfiles support specific commands in Dockerfiles, such as the COPY, RUN, ENV, USER, and WORKDIR commands. To use a Funfile to install third-party dependencies, add fun-install
before the apt-get
and pip
commands in the Funfile.
You can use one of the following methods to run the
fun install
command to verify the syntax supported by a Funfile:
- Copy the following content to the Funfile. Then, Function Compute copies the package.json file in the function directory to perform subsequent operations.
RUNTIME nodejs8 COPY ./package.json . RUN npm install
- Use the following complex commands to install the rlang package in Function Compute:
RUNTIME python3RUN fun-install apt-get install libblas3 RUN fun-install pip install pandas RUN apt-get build-dep -y r-base; \ curl -L https://fc-demo-public.oss-cn-hangzhou.aliyuncs.com/fun/examples/R-3.5.2.tar.gz | tar -zxf -; \ cd R-3.5.2 ; \ ./configure --prefix=/code/.fun/R/ --enable-R-shlib --with-blas --with-lapack ; \ make ; \ make install; RUN PATH=/code/.fun/R/bin:$PATH LD_LIBRARY_PATH=/code/.fun/root/usr/lib/libblas:$LD_LIBRARY_PATH fun-install pip install rpy2 RUN rm -rf R-3.5.2; \ rm -rf .fun/root/usr/share; \ rm -rf .fun/R/share; \ rm -rf .fun/R/lib/R/doc; \ rm -rf .fun/python/lib/python3.6/site-packages/pandas/tests; \ rm -rf .fun/R/lib/R/library/*/{help,demo,html,doc}; \ find .fun -type f -name "*.so" -exec strip --strip-all {} \;
Advantages of Funfiles
- Standardized: The commands that are specified in a Funfile to install dependencies help standardize the development process.
- Convenient: You can submit a Funfile instead of specific dependencies to the version control system. This helps maintain function code.
- Native: Funfile commands are similar to native Dockerfile commands. You can test installation
commands in an interactive environment by using
fun install sbox
and then write the final installation commands in a Funfile as in a Dockerfile. - Efficient: Funfiles support the cache feature of Dockerfiles. If the changes in a project do not affect Funfiles, Function Compute can skip related commands in the Funfiles based on the cached data. This accelerates the execution of Funfiles and improves development efficiency.
Procedure
- Create a Funfile.
- Use the Funfile to install dependencies.