Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 2.15 KB

README.md

File metadata and controls

46 lines (36 loc) · 2.15 KB

rules_nfpm example

This folder contains an example bazel WORKSPACE and BUILD setup that builds a small go binary and packages the binary into deb and rpm formats.

Usage

$ bazel build packages/...

$ rpm -qil -v ./bazel-bin/packages/helloworld.rpm
error: cannot open Packages database in /var/lib/rpm
error: cannot open Packages database in /var/lib/rpm
Name        : helloworld
Epoch       : 0
Version     : v1.2.3-develop
Release     : 1
Architecture: x86_64
Install Date: (not installed)
Group       : Development/Tools
Size        : 2169992
License     :
Signature   : (none)
Source RPM  : helloworld-v1.2.3-develop-1.src.rpm
Build Date  : Sat Jun 13 15:59:21 2020
Build Host  : 5989.lan
Relocations : (not relocatable)
Packager    :
Vendor      :
URL         :
Summary     : helloworld is a typical "hello, world" program.
Description :
helloworld is a typical "hello, world" program.

helloworld prints "hello, world" and then exits. This particular package was generated at
2020-06-13T19:59:21Z.

-r-xr-xr-x    1 root    root                  2169992 Jun 13 15:46 /usr/bin/helloworld

Internals

The directory's .bazelrc file configures the workspace-status.sh script to run on every bazel build invocation. The workspace status script produces "stable" and "volatile" key-value pairs that are useable later; the values are hardcoded for the purposes of this example, but could be dynamically computed via git commands.

packages/BUILD.bazel configures two targets, helloworld.rpm and helloworld.deb. Each depend on the //cmd/helloworld target, which is a small go binary.

The package targets use packages/helloworld.yaml as a template to configure NFPM. The actual configuration is generated by the go template package, where . is a ConfigTemplateData struct.