Giter Club home page Giter Club logo

hello-world's Introduction

Function project

Welcome to your new Function project!

This sample project contains a single function based on Spring Cloud Function: functions.CloudFunctionApplication.echo(), which returns an echo of the data passed via HTTP request.

Local execution

Make sure that Java 17 SDK is installed since Spring Boot 3.0 requires Java 17.

To start server locally run ./mvnw spring-boot:run. The command starts http server and automatically watches for changes of source code. If source code changes the change will be propagated to running server. It also opens debugging port 5005 so a debugger can be attached if needed.

To run tests locally run ./mvnw test.

The func CLI

It's recommended to set FUNC_REGISTRY environment variable.

# replace ~/.bashrc by your shell rc file
# replace docker.io/johndoe with your registry
export FUNC_REGISTRY=docker.io/johndoe
echo "export FUNC_REGISTRY=docker.io/johndoe" >> ~/.bashrc

Building

This command builds an OCI image for the function. By default, this will build a JVM image.

func build -v                  # build image

Note: If you want to enable the native build, you need to edit the func.yaml file and set the BP_NATIVE_IMAGE BuilderEnv variable to true:

buildEnvs:
  - name: BP_NATIVE_IMAGE
    value: "true"

Note: If you have issues with the Spring AOT processing in your build, you can turn this off by editing the func.yaml file and remove the -Pnative profile from the BP_MAVEN_BUILD_ARGUMENTS BuilderEnv variable:

buildEnvs:
  - name: BP_MAVEN_BUILD_ARGUMENTS
    value: -Pnative -Dmaven.test.skip=true --no-transfer-progress package

Removing the -Pnative profile means that you no longer will be able to build as a native image.

Running

This command runs the func locally in a container using the image created above.

func run

Deploying

This command will build and deploy the function into cluster.

func deploy -v # also triggers build

For ARM processor based systems

Building Spring Boot apps with Paketo Buildpacks on an ARM processor based system, like an Apple Macbook with an M1 or M2 chip, doesn't work well at the moment. To work around this you can build the image on your local system using Jib. Then, you would deploy the Jib generated image.

./mvnw compile com.google.cloud.tools:jib-maven-plugin:3.3.1:dockerBuild -Dimage=$FUNC_REGISTRY/echo
func deploy --build=false --image=$FUNC_REGISTRY/echo

Function invocation

For the examples below, please be sure to set the URL variable to the route of your function.

You get the route by following command.

func info

Note the value of Routes: from the output, set $URL to its value.

TIP:

If you use kn then you can set the url by:

# kn service describe <function name> and show route url
export URL=$(kn service describe $(basename $PWD) -ourl)

func

Using func invoke command with Path-Based routing:

func invoke --target "$URL/echo" --data "$(whoami)"

If your function class only contains one function, then you can leave out the target path:

func invoke --data "$(whoami)"

cURL

curl -v "$URL/echo" \
  -H "Content-Type:text/plain" \
  -w "\n" \
  -d "$(whoami)"

If your function class only contains one function, then you can leave out the target path:

curl -v "$URL" \
  -H "Content-Type:text/plain" \
  -w "\n" \
  -d "$(whoami)"

HTTPie

echo "$(whoami)" | http -v "$URL/echo"

If your function class only contains one function, then you can leave out the target path:

echo "$(whoami)" | http -v "$URL"

Cleanup

To clean the deployed function run:

func delete

hello-world

hello-world's People

Contributors

trisberg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.