Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go function project with packages fails to build with s2i builder #2522

Open
jrangelramos opened this issue Sep 26, 2024 · 0 comments
Open
Assignees

Comments

@jrangelramos
Copy link
Contributor

jrangelramos commented Sep 26, 2024

Go function project with packages fails to build with s2i builder, with error:

/tmp/src/.s2i/builds/last /tmp/src ~
go: f imports
	function/hello: package function/hello is not in std (/usr/lib/golang/src/function/hello)

Sample Go function project structure (full source code https://github.com/jrangelramos/gofuncpkg):

├── func.yaml
├── go.mod
├── handle.go
└── hello
    └── hello.go

handle.go

package function

import (
	"fmt"
	"function/hello"
	"net/http"
)

func Handle(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, hello.Hello("Jeff"))
}

hello/hello.go

package hello

func Hello(name string) string {
	return "Hello " + name
}

Building the above function with s2i fails as below:

func run -b s2i --build -v
Building function image
Step 1/9 : FROM registry.access.redhat.com/ubi8/go-toolset
latest: Pulling from ubi8/go-toolset
Digest: sha256:6626052118c5fa2f8ff7dcf80508f4347a6dc0f00ed67a4674ebaed427fff82a
Status: Image is up to date for registry.access.redhat.com/ubi8/go-toolset:latest
 ---> e60e55932f56
Step 2/9 : LABEL "io.openshift.s2i.build.source-location"="/tmp/gofuncpkg"       "io.k8s.display-name"="image-registry.openshift-image-registry.svc:5000/default/gofuncpkg:latest"       "io.openshift.s2i.build.image"="registry.access.redhat.com/ubi8/go-toolset"
 ---> Running in 66b3cda8f0b4
 ---> 647c848504c2
Step 3/9 : USER root
 ---> Running in 1d9352b3b087
 ---> b9fa15fef877
Step 4/9 : COPY upload/scripts /tmp/scripts
 ---> 7c4e466dd814
Step 5/9 : COPY upload/src /tmp/src
 ---> b8f869a5d7be
Step 6/9 : RUN chown -R 1001:0 /tmp/scripts /tmp/src
 ---> Running in 29442f581e96
 ---> 581baef44613
Step 7/9 : USER 1001
 ---> Running in db76e4ab6e7e
 ---> ceceb8e18ac8
Step 8/9 : RUN /tmp/scripts/assemble
 ---> Running in 4343ca78d928
/tmp/src ~
/tmp/src/.s2i/builds/last /tmp/src ~
go: f imports
	function/hello: package function/hello is not in std (/usr/lib/golang/src/function/hello)
Error: The command '/bin/sh -c /tmp/scripts/assemble' returned a non-zero code: 1

The function can be built and run properly using pack builder

[/tmp/gofuncpkg]$ func run -b pack --build   
Building function image
Still building
Still building
Yes, still building
🙌 Function built: image-registry.openshift-image-registry.svc:5000/default/gofuncpkg:latest
Running on host port 35151
Initializing HTTP function
listening on http port 8080
^Z
[/tmp/gofuncpkg]$ http :8080
HTTP/1.1 200 OK
Content-Length: 10
Content-Type: text/plain; charset=utf-8
Date: Thu, 26 Sep 2024 13:13:47 GMT

Hello Jeff

@lkingland lkingland self-assigned this Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants