knative/func

Packaging func cli for openSUSE: How to make it properly report the version?

Closed this issue · 5 comments

Hi all,

I am trying to package the func CLI for the openSUSE linux distribution. The executable itself is working, however I cannot for the life of me figure out how to have it properly report the version.

As far as I put together from the Makefile and various other build scripts, the following invocation should do the trick. But all I get is v0.0.0+source when calling func version

These are the relevant parts of the spec file that is used to build the RPM package (where no network connectivity is present, hence all information must be provided beforehand).

%define knative_version knative-v1.13.0
[...]
VTAG="%{knative_version}"                                                                                                                                                                                                                                                                
# hash will be shortended by COMMIT_HASH:0:8 later                                                                                                                                                                                                                                       
COMMIT_HASH="$(awk '/^commit/ {print $2}' %_sourcedir/func.obsinfo)"                                                                                                                                                                                                                     
go generate pkg/functions/templates_embedded.go                                                                                                                                                                                                                                          
CGO_ENABLED=0 go build \                                                                                                                                                                                                                                                                 
   -mod=vendor \                                                                                                                                                                                                                                                                         
   -buildmode=pie \                                                                                                                                                                                                                                                                      
   -trimpath \                                                                                                                                                                                                                                                                           
   -ldflags=" \
   -X knative.dev/client/pkg/kn/commands/version.Version=v%{version} \                                                                                                                                                                                                                   
   -X knative.dev/client/pkg/kn/commands/version.GitRev=${COMMIT_HASH:0:8} \                                                                                                                                                                                                             
   -X knative.dev/client/pkg/kn/commands/version.BuildDate=${BUILD_DATE} \                                                                                                                                                                                                                                                                    
   -X knative.dev/func/pkg/app.vers=v%{version} \                                                                                                                                                                                                                                        
   -X knative.dev/func/pkg/app.kver=%{knative_version} \                                                                                                                                                                                                                                 
   -X knative.dev/func/pkg/app.hash=${COMMIT_HASH:0:8}" \                                                                                                                                                                                                                                
   -o bin/%{executable_name} ./cmd/func/

What am I missing?

Thanks in advance.

Kind Regards,
Johannes

Hello Jonannes,

Thank you for your issue. I tried the following (similar) command:
CGO_ENABLED=0 go build -buildmode=pie -trimpath -ldflags="-X knative.dev/func/pkg/app.vers=v1.2.3" ./cmd/func
And the resultant binary does report the version:

./func version
v1.2.3

Can you try running the same command, and ensure you're building the latest main? We very recently changed the target of those LDFLAG -X arguments, so that may be an issue if you're not on the latest main

Hi @lkingland
I just upgraded to 0.40.1, but the issue still persist. So it might just be that I am missing the latest changes from main.

Yes, if you are using the latest tagged version, the path of those ldflags is different than building from main, since it changed very recently. It looks like your settings will work if you update your main branch with the latest.

I am going to close this because it is clear that you're using the correct LDLFAGS for main, but not for the latest release (as they were recently changed). Please re-open this issue if the problem persists

For the record, with 0.41.0 aka 1.14.0 the LDFLAGS are working and the package reports back the versions properly:

kn-func version -v
Version: v0.41.0
Knative: v1.14.0
Commit: eebea9fc
SocatImage: ghcr.io/knative/func-utils:latest
TarImage: ghcr.io/knative/func-utils:latest

$ kn-func version
v0.41.0
%