forked from TritonDataCenter/sdc-cn-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
200 lines (178 loc) · 6.29 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# Copyright 2019 Joyent, Inc.
#
#
# Makefile: basic Makefile for template API service
#
# This Makefile is a template for new repos. It contains only repo-specific
# logic and uses included makefiles to supply common targets (javascriptlint,
# jsstyle, restdown, etc.), which are used by other repos as well. You may well
# need to rewrite most of this file, but you shouldn't need to touch the
# included makefiles.
#
# If you find yourself adding support for new targets that could be useful for
# other projects too, you should add these to the original versions of the
# included Makefiles (in eng.git) so that other teams can use them too.
#
#
# Files
#
DOC_FILES = index.md
JS_FILES := $(shell ls *.js 2>/dev/null) \
$(shell find bin lib test -name '*.js' 2>/dev/null)
JSL_CONF_NODE = tools/jsl.node.conf
JSL_FILES_NODE = $(JS_FILES)
JSSTYLE_FILES = $(JS_FILES)
JSSTYLE_FLAGS = -o indent=4,doxygen,unparenthesized-return=0
# The next line breaks the build due to a variable that eng.git sed expander
# doesn't know about (@@ENABLED@@)
# SMF_MANIFESTS_IN = smf/manifests/cn-agent.xml.in
NODE_PREBUILT_VERSION = v6.17.0
NODE_PREBUILT_TAG = gz
ifeq ($(shell uname -s),SunOS)
NODE_PREBUILT_IMAGE = 18b094b0-eb01-11e5-80c1-175dac7ddf02
endif
# Included definitions
ENGBLD_REQUIRE := $(shell git submodule update --init deps/eng)
include ./deps/eng/tools/mk/Makefile.defs
TOP ?= $(error Unable to access eng.git submodule Makefiles.)
ifeq ($(shell uname -s),SunOS)
include ./deps/eng/tools/mk/Makefile.node_prebuilt.defs
else
NPM=npm
NODE=node
NPM_EXEC=$(shell which npm)
NODE_EXEC=$(shell which node)
endif
include ./deps/eng/tools/mk/Makefile.smf.defs
NAME := cn-agent
RELEASE_TARBALL := $(NAME)-$(STAMP).tgz
RELEASE_MANIFEST := $(NAME)-$(STAMP).manifest
RELSTAGEDIR := /tmp/$(NAME)-$(STAMP)
NODEUNIT = $(TOP)/node_modules/.bin/nodeunit
ZFS_SNAPSHOT_TAR := $(TOP)/deps/zfs_snapshot_tar/zfs_snapshot_tar
NOMKNOD := $(TOP)/src/nomknod/nomknod.32.so \
$(TOP)/src/nomknod/nomknod.64.so
COAL ?= [email protected]
#
# Due to the unfortunate nature of npm, the Node Package Manager, there appears
# to be no way to assemble our dependencies without running the lifecycle
# scripts. These lifecycle scripts should not be run except in the context of
# an agent installation or uninstallation, so we provide a magic environment
# varible to disable them here.
#
NPM_ENV = SDC_AGENT_SKIP_LIFECYCLE=yes \
MAKE_OVERRIDES='CTFCONVERT=/bin/true CTFMERGE=/bin/true'
RUN_NPM_INSTALL = $(NPM_ENV) $(NPM) install
#
# Repo-specific targets
#
.PHONY: all
all: $(SMF_MANIFESTS) | $(NPM_EXEC) $(REPO_DEPS) $(ZFS_SNAPSHOT_TAR) $(NOMKNOD)
$(RUN_NPM_INSTALL)
$(NODEUNIT): | $(NPM_EXEC)
$(RUN_NPM_INSTALL)
#
# Unfortunately we don't have the CTF tools available during this build. We
# stub out their execution below, but also prevent stripping the binary.
# Shipped binaries will, at least, contain DWARF.
#
$(ZFS_SNAPSHOT_TAR): deps/zfs_snapshot_tar/.git
cd $(@D) && $(MAKE) \
CTFCONVERT=/bin/true \
CTFMERGE=/bin/true \
STRIP=/bin/true \
$(@F)
$(NOMKNOD): src/nomknod/nomknod.c src/nomknod/Makefile
cd $(@D) && $(MAKE)
CLEAN_FILES += $(NODEUNIT) ./node_modules/tap $(NOMKNOD)
DISTCLEAN_FILES += $(NAME)-*.manifest $(NAME)-*.tgz
.PHONY: test
test:
./test/runtests
.PHONY: test-coal
test-coal:
./tools/rsync-to coal
ssh $(COAL) 'cd /opt/smartdc/agents/lib/node_modules/cn-agent \
&& /opt/smartdc/agents/lib/node_modules/cn-agent/node/bin/node \
/opt/smartdc/agents/lib/node_modules/cn-agent/node_modules/.bin/nodeunit \
--reporter default'
.PHONY: release
release: all deps docs $(SMF_MANIFESTS)
@echo "Building $(RELEASE_TARBALL)"
@mkdir -p $(RELSTAGEDIR)/$(NAME)
cd $(TOP) && $(RUN_NPM_INSTALL)
cp -r \
$(TOP)/Makefile \
$(TOP)/bin \
$(TOP)/build/node \
$(TOP)/lib \
$(TOP)/node_modules \
$(TOP)/npm \
$(TOP)/package.json \
$(TOP)/sapi_manifests \
$(TOP)/smf \
$(TOP)/test \
$(TOP)/tools \
$(RELSTAGEDIR)/$(NAME)
cp $(ZFS_SNAPSHOT_TAR) \
$(RELSTAGEDIR)/$(NAME)/lib/zfs_snapshot_tar
cp $(NOMKNOD) \
$(RELSTAGEDIR)/$(NAME)/lib/
# Trim node
rm -rf \
$(RELSTAGEDIR)/$(NAME)/node/bin/npm \
$(RELSTAGEDIR)/$(NAME)/node/lib/node_modules \
$(RELSTAGEDIR)/$(NAME)/node/include \
$(RELSTAGEDIR)/$(NAME)/node/share
uuid -v4 >$(RELSTAGEDIR)/cn-agent/image_uuid
cd $(RELSTAGEDIR) && $(TAR) -I pigz -cf $(TOP)/$(RELEASE_TARBALL) *
cat $(TOP)/manifest.tmpl | sed \
-e "s/UUID/$$(cat $(RELSTAGEDIR)/cn-agent/image_uuid)/" \
-e "s/NAME/$$(json name < $(TOP)/package.json)/" \
-e "s/VERSION/$$(json version < $(TOP)/package.json)/" \
-e "s/DESCRIPTION/$$(json description < $(TOP)/package.json)/" \
-e "s/BUILDSTAMP/$(STAMP)/" \
-e "s/SIZE/$$(stat --printf="%s" $(TOP)/$(RELEASE_TARBALL))/" \
-e "s/SHA/$$(openssl sha1 $(TOP)/$(RELEASE_TARBALL) \
| cut -d ' ' -f2)/" \
> $(TOP)/$(RELEASE_MANIFEST)
@rm -rf $(RELSTAGEDIR)
# removing build by-product in libarchive
rm -f deps/zfs_snapshot_tar/deps/libarchive/build/autoconf/test-driver
.PHONY: publish
publish: release
mkdir -p $(ENGBLD_BITS_DIR)/$(NAME)
cp $(TOP)/$(RELEASE_TARBALL) $(ENGBLD_BITS_DIR)/$(NAME)/$(RELEASE_TARBALL)
cp $(TOP)/$(RELEASE_MANIFEST) $(ENGBLD_BITS_DIR)/$(NAME)/$(RELEASE_MANIFEST)
.PHONY: dumpvar
dumpvar:
@if [[ -z "$(VAR)" ]]; then \
echo "error: set 'VAR' to dump a var"; \
exit 1; \
fi
@echo "$(VAR) is '$($(VAR))'"
clean::
-cd deps/zfs_snapshot_tar && $(MAKE) clobber
# Here "cutting a release" is just tagging the current commit with
# "v(package.json version)". We don't publish this to npm.
.PHONY: cutarelease
cutarelease:
@echo "# Ensure working copy is clean."
[[ -z `git status --short` ]] # If this fails, the working dir is dirty.
@echo "# Ensure have 'json' tool."
which json 2>/dev/null 1>/dev/null
ver=$(shell cat package.json | json version) && \
git tag "v$$ver" && \
git push origin "v$$ver"
include ./deps/eng/tools/mk/Makefile.deps
ifeq ($(shell uname -s),SunOS)
include ./deps/eng/tools/mk/Makefile.node_prebuilt.targ
endif
include ./deps/eng/tools/mk/Makefile.smf.targ
include ./deps/eng/tools/mk/Makefile.targ