#!/usr/bin/env bash # # Package the (already built) plugin binary into RPMs with nfpm. # Builds one RPM per target server: Vault (/opt/vault-plugins) and # OpenBao (/opt/openbao-plugins). Both wrap the same binary. # Usage: scripts/build-rpm.sh [version] (version defaults to $CI_COMMIT_TAG) # set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${ROOT_DIR}" VERSION="${1:-${CI_COMMIT_TAG:-0.0.0-dev}}" VERSION="${VERSION#v}" # strip a leading v BINARY="vault-plugin-secrets-arrstack" DIST="dist" if [ ! -f "${DIST}/${BINARY}" ]; then echo "ERROR: ${DIST}/${BINARY} not found; run 'make build' first" >&2 exit 1 fi # The plugin is registered in Vault/OpenBao by the sha256 of the binary, and # Puppet pins that same digest. Print it so the release log records it. SHA256="$(sha256sum "${DIST}/${BINARY}" | cut -d' ' -f1)" echo "PLUGIN_SHA256 ${BINARY} ${VERSION} ${SHA256}" # Fields shared across every flavour. export PACKAGE_VERSION="${VERSION}" export PACKAGE_RELEASE="1" export PACKAGE_ARCH="amd64" export PACKAGE_PLATFORM="linux" export PACKAGE_DESCRIPTION="Vault/OpenBao dynamic secrets engine for arrproxy machine tokens" export PACKAGE_MAINTAINER="Ben Vincent " export PACKAGE_HOMEPAGE="https://git.unkin.net/unkin/vault-plugin-secrets-arrstack" export PACKAGE_LICENSE="MIT" # build_flavor build_flavor() { export PACKAGE_NAME="$1" export PACKAGE_PLUGIN_DIR="$2" export PACKAGE_PREINSTALL="${DIST}/preinstall-${PACKAGE_NAME}.sh" envsubst '${PACKAGE_PLUGIN_DIR}' \ < packaging/scripts/preinstall.sh.tmpl > "${PACKAGE_PREINSTALL}" envsubst < packaging/nfpm.yaml > "${DIST}/nfpm-${PACKAGE_NAME}.yaml" nfpm pkg --config "${DIST}/nfpm-${PACKAGE_NAME}.yaml" --target "${DIST}" --packager rpm } build_flavor "vault-plugin-secrets-arrstack" "/opt/vault-plugins" build_flavor "openbao-plugin-secrets-arrstack" "/opt/openbao-plugins" echo "Built:" ls -1 "${DIST}"/*.rpm