|
| 1 | +PACKAGE_TYPES ?= deb rpm |
| 2 | +PROJECT_NAME = nri-$(INTEGRATION) |
| 3 | +BINS_DIR = $(TARGET_DIR)/bin/linux_amd64 |
| 4 | +SOURCE_DIR = $(TARGET_DIR)/source |
| 5 | +PACKAGES_DIR = $(TARGET_DIR)/packages |
| 6 | +VERSION ?= 0.0.0 |
| 7 | +RELEASE ?= dev |
| 8 | +LICENSE = "https://newrelic.com/terms (also see LICENSE.txt installed with this package)" |
| 9 | +VENDOR = "New Relic, Inc." |
| 10 | +PACKAGER = "New Relic Infrastructure Team <infrastructure-eng@newrelic.com>" |
| 11 | +PACKAGE_URL = "https://www.newrelic.com/infrastructure" |
| 12 | +SUMMARY = "New Relic Infrastructure $(INTEGRATION) Integrations" |
| 13 | +DESCRIPTION = "New Relic Infrastructure $(INTEGRATION) Integrations extend the core New Relic\nInfrastructure agent's capabilities to allow you to collect metric and\nlive state data from your infrastructure $(INTEGRATION) components." |
| 14 | +FPM_COMMON_OPTIONS = --verbose -C $(SOURCE_DIR) -s dir -n $(PROJECT_NAME) -v $(VERSION) --iteration $(RELEASE) --prefix "" --license $(LICENSE) --vendor $(VENDOR) -m $(PACKAGER) --url $(PACKAGE_URL) --config-files /etc/newrelic-infra/ --description "$$(printf $(DESCRIPTION))" --depends "newrelic-infra >= 1.0.726" |
| 15 | +FPM_DEB_OPTIONS = -t deb -p $(PACKAGES_DIR)/deb/ |
| 16 | +FPM_RPM_OPTIONS = -t rpm -p $(PACKAGES_DIR)/rpm/ --epoch 0 --rpm-summary $(SUMMARY) |
| 17 | + |
| 18 | +package: create-bins prep-pkg-env $(PACKAGE_TYPES) |
| 19 | + |
| 20 | +create-bins: |
| 21 | + echo "=== Main === [ create-bins ]: creating binary ..." |
| 22 | + go build -v -ldflags '-X main.buildVersion=$(VERSION)' -o $(BINS_DIR)/$(BINARY_NAME) $(GO_FILES) || exit 1 |
| 23 | + @echo "" |
| 24 | + |
| 25 | +prep-pkg-env: |
| 26 | + @if [ ! -d $(BINS_DIR) ]; then \ |
| 27 | + echo "=== Main === [ prep-pkg-env ]: no built binaries found. Run 'make create-bins'" ;\ |
| 28 | + exit 1 ;\ |
| 29 | + fi |
| 30 | + @echo "=== Main === [ prep-pkg-env ]: preparing a clean packaging environment..." |
| 31 | + @rm -rf $(SOURCE_DIR) |
| 32 | + @mkdir -p $(SOURCE_DIR)/var/db/newrelic-infra/newrelic-integrations/bin $(SOURCE_DIR)/etc/newrelic-infra/integrations.d |
| 33 | + @echo "=== Main === [ prep-pkg-env ]: adding built binaries and configuration and definition files..." |
| 34 | + @cp $(BINS_DIR)/$(BINARY_NAME) $(SOURCE_DIR)/var/db/newrelic-infra/newrelic-integrations/bin |
| 35 | + @chmod 755 $(SOURCE_DIR)/var/db/newrelic-infra/newrelic-integrations/bin/* |
| 36 | + @cp ./*.yml $(SOURCE_DIR)/var/db/newrelic-infra/newrelic-integrations/ |
| 37 | + @chmod 644 $(SOURCE_DIR)/var/db/newrelic-infra/newrelic-integrations/*.yml |
| 38 | + @cp ./*.sample $(SOURCE_DIR)/etc/newrelic-infra/integrations.d/ |
| 39 | + @chmod 644 $(SOURCE_DIR)/etc/newrelic-infra/integrations.d/*.sample |
| 40 | + |
| 41 | +deb: prep-pkg-env |
| 42 | + @echo "=== Main === [ deb ]: building DEB package..." |
| 43 | + @mkdir -p $(PACKAGES_DIR)/deb |
| 44 | + @fpm $(FPM_COMMON_OPTIONS) $(FPM_DEB_OPTIONS) . |
| 45 | + |
| 46 | +rpm: prep-pkg-env |
| 47 | + @echo "=== Main === [ rpm ]: building RPM package..." |
| 48 | + @mkdir -p $(PACKAGES_DIR)/rpm |
| 49 | + @fpm $(FPM_COMMON_OPTIONS) $(FPM_RPM_OPTIONS) . |
| 50 | + |
| 51 | +.PHONY: package create-bins prep-pkg-env $(PACKAGE_TYPES) |
0 commit comments