forked from kbaseattic/handle_service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
333 lines (277 loc) · 12.5 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# totrack variables added herein
VARS_OLD := $(.VARIABLES)
TOP_DIR = ../..
DEPLOY_RUNTIME ?= /kb/runtime
TARGET ?= /kb/deployment
include $(TOP_DIR)/tools/Makefile.common
SERVICE_SPEC = handle_service.spec
SERVICE_NAME = AbstractHandle
SERVICE_PORT = 7109
SERVICE_DIR = handle_service
ifeq ($(SELF_URL),)
SELF_URL = http://localhost:$(SERVICE_PORT)
endif
NAMESPACE = KBH
SERVICE_PSGI = $(SERVICE_NAME).psgi
TPAGE_ARGS = --define kb_runas_user=$(SERVICE_USER) --define kb_top=$(TARGET) --define kb_runtime=$(DEPLOY_RUNTIME) --define kb_service_name=$(SERVICE_NAME) --define kb_service_dir=$(SERVICE_DIR) --define kb_service_port=$(SERVICE_PORT) --define kb_psgi=$(SERVICE_PSGI) --define handle_namespace=$(NAMESPACE)
# to wrap scripts and deploy them to $(TARGET)/bin using tools in
# the dev_container. right now, these vars are defined in
# Makefile.common, so it's redundant here.
TOOLS_DIR = $(TOP_DIR)/tools
SRC_PERL = $(wildcard scripts/*.pl)
# You can change these if you are putting your tests somewhere
# else or if you are not using the standard .t suffix
CLIENT_TESTS = $(wildcard client-tests/*.t)
SCRIPTS_TESTS = $(wildcard script-tests/*.t)
SERVER_TESTS = $(wildcard server-tests/*.t)
# This is a very client-centric view of release engineering.
# We assume our primary product for the community is the client
# libraries, command line interfaces, and the related documentation
# from which specific science applications can be built.
#
# A service is composed of a client and a server, each of which
# should be independently deployable. Clients are composed of
# an application programming interface (API) and a command line
# interface (CLI). In our make targets, deploy-service deploys
# the server, deploy-client deploys the application
# programming interface libraries, and deploy-scripts deploys
# the command line interface (usually scripts written in a
# scripting language but java executables also qualify), and the
# deploy target would be equivelant to deploying a service (client
# libs, scripts, and server).
#
# Because the deployment of the server side code depends on the
# specific software module being deployed, the strategy needs
# to be one that leaves this decision to the module developer.
# This is done by having the deploy target depend on the
# deploy-service target. The module developer who chooses for
# good reason not to deploy the server with the client simply
# manages this dependancy accordingly. One option is to have
# a deploy-service target that does nothing, the other is to
# remove the dependancy from the deploy target.
#
# A smiliar naming convention is used for tests.
default: build-libs
.SILENT:
vars:
@echo "nothing to do for default"
$(foreach v, \
$(filter-out $(VARS_OLD) VARS_OLD,$(.VARIABLES)), \
$(info $(v) = $($(v))))
# Distribution Section
#
# This section deals with the packaging of source code into a
# distributable form. This is different from a deployable form
# as our deployments tend to be kbase specific. To create a
# distribution, we have to consider the distribution mechanisms.
# For starters, we will consider cpan style packages for perl
# code, we will consider egg for python, npm for javascript,
# and it is not clear at this time what is right for java.
#
# In all cases, it is important not to implement into these
# targets the actual distribution. What these targets deal
# with is creating the distributable object (.tar.gz, .jar,
# etc) and placing it in the top level directory of the module
# distrubution directory.
#
# Use <module_name>/distribution as the top level distribution
# directory
dist: dist-cpan dist-egg dist-npm dist-java dist-r
dist-cpan: dist-cpan-client dist-cpan-service
dist-egg: dist-egg-client dist-egg-service
# In this case, it is not clear what npm service would mean,
# unless we are talking about a service backend implemented
# in javascript, which I can imagine happing. So the target
# is here, even though we don't have support for javascript
# on the back end of the compiler at this time.
dist-npm: dist-npm-client dist-npm-service
dist-java: dist-java-client dist-java-service
# in this case, I'm using the word client just for consistency
# sake. What we mean by client is an R library. At this time
# the meaning of a r-service is not understood. It can be
# added at a later time if there is a good reason.
dist-r: dist-r-client
dist-cpan-client:
echo "cpan client distribution not supported"
dist-cpan-service:
echo "cpan service distribution not supported"
dist-egg-client:
echo "egg client distribution not supported"
dist-egg-service:
echo "egg service distribution not supported"
dist-npm-client:
echo "npm client distribution not supported"
dist-npm-service:
echo "npm service distribution not supported"
dist-java-client:
echo "java client distribution not supported"
dist-java-service:
echo "java service distribuiton not supported"
dist-r-client:
echo "r client lib distribution not supported"
# Test Section
test: test-client
@echo "done running client tests"
# test-all is deprecated.
# test-all: test-client test-scripts test-service
#
# test-client: This is a test of a client library. If it is a
# client-server module, then it should be run against a running
# server. You can say that this also tests the server, and I
# agree. You can add a test-service dependancy to the test-client
# target if it makes sense to you. This test example assumes there is
# already a tested running server.
test-client:
# run each test
for t in $(CLIENT_TESTS) ; do \
if [ -f $$t ] ; then \
$(DEPLOY_RUNTIME)/bin/perl $$t ; \
if [ $$? -ne 0 ] ; then \
exit 1 ; \
fi \
fi \
done
# test-scripts: A script test should test the command line scripts. If
# the script is a client in a client-server architecture, then there
# should be tests against a running server. You can add a test-service
# dependency to the test-client target. You could also add a
# deploy-service and start-server dependancy to the test-scripts
# target if it makes sense to you. Future versions of the makefiles
# for services will move in this direction.
test-scripts:
# run each test
for t in $(SCRIPT_TESTS) ; do \
if [ -f $$t ] ; then \
$(DEPLOY_RUNTIME)/bin/perl $$t ; \
if [ $$? -ne 0 ] ; then \
exit 1 ; \
fi \
fi \
done
# test-service: A server test should not rely on the client libraries
# or scripts--you should not have a test-service target that depends
# on the test-client or test-scripts targets. Otherwise, a circular
# dependency graph could result.
test-service:
# run each test
for t in $(SERVER_TESTS) ; do \
if [ -f $$t ] ; then \
$(DEPLOY_RUNTIME)/bin/perl $$t ; \
if [ $$? -ne 0 ] ; then \
exit 1 ; \
fi \
fi \
done
# Deployment:
#
# We are assuming our primary products to the community are
# client side application programming interface libraries and a
# command line interface (scripts). The deployment of client
# artifacts should not be dependent on deployment of a server,
# although we recommend deploying the server code with the
# client code when the deploy target is executed. If you have
# good reason not to deploy the server at the same time as the
# client, just delete the dependancy on deploy-service. It is
# important to note that you must have a deploy-service target
# even if there is no server side code to deploy.
deploy: deploy-client deploy-service
# deploy-all deploys client *and* server. This target is deprecated
# and should be replaced by the deploy target.
deploy-all: deploy-client deploy-service
# deploy-client should deploy the client artifacts, mainly
# the application programming interface libraries, command
# line scripts, and associated reference documentation.
deploy-client: build-libs deploy-libs deploy-scripts deploy-docs vars
deploy-scripts: deploy-perl-scripts
# The deploy-libs and deploy-scripts targets are used to recognize
# and delineate the client types, mainly a set of libraries that
# implement an application programming interface and a set of
# command line scripts that provide command-based execution of
# individual API functions and aggregated sets of API functions.
deploy-libs:
rsync --exclude '*.bak*' -arv lib/. $(TARGET)/lib/.
# Deploying scripts needs some special care. They need to run
# in a certain runtime environment. Users should not have
# to modify their user environments to run kbase scripts, other
# than just sourcing a single user-env script. The creation
# of this user-env script is the responsibility of the code
# that builds all the kbase modules. In the code below, we
# run a script in the dev_container tools directory that
# wraps perl scripts. The name of the perl wrapper script is
# kept in the WRAP_PERL_SCRIPT make variable. This script
# requires some information that is passed to it by way
# of exported environment variables in the bash script below.
#
# What does it mean to wrap a perl script? To wrap a perl
# script means that a bash script is created that sets
# all required environment variables and then calls the perl
# script using the perl interperter in the kbase runtime.
# For this to work, both the actual script and the newly
# created shell script have to be deployed. When a perl
# script is wrapped, it is first copied to TARGET/plbin.
# The shell script can now be created because the necessary
# environment variables are known and the location of the
# script is known.
# Deploying a service refers to to deploying the capability
# to run a service. Becuase service code is often deployed
# as part of the libs, meaning service code gets deployed
# when deploy-libs is called, the deploy-service target is
# generally concerned with the service start and stop scripts.
# The deploy-cfg target is defined in the common rules file
# located at $TOP_DIR/tools/Makefile.common.rules and included
# at the end of this file.
deploy-service: deploy-cfg
mkdir -p $(TARGET)/services/$(SERVICE_DIR)
$(TPAGE) $(TPAGE_ARGS) service/start_service.tt > $(TARGET)/services/$(SERVICE_DIR)/start_service
chmod +x $(TARGET)/services/$(SERVICE_DIR)/start_service
$(TPAGE) $(TPAGE_ARGS) service/stop_service.tt > $(TARGET)/services/$(SERVICE_DIR)/stop_service
chmod +x $(TARGET)/services/$(SERVICE_DIR)/stop_service
$(TPAGE) $(TPAGE_ARGS) service/upstart.tt > service/$(SERVICE_NAME).conf
chmod +x service/$(SERVICE_NAME).conf
$(TPAGE) $(TPAGE_ARGS) service/constants.tt > $(TARGET)/lib/Bio/KBase/HandleServiceConstants.pm
echo "done executing deploy-service target"
deploy-upstart: deploy-service
-cp service/$(SERVICE_NAME).conf /etc/init/
echo "done executing deploy-upstart target"
# Deploying docs here refers to the deployment of documentation
# of the API. We'll include a description of deploying documentation
# of command line interface scripts when we have a better understanding of
# how to standardize and automate CLI documentation.
deploy-docs: build-docs
-mkdir -p $(TARGET)/services/$(SERVICE_DIR)/webroot/.
cp docs/*.html $(TARGET)/services/$(SERVICE_DIR)/webroot/.
# The location of the Client.pm file depends on the --client param
# that is provided to the compile_typespec command. The
# compile_typespec command is called in the build-libs target.
build-docs: compile-docs
-mkdir -p docs
pod2html --infile=lib/Bio/KBase/$(SERVICE_NAME)/Client.pm --outfile=docs/$(SERVICE_NAME).html
# Use the compile-docs target if you want to unlink the generation of
# the docs from the generation of the libs. Not recommended, but there
# could be a reason for it that I'm not seeing.
# The compile-docs target should depend on build-libs so that we are
# assured of having a set of documentation that is based on the latest
# type spec.
compile-docs: build-libs
# build-libs should be dependent on the type specification and the
# type compiler. Building the libs in this way means that you don't
# need to put automatically generated code in a source code version
# control repository (e.g., cvs, git). It also ensures that you always
# have the most up-to-date libs and documentation if your compile-docs
# target depends on the compiled libs.
build-libs:
compile_typespec \
--patric \
--psgi $(SERVICE_PSGI) \
--impl Bio::KBase::$(SERVICE_NAME)::$(SERVICE_NAME)Impl \
--service Bio::KBase::$(SERVICE_NAME)::Service \
--client Bio::KBase::$(SERVICE_NAME)::Client \
--py biokbase/$(SERVICE_NAME)/Client \
--js javascript/$(SERVICE_NAME)/Client \
--url $(SELF_URL) \
$(SERVICE_SPEC) lib
# the Makefile.common.rules contains a set of rules that can be used
# in this setup. Because it is included last, it has the effect of
# shadowing any targets defined above. So lease be aware of the
# set of targets in the common rules file.
include $(TOP_DIR)/tools/Makefile.common.rules