diff --git a/Makefile b/Makefile index 9620a60fbc..fae80d6d1e 100644 --- a/Makefile +++ b/Makefile @@ -115,6 +115,16 @@ docs-%: man: ./build/gen-man.sh man +###################################################### +# +# Linux distro package targets +# +###################################################### + +.PHONY: deb +deb: + VERSION=$(VERSION) ./build/gen-deb.sh + ###################################################### # # Wasm targets diff --git a/build/build-release.sh b/build/build-release.sh index add25069b1..9e3eda133b 100755 --- a/build/build-release.sh +++ b/build/build-release.sh @@ -46,6 +46,7 @@ build_release() { GOOS=linux GOARCH=amd64 make build GOOS=windows GOARCH=amd64 make build mv opa_windows_amd64 opa_windows_amd64.exe + build_distro_packages mv opa_*_* $OUTPUT_DIR } @@ -57,6 +58,17 @@ clone_repo() { fi } +build_distro_packages() { + if [ -f build/gen-deb.sh ]; then + make man + # If VERSION is not set, set it to `make version` + VERSION=${VERSION:-`make version`} make deb + mv opa_*.* $OUTPUT_DIR + else + echo "Skip building distro packages. Could not find gen-deb.sh." + fi +} + main() { clone_repo build_release diff --git a/build/gen-deb.sh b/build/gen-deb.sh new file mode 100755 index 0000000000..9a747c9b41 --- /dev/null +++ b/build/gen-deb.sh @@ -0,0 +1,63 @@ +set -e + +if [ ! -f "opa_linux_amd64" ]; then + echo "ERROR: File 'opa_linux_amd64' not found. First build it 'make build-linux'." + exit 1 +fi + +if [ ! -d "man" ]; then + echo "ERROR: The man pages not found. First build them 'make man'." + exit 1 +fi + +if [ -z "$VERSION" ]; then + echo "ERROR: Need to have VERSION environment variable set." + exit 1 +fi + +if ! command -v dpkg-deb >/dev/null 2>/dev/null; then + echo "ERROR: 'dpkg-deb' was not found and is required." + exit 1 +fi + +rm -rf tmp_working_dir_opa +mkdir tmp_working_dir_opa +cd tmp_working_dir_opa + +mkdir -p ./usr/bin/ +cp ../opa_linux_amd64 ./usr/bin/opa +chmod +x ./usr/bin/opa + +mkdir -p ./usr/share/man/man1/ +for MAN_PAGE in ../man/*.1; do + gzip --keep --best $MAN_PAGE +done +mv ../man/*.1.gz ./usr/share/man/man1/ + +echo "Package: opa" > control +echo "Version: $VERSION" >> control +cat << 'EOF' >> control +Architecture: amd64 +Maintainer: OPA Maintainers +Depends: libc6 (>= 2.2.5) +Section: admin +Priority: optional +Homepage: https://openpolicyagent.org +Description: An open source, general-purpose policy engine. + The Open Policy Agent (OPA) is an open source, general-purpose + policy engine that enables unified, context-aware policy + enforcement across the entire stack. +EOF + +md5sum ../opa_linux_amd64 > md5sums + +mkdir -p opa_$VERSION/DEBIAN +mv control opa_$VERSION/DEBIAN/control +mv md5sums opa_$VERSION/DEBIAN/md5sums +mv ./usr opa_$VERSION/usr + +dpkg-deb -b opa_$VERSION/ + +mv opa_$VERSION.deb ../ +cd .. +rm -rf tmp_working_dir_opa