samples icon indicating copy to clipboard operation
samples copied to clipboard

java-sample build failed due to network io timeout, can we do offline build?

Open zylan29 opened this issue 3 years ago • 3 comments

I am following the java-sample steps.

~ kubectl apply -f java-function-sample.yml

~ cat java-function-sample.yml
apiVersion: core.openfunction.io/v1beta1
kind: Function
metadata:
  name: java-sample
spec:
  version: "v1.0.0"
  image: "harbor.local/sample-java-func:latest"
  imageCredentials:
    name: harbor-secret
  port: 80 # default to 8080
  build:
    builder: "openfunction/gcp-builder:v1"
    env:
      GOOGLE_FUNCTION_TARGET: "com.openfunction.HelloWorld"
      GOOGLE_FUNCTION_SIGNATURE_TYPE: "http"
    srcRepo:
      url: "https://github.com/OpenFunction/samples.git"
      sourceSubPath: "functions/knative/hello-world-java"
      revision: "main"
  serving:
    runtime: knative # default to knative
    template:
      containers:
        - name: function
          imagePullPolicy: Always

The builder failed when step-create, the error log is following:

 ===> DETECTING
 4 of 5 buildpacks participating
 google.java.runtime             0.9.1
 google.java.maven               0.9.0
 google.java.functions-framework 1.0.1
 google.utils.label              0.0.1
 ===> ANALYZING
 Previous image with name "harbor.local/sample-java-func:latest" not found
 ===> RESTORING
 ===> BUILDING
 === Java - Runtime ([email protected]) ===
 Using latest Java 11 runtime version. You can specify a different version with GOOGLE_RUNTIME_VERSION: https://github.com/GoogleCloudPlatform/buildpacks#configuration
 Failure: (ID: 2ff5e9d8) getting status code for https://api.adoptopenjdk.net/v3/assets/feature_releases/11/ga?architecture=x64&heap_size=normal&image_type=jdk&jvm_impl=hotspot&os=linux&page=0&page_size=1&project=jdk&sort_order=DESC&vendor=adoptopenjdk: Head "https://api.adoptopenjdk.net/v3/assets/feature_releases/11/ga?architecture=x64&heap_size=normal&image_type=jdk&jvm_impl=hotspot&os=linux&page=0&page_size=1&project=jdk&sort_order=DESC&vendor=adoptopenjdk": dial tcp 104.17.158.60:443: i/o timeout
 --------------------------------------------------------------------------------
 Sorry your project couldn't be built.
 Our documentation explains ways to configure Buildpacks to better recognise your project:
  -> https://github.com/GoogleCloudPlatform/buildpacks/blob/main/README.md
 If you think you've found an issue, please report it:
  -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
 --------------------------------------------------------------------------------
 ERROR: failed to build: exit status 1

Since many production environments cannot access internet, can we build Function from source code without internet?

zylan29 avatar May 07 '22 13:05 zylan29

It looks like your cluster can't access this address: dial tcp 104.17.158.60:443: i/o timeout

The openfunction/gcp-builder:v1 is a builder provided by Google, and it may require your network to be unrestricted. So we are working on builders that can adapt to multiple network environments, including the Java builder (in progress)

The workaround is to configure a proxy for your cluster so that the builder can access api.adoptopenjdk.net

tpiperatgod avatar May 08 '22 02:05 tpiperatgod

Alternatively if your local network is good, you can build it in your local and push the image to your harbor.

  1. Install Docker and the pack tool.

  2. Build a container from your function using the Functions buildpacks:

pack build \
	--builder openfunction/gcp-builder:v1 \
	--env GOOGLE_FUNCTION_TARGET=com.openfunction.HelloWorld \
	--env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \
	my-java-sample

Deploy the serving-only function like this example.

lizzzcai avatar May 08 '22 02:05 lizzzcai

Alternatively if your local network is good, you can build it in your local and push the image to your harbor.

  1. Install Docker and the pack tool.
  2. Build a container from your function using the Functions buildpacks:
pack build \
	--builder openfunction/gcp-builder:v1 \
	--env GOOGLE_FUNCTION_TARGET=com.openfunction.HelloWorld \
	--env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \
	my-java-sample

Deploy the serving-only function like this example.

Thanks @lizzzcai , I'm going to add the pack build method to the official doc

benjaminhuo avatar May 08 '22 11:05 benjaminhuo