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

Add generation of apiserver-builder executables, .deb and .rpm packages in . #150

Merged

Conversation

metmajer
Copy link
Contributor

This PR creates apiserver-builder executables for darwin-amd64, linux-amd64 and windows-amd64 in build/ via make build:

metmajer$ tree build/
build/
├── darwin-amd64
│   └── bin
│       ├── apiregister-gen
│       ├── apiserver-boot
│       └── apiserver-builder-release
├── linux-amd64
│   └── bin
│       ├── apiregister-gen
│       ├── apiserver-boot
│       └── apiserver-builder-release
└── windows-amd64
    └── bin
        ├── apiregister-gen.exe
        ├── apiserver-boot.exe
        └── apiserver-builder-release.exe

Additionally, it enables the creation of .deb and .rpm packages using jordansissel/fpm in build/ via make packages:

metmajer$ tree build/
build/
└── linux-amd64
    └── pkg
        ├── apiserver-builder_0.1-alpha.14_amd64.deb
        └── apiserver-builder_0.1-alpha.14_amd64.rpm

The version number is now stored in VERSION for better version management.

Debian Package

Information

ubuntu@ubuntu-xenial$ dpkg-deb -I apiserver-builder_0.1-alpha.14_amd64.deb
 new debian package, version 2.0.
 size 5705424 bytes: control archive=579 bytes.
     422 bytes,    11 lines      control
     292 bytes,     4 lines      md5sums
 Package: apiserver-builder
 Version: 0.1-alpha.14
 License: Apache-2.0
 Vendor: kubernetes-incubator
 Architecture: amd64
 Maintainer: The Kubernetes Authors
 Installed-Size: 17381
 Section: default
 Priority: extra
 Homepage: https://github.com/kubernetes-incubator/apiserver-builder
 Description: apiserver-builder implements libraries and tools to quickly and easily build Kubernetes apiservers to support custom resource types.

Installation

Users can install the .deb package either using dpkg -i $name.deb or apt-get install -f $name.deb or apt install $name.deb.

ubuntu@ubuntu-xenial$ sudo dpkg -i apiserver-builder_0.1-alpha.14_amd64.deb
Selecting previously unselected package apiserver-builder.
(Reading database ... 53918 files and directories currently installed.)
Preparing to unpack apiserver-builder_0.1-alpha.14_amd64.deb ...
Unpacking apiserver-builder (0.1-alpha.14) ...
Setting up apiserver-builder (0.1-alpha.14) ...
ubuntu@ubuntu-xenial$ ls -la /usr/local/bin/
total 17396
drwxr-xr-x  2 root root    4096 Sep 15 18:31 .
drwxr-xr-x 10 root root    4096 Sep 15 18:31 ..
-rwxr-xr-x  1 root root 7894084 Sep 15 18:30 apiregister-gen
-rwxr-xr-x  1 root root 5598073 Sep 15 18:30 apiserver-boot
-rwxr-xr-x  1 root root 4306566 Sep 15 18:30 apiserver-builder-release
ubuntu@ubuntu-xenial$ file /usr/local/bin/apiregister-gen
/usr/local/bin/apiregister-gen: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

RPM Package

Information

vagrant@fedora$ rpm -qip apiserver-builder_0.1-alpha.14_amd64.rpm
warning: ./apiserver-builder_0.1-alpha.14_amd64.rpm: Header V4 RSA/SHA1 Signature, key ID c1cbfc12: NOKEY
Name        : apiserver-builder
Version     : 0.1_alpha.14
Release     : 1
Architecture: x86_64
Install Date: (not installed)
Group       : default
Size        : 17798723
License     : Apache-2.0
Signature   : RSA/SHA1, Fri 15 Sep 2017 06:38:50 PM UTC, Key ID b8495724c1cbfc12
Source RPM  : apiserver-builder-0.1_alpha.14-1.src.rpm
Build Date  : Fri 15 Sep 2017 06:38:50 PM UTC
Build Host  : martins-macbook-pro.local
Relocations : /
Packager    : The Kubernetes Authors
Vendor      : kubernetes-incubator
URL         : https://github.com/kubernetes-incubator/apiserver-builder
Summary     : apiserver-builder implements libraries and tools to quickly and easily build Kubernetes apiservers to support custom resource types.
Description :
apiserver-builder implements libraries and tools to quickly and easily build Kubernetes apiservers to support custom resource types.
vagrant@fedora$ rpm -ihv apiserver-builder_0.1-alpha.14_amd64.rpm
warning: apiserver-builder_0.1-alpha.14_amd64.rpm: Header V4 RSA/SHA1 Signature, key ID 8f0e18b6: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:apiserver-builder-0.1_alpha.14-1 ################################# [100%]
vagrant@fedora$ ls -la /usr/local/bin/
total 17216
drwxr-xr-x.  3 root root    4096 Sep 15 20:20 .
drwxr-xr-x. 12 root root    4096 Nov 15  2016 ..
-rwxr-xr-x.  1 root root 7888579 Sep 15 20:18 apiregister-gen
-rwxr-xr-x.  1 root root 5530494 Sep 15 20:18 apiserver-boot
-rwxr-xr-x.  1 root root 4197066 Sep 15 20:18 apiserver-builder-release

With that, .deb and .rpm packages can now be attached to a release on GitHub. If you like, I can also include the generation of source and binary .tar.gz distributables.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 16, 2017
@metmajer
Copy link
Contributor Author

@pwittrock I'll have a look at your suggestions in #148.

@metmajer metmajer changed the title Add generation of apiserver-builder executables, .deb and .rpm packages in build/. [WIP] Add generation of apiserver-builder executables, .deb and .rpm packages in build/. Sep 16, 2017
@metmajer
Copy link
Contributor Author

@pwittrock following your suggestion, I now use the following commands to build a release.

.PHONY: build
build: clean
	go run ./cmd/apiserver-builder-release/main.go vendor --version $(VERSION)
	go run ./cmd/apiserver-builder-release/main.go build --version $(VERSION)

I am getting the following error message from the apiserver-builder-release vendor command for which I don't have an explanation. Can you please advise?

metmajer$ go run ./cmd/apiserver-builder-release/main.go vendor --version 1.0
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/gen-apidocs vendor/github.com/kubernetes-incubator/reference-docs/gen-apidocs/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/client-gen vendor/k8s.io/kubernetes/cmd/libs/go2idl/client-gen/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/conversion-gen vendor/k8s.io/kubernetes/cmd/libs/go2idl/conversion-gen/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/deepcopy-gen vendor/k8s.io/kubernetes/cmd/libs/go2idl/deepcopy-gen/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/defaulter-gen vendor/k8s.io/kubernetes/cmd/libs/go2idl/defaulter-gen/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/informer-gen vendor/k8s.io/kubernetes/cmd/libs/go2idl/informer-gen/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/lister-gen vendor/k8s.io/kubernetes/cmd/libs/go2idl/lister-gen/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/openapi-gen vendor/k8s.io/kubernetes/cmd/libs/go2idl/openapi-gen/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/apiregister-gen cmd/apiregister-gen/main.go
go build -o /Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/apiserver-boot cmd/apiserver-boot/main.go
to rerun with cached glide use `--vendordir /private/var/folders/nv/wcjs75q94kn8y46_dxmzc3zm0000gn/T/apiserver-builder-release658317748`
/Users/metmajer/go/src/github.com/kubernetes-incubator/apiserver-builder/release/1.0/bin/apiserver-boot init repo --domain k8s.io --install-deps=false
2017/09/16 11:40:33 apiserver-boot must be run from the directory containing the go package to bootstrap. This must be under $GOPATH/src/<package>.
Current GOPATH=/Users/metmajer/go.
Current directory=/private/var/folders/nv/wcjs75q94kn8y46_dxmzc3zm0000gn/T/apiserver-builder-release658317748/src/github.com/kubernetes-incubator/test
2017/09/16 11:40:33 exit status 1
exit status 1

I executed the command from the repository's root directory and I also don't see any notable difference in build-tools.sh.

Makefile Outdated
.PHONY: build-apiregister-gen-linux-amd64 build-apiserver-boot-linux-amd64 build-apiserver-builder-release-linux-amd64
build-apiregister-gen-linux-amd64 build-apiserver-boot-linux-amd64 build-apiserver-builder-release-linux-amd64: build-%-linux-amd64:
mkdir -p $(LINUX_AMD64_BUILD_BIN_DIR)
GOOS=linux GOARCH=amd64 go build -o $(LINUX_AMD64_BUILD_BIN_DIR)/$* ./cmd/$*/main.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to do something more than this. The tar release contains builds of the vendored code-generators + the vendored go packages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the artifacts in the .tar.gz published in the release and the release cmd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood (see the comment above). The idea is then to run apiserver-builder-release to build a .tar.gz and use this to create the packages. Do you have any idea why apiserver-boot fails when I run apiserver-builder-release (again, see the comment above).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. That is weird, the release command should set the GOPATH. Looking that the code, it looks like it might be just appending the GOPATH. Perhaps if your GOPATH is already set, it won't override it. What OS are you running this on? I have only run it from a Mac.

I am going to try a fix by removing the existing GOPATH env from the exec'ed command environment if it is preset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am running this on a Mac with a GOPATH set. Since you're already on it, I won't open an issue for it then. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that is odd. What shell are you using? I made some changes so it will prune the GOPATH from the environment when execing. Try running again now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your may revert your change to GOPATH handling. The error was due to glide being missing.

@pwittrock
Copy link
Contributor

Thanks @metmajer. I will be traveling for the next, so may be less responsive than typical, but will try to be available.

@metmajer
Copy link
Contributor Author

metmajer commented Sep 22, 2017

I've changed the implementation to create build artefacts using apiserver-builder-release in . via make build as suggested. make package creates the following packages, too in ., where $VERSION is defined in the VERSION file:

apiserver-builder-$VERSION-amd64.deb
apiserver-builder-$VERSION-amd64.rpm

Installing these packages will make binaries end up in /usr/local/bin:

$ sudo rpm -ihv apiserver-builder-0.1-alpha.14-amd64.rpm
warning: apiserver-builder-0.1-alpha.14-amd64.rpm: Header V4 RSA/SHA1 Signature, key ID b018000d: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:apiserver-builder-0.1_alpha.14-1 ################################# [100%]

$ ls -la /usr/local/bin/
total 92212
drwxr-xr-x.  2 root root     4096 Sep 22 20:23 .
drwxr-xr-x. 12 root root     4096 Nov 15  2016 ..
-r-xr-xr-x.  1 root root  7888904 Sep 22 20:21 apiregister-gen
-r-xr-xr-x.  1 root root  5584848 Sep 22 20:21 apiserver-boot
-r-xr-xr-x.  1 root root  7145656 Sep 22 20:21 client-gen
-r-xr-xr-x.  1 root root  6875640 Sep 22 20:21 conversion-gen
-r-xr-xr-x.  1 root root  6831448 Sep 22 20:21 deepcopy-gen
-r-xr-xr-x.  1 root root  6805576 Sep 22 20:21 defaulter-gen
-r-xr-xr-x.  1 root root 10204052 Sep 22 20:21 gen-apidocs
-r-xr-xr-x.  1 root root 16857973 Sep 22 20:21 glide.tar.gz
-r-xr-xr-x.  1 root root  6948712 Sep 22 20:21 informer-gen
-r-xr-xr-x.  1 root root  6763736 Sep 22 20:21 lister-gen
-r-xr-xr-x.  1 root root 12485788 Sep 22 20:21 openapi-gen

@metmajer
Copy link
Contributor Author

The .tar.gz archives store binaries in a ./bin directory inside the archive. Is there a reason why this directory is contained? If there's no particular reason, I'd suggest to have the files stores at . instead.

@metmajer metmajer changed the title [WIP] Add generation of apiserver-builder executables, .deb and .rpm packages in build/. [WIP] Add generation of apiserver-builder executables, .deb and .rpm packages in . Sep 23, 2017
@pwittrock
Copy link
Contributor

@metmajer I don't think there is a particular reason. I was copying how the go installation is structured /usr/local/go/bin => /usr/local/apiserver-builder/bin. Where do you think the binaries should be installed? We could instead just do /usr/local/apiserver-builder. Since there are multiple binaries contained in the distribution, I am not sure we want just /usr/local/bin.

@pwittrock
Copy link
Contributor

I am open to anything though.

@metmajer
Copy link
Contributor Author

@pwittrock Installing them into /usr/local/go/bin or /usr/local/apiserver-builder/bin both make sense. If you'd like to have the executables available in the user's PATH, then /usr/local/go/bin or /usr/local/bin would be favorable. Please decide.

Appreciate your thoughts. Having the bin folder structure in the archive make now makes more sense to me.

@pwittrock
Copy link
Contributor

@metmajer hm, I am starting to lean toward the tar containing a folder called apiserver-builder/ will all the binaries, and suggest users install it under /usr/local/. e.g. /usr/local/apiserver-builder/apiserver-boot. Then users would need to add /usr/local/apiserver-builder to their PATH. I think having the user add this to their path is reasonable and provides a better experience. It is consistent with how many other programs are installed (such as how go is installed).


.PHONY: build
build: clean ## Create release artefacts for darwin:amd64, linux:amd64 and windows:amd64. Requires etcd, glide, hg.
go run ./cmd/apiserver-builder-release/main.go vendor --version $(VERSION)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preferred format of this command is to pass it a --commit flag to make sure it pulls down the apiserver-builder at the intended versions (and not whatever glide has cached)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain how we could make use of --commit here? Which version would be expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR
The most recent commit hash from the apiserver-buidler repo

The release command doesn't use the local src for building the glide.tar.gz with the vendored go code for apiserver-builder++. Instead it uses apiserver-boot (built from the local code) to start a new project, and run glide to download all of the godeps to vendor. The commit here is put in the glide.yaml file to pin the apiserver-builder vendored go libraries. This ensures that the correct version of the libraries are vendored, instead of whatever glide decides it wants to fetch (can depend on the local cache).

@pwittrock pwittrock merged commit 769b029 into kubernetes-sigs:master Sep 23, 2017
@pwittrock
Copy link
Contributor

@metmajer Looks good. I will follow up on changing the release script to put the binaries in a folder called apiserver-builder so it gets installed in the right place.

@metmajer metmajer changed the title [WIP] Add generation of apiserver-builder executables, .deb and .rpm packages in . Add generation of apiserver-builder executables, .deb and .rpm packages in . Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants