Skip to content

Commit b5a0391

Browse files
authored
Merge pull request #2 from newrelic/packaging
Add packaging to makefile
2 parents bcde788 + a54781a commit b5a0391

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
INTEGRATION := mysql
22
BINARY_NAME = nr-$(INTEGRATION)
33
SRC_DIR = ./src/
4-
GO_FILES := $(shell find $(SRC_DIR) -type f -name "*.go")
54
VALIDATE_DEPS = github.com/golang/lint/golint
65
TEST_DEPS = github.com/axw/gocov/gocov github.com/AlekSi/gocov-xml
76
INTEGRATIONS_DIR = /var/db/newrelic-infra/newrelic-integrations/
87
CONFIG_DIR = /etc/newrelic-infra/integrations.d
8+
GO_FILES := ./src/
9+
WORKDIR := $(shell pwd)
10+
TARGET := target
11+
TARGET_DIR = $(WORKDIR)/$(TARGET)
912

1013
all: build
1114

1215
build: clean validate compile test
1316

1417
clean:
1518
@echo "=== $(INTEGRATION) === [ clean ]: removing binaries and coverage file..."
16-
@rm -rfv bin coverage.xml
19+
@rm -rfv bin coverage.xml $(TARGET)
1720

1821
validate-deps:
1922
@echo "=== $(INTEGRATION) === [ validate-deps ]: installing validation dependencies..."
@@ -80,4 +83,7 @@ install: bin/$(BINARY_NAME)
8083
@sudo install -D --mode=644 --owner=root $(ROOT)$(INTEGRATION)-definition.yml $(INTEGRATIONS_DIR)/$(INTEGRATION)-definition.yml
8184
@sudo install -D --mode=644 --owner=root $(ROOT)$(INTEGRATION)-config.yml.sample $(CONFIG_DIR)/$(INTEGRATION)-config.yml.sample
8285

86+
# Include thematic Makefiles
87+
include Makefile-*.mk
88+
8389
.PHONY: all build clean validate-deps validate-only validate compile-deps compile test-deps test-only test install

Makefile-package.mk

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)