This topic shows you how to run the fun build
command to build a code package for delivery based on the source code.
For more information about how to migrate Function Compute-related resources from Funcraft to Serverless Devs, see Migrate resources from Funcraft to Serverless Devs.
For more information about Serverless Devs, see What is Serverless Devs?.
For more information about how to use Serverless Devs to install dependencies, see Run the s build command to install dependencies.
We apologize for any inconvenience caused.
Background
The source code is not a deliverable. For example, after you write code in Java, you cannot directly upload the code. You must compile and package the code before you upload it. The package obtained after you compile and package the code is a deliverable. You can upload only one ZIP or JAR package to Function Compute. Therefore, you must compress the code deliverable and its dependencies into a JAR package and then deliver the package.
When you run the fun build
command to build a code package, Funcraft first searches for specific manifest files in the code directory of the function. Then, Funcraft builds code, downloads
dependencies, and compiles the code based on the manifest files.
- Funfile files of Funcraft for all programming languages. For more information, see Run the fun install command to install third-party dependencies
- pom.xml files of Apache Maven for Java
- package.json files of npm for Node.js
- requirements.txt files of pip for Python
- composer.json files of Composer for PHP.
Features of the fun build command
fun build
command: fun build -h
Expected output:Usage: fun build [options] [[service/]function]
Build the dependencies.
Options:
-d, --use-docker Use docker container to build functions
-t, --template [template] The path of fun template file.
-h, --help display help for command
Procedure
This section describes how to build a code package for delivery in Java 8.
Additional information
- Run the following command to build all the functions described in the template.yml file:
fun build
- Run the following command to build all the functions in a simulated on-premises Function
Compute environment:
fun build --use-docker
- Run the following command to build and invoke functions:
fun build && fun local invoke
- Run the following command to build and deploy functions:
fun build && fun deploy
Example
The following example shows you how to initialize, build, run, and modify Java code.