forked from LinOTP/LinOTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
415 lines (340 loc) · 13 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/usr/bin/make -f
# -*- coding: utf-8 -*-
#
# LinOTP - the open source solution for two factor authentication
# Copyright (C) 2016 - 2017 KeyIdentity GmbH
#
# This file is part of LinOTP server.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public
# License, version 3, as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the
# GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# E-mail: [email protected]
# Contact: www.linotp.org
# Support: www.keyidentity.com
#
#
# LinOTP toplevel makefile
#
#
# If you are running in a local development environment, you can
# set these environment variables to configure make behaviour:
# export http_proxy=http://proxy.hostname:port
# export no_proxy=localhost,127.0.0.1,.my.local.domain
# export RANCHER_URL=https://rancher.hostname/v1
# export RANCHER_ACCESS_KEY=copy-from-rancher-UI-API-section
# export RANCHER_SECRET_KEY=copy-from-rancher-UI-API-section
# export DOCKER_REGISTRY_URL=registry.local.domain
PYTHON:=python2
# This directory is used as destination for the various parts of
# the build phase. The various install targets default to this directory
# but can be overriden by DESTDIR
BUILDDIR:=$(PWD)/build
# Targets to operate on LinOTPd and its dependent projects shipped
# in this repository
LINOTPD_PROJS := linotpd adminclient/LinOTPAdminClientCLI
# These variables let you set the amount of stuff LinOTP is logging.
#
# LINOTP_LOGLEVEL controls the amount of logging in general while
# LINOTP_CONSOLE_LOGLEVEL controls logging to the console (as opposed
# to logstash -- logstash always gets whatever LINOTP_LOGLEVEL lets
# through, so LINOTP_CONSOLE_LOGLEVEL can be used to have less stuff
# show up on the console than in logstash).
# SQLALCHEMY_LOGLEVEL controls the amount of logging done by SQLAlchemy
# (who would have guessed); DEBUG will log SQL queries and results,
# INFO will log just queries (no results) and WARN will log neither.
# APACHE_LOGLEVEL limits the amount of stuff Apache writes to its error
# output; normally anything that is written to the LinOTP console goes
# through here, too, so there isn't a lot of sense in setting this
# differently to LINOTP_CONSOLE_LOGLEVEL unless you're doing nonstandard
# trickery and/or use a different (and unsupported by us) web server
# than Apache to run LinOTP.
export LINOTP_LOGLEVEL=INFO
export LINOTP_CONSOLE_LOGLEVEL=DEBUG
export SQLALCHEMY_LOGLEVEL=ERROR
export APACHE_LOGLEVEL=DEBUG
###################
# Recursive targets
#
# These invoke make in the project subdirectories
#
# install
# clean
#
# Each target will be expanded into the subdirectory targets
#
# e.g. build -> build.subdirmake -> build.smsprovider + build.useridresolver + build.linotpd
# Targets that should recurse into linotp project directories
LINOTPD_TARGETS := install clean
.PHONY: $(LINOTPD_TARGETS)
INSTALL_TARGETS := $(addsuffix .install,$(LINOTPD_PROJS))
CLEAN_TARGETS := $(addsuffix .clean,$(LINOTPD_PROJS))
MAKEFILE_TARGETS := $(INSTALL_TARGETS) $(CLEAN_TARGETS)
.PHONY: $(MAKEFILE_TARGETS)
$(MAKEFILE_TARGETS):
# Invoke makefile target in subdirectory/src
$(MAKE) -C $(basename $@)/src $(subst $(basename $@).,,$@)
# Subdirectory make that should invoke target in all subproject directories
.PHONY: %.subdirmake
%.subdirmake : linotpd.% ;
# Add dependencies for main targets
# build -> build.subdirmake
# clean -> clean.subdirmake
# etc.
.SECONDEXPANSION:
$(LINOTPD_TARGETS): $$(basename $$@).subdirmake
clean:
if [ -d $(BUILDDIR) ]; then rm -rf $(BUILDDIR) ;fi
if [ -d RELEASE ]; then rm -rf RELEASE; fi
# Run a command in a list of directories
# $(call run-in-directories,DIRS,COMMAND)
run-in-directories = \
echo run-in-directories:$(1) ;\
for P in $(1) ;\
do \
cmd="cd $$P/src && $(2)" ;\
echo \\n$$cmd ;\
( eval $$cmd ) || exit $? ;\
done
# Run a command in all linotpd directories
run-in-linotpd-projs = $(call run-in-directories,$(LINOTPD_PROJS),$(1))
#################
# Targets invoking setup.py
#
# Installation of packages in 'develop mode'.
.PHONY: develop
develop:
$(call run-in-linotpd-projs,$(PYTHON) setup.py $@)
#####################
# Unit test targets
#
#
# These targets can be run directly from a development
# environment, within a container or an installed system
#
# unittests - just the unit tests
# integrationtests - selenium integration tests
# test - all tests
ifndef NOSETESTS_ARGS
NOSETESTS_ARGS?=-v
endif
test: unittests integrationtests
unittests:
$(MAKE) -C linotpd/src/linotp/tests/unit $@
nosetests $(NOSETESTS_ARGS) .
# Functional tests. Additional arguments can be
# supplied with FUNCTIONALTESTS_ARGS
functionaltests:
$(MAKE) -C linotpd/src/linotp/tests/functional $@
# integrationtests - selenium integration tests
# Use the SELENIUMTESTS_ARGS to supply test arguments
integrationtests:
$(MAKE) -C linotpd/src/linotp/tests/integration $@
.PHONY: test unittests functionaltests integrationtests
#####################
# Packaging targets
#
# These targets run the various commands needed
# to create packages of linotp
# builddeb: Generate .debs
# deb-install: Build .debs and install to DESTDIR
DEBPKG_PROJS := linotpd adminclient/LinOTPAdminClientCLI
BUILDARCH = $(shell dpkg-architecture -q DEB_BUILD_ARCH)
CHANGELOG = "$(shell cd linotpd/src ; dpkg-parsechangelog)"
# Output is placed in DESTDIR, but this
# can be overriden
ifndef DESTDIR
DESTDIR = $(BUILDDIR)
endif
.PHONY: builddeb
builddeb:
# builddeb: Run debuild in each directory to generate .deb
$(call run-in-directories,$(DEBPKG_PROJS),$(MAKE) builddeb)
.PHONY: deb-install
deb-install: builddeb
# deb-install: move the built .deb files into an archive directory and
# generate Packages file
mkdir -pv $(DESTDIR)
cp $(foreach dir,$(DEBPKG_PROJS),$(dir)/build/*.deb) $(DESTDIR)
find $(DESTDIR)
cd $(DESTDIR) && dpkg-scanpackages -m . > Packages
#####################
# Docker container targets
#
# These targets are for building and running docker containers
# for integration and builds
# Container name | Dockerfile location | Purpose
# ---------------------------------------------------------------------------------------------------
# linotp-builder | Dockerfile.builder | Container ready to build linotp packages
# linotp | linotpd/src | Runs linotp in apache
# selenium-test | linotpd/src/tests/integration | Run LinOTP Selenium tests against selenium remote
# Extra arguments can be passed to docker build
DOCKER_BUILD_ARGS=
# List of tags to add to built linotp images, using the '-t' flag to docker-build
DOCKER_TAGS=latest
# Override to change the mirror used for image building
DEBIAN_MIRROR=ftp.debian.org
# Pass proxy environment variables through to docker build by default
DOCKER_PROXY_BUILD_ARGS= --build-arg=http_proxy --build-arg=https_proxy --build-arg=no_proxy
DOCKER_BUILD_ARGS+= --build-arg=DEBIAN_MIRROR=$(DEBIAN_MIRROR)
# Default Docker run arguments.
# Extra run arguments can be given here. It can also be used to
# override runtime parameters. For example, to specify a port mapping:
# make docker-run-linotp-sqlite DOCKER_RUN_ARGS='-p 1234:80'
DOCKER_RUN_ARGS=
DOCKER_BUILD = docker build $(DOCKER_BUILD_ARGS) $(DOCKER_PROXY_BUILD_ARGS)
DOCKER_RUN = docker run $(DOCKER_RUN_ARGS)
SELENIUM_TESTS_DIR=linotpd/src/linotp/tests/integration
## Toplevel targets
# Toplevel target to build all containers
docker-build-all: docker-build-debs docker-build-linotp docker-build-selenium
# Toplevel target to build linotp container
docker-linotp: docker-build-debs docker-build-linotp
# Build and run Selenium tests
docker-selenium: docker-build-linotp docker-build-selenium docker-run-selenium
##
.PHONY: docker-build-all docker-linotp docker-run-selenium
# This is expanded during build to add image tags
DOCKER_TAG_ARGS=$(foreach tag,$(DOCKER_TAGS),-t $(DOCKER_IMAGE):$(tag))
# The linotp builder container contains all build dependencies
# needed to build linotp, plus a copy of the linotp
# sources under /pkg/linotp
#
# To use this container as a playground to test build linotp:
# docker run -it linotp-builder
.PHONY: docker-build-linotp-builder
docker-build-linotp-builder:
$(DOCKER_BUILD) \
-f Dockerfile.builder \
-t linotp-builder \
.
# A unique name to reference containers for this build
NAME_PREFIX := linotpbuilder-$(shell date +%H%M%S-%N)
DOCKER_CONTAINER_NAME = $(NAME_PREFIX)
.PHONY: docker-build-debs
docker-build-debs: docker-build-linotp-builder
# Force rebuild of debs
rm -f $(BUILDDIR)/apt/Packages
$(MAKE) $(BUILDDIR)/apt/Packages
$(BUILDDIR)/apt/Packages:
# Build the debs in a container, then extract them from the image
$(DOCKER_RUN) \
--workdir=/pkg/linotp \
--name=$(DOCKER_CONTAINER_NAME)-apt \
--volume=$(PWD):/pkg/linotpsrc:ro \
linotp-builder \
sh -c "cp -ra /pkg/linotpsrc/* /pkg/linotp && \
make deb-install DESTDIR=/pkg/apt DEBUILD_OPTS=\"$(DEBUILD_OPTS)\" "
docker cp \
$(DOCKER_CONTAINER_NAME)-apt:/pkg/apt $(DESTDIR)
docker rm $(DOCKER_CONTAINER_NAME)-apt
.PHONY: docker-build-linotp
docker-build-linotp: DOCKER_IMAGE=linotp
docker-build-linotp: $(BUILDDIR)/dockerfy $(BUILDDIR)/apt/Packages
cp linotpd/src/Dockerfile \
linotpd/src/config/*.tmpl \
linotpd/src/tools/linotp-create-htdigest \
$(BUILDDIR)
# We show the files sent to Docker context here to aid in debugging
find $(BUILDDIR) -ls
$(DOCKER_BUILD) \
$(DOCKER_TAG_ARGS) \
-t $(DOCKER_IMAGE) \
$(BUILDDIR)
SELENIUM_DB_IMAGE=mysql:latest
.PHONY: docker-build-selenium
docker-build-selenium: docker-build-linotp
cd $(SELENIUM_TESTS_DIR) \
&& $(DOCKER_BUILD) \
-t selenium_tester .
.PHONY: docker-run-selenium
docker-run-selenium: docker-build-selenium
cd $(SELENIUM_TESTS_DIR) \
&& docker-compose run --rm selenium_tester
cd $(SELENIUM_TESTS_DIR) \
&& docker-compose down
.PHONY: docker-run-linotp-sqlite
docker-run-linotp-sqlite: docker-build-linotp
# Run linotp in a standalone container
cd linotpd/src \
&& $(DOCKER_RUN) -it \
-e LINOTP_DB_TYPE=sqlite \
-e LINOTP_DB_NAME=//tmp/sqlite \
-e LINOTP_DB_HOST= \
-e LINOTP_DB_PORT= \
-e HEALTHCHECK_PORT=80 \
-e LINOTP_LOGLEVEL=$(LINOTP_LOGLEVEL) \
-e LINOTP_CONSOLE_LOGLEVEL=$(LINOTP_CONSOLE_LOGLEVEL) \
-e SQLALCHEMY_LOGLEVEL=$(SQLALCHEMY_LOGLEVEL) \
-e APACHE_LOGLEVEL=$(APACHE_LOGLEVEL) \
linotp
# Dockerfy tool
.PHONY: get-dockerfy
get-dockerfy: $(BUILDDIR)/dockerfy
DOCKERFY_URL=https://github.com/SocialCodeInc/dockerfy/releases/download/1.1.0/dockerfy-linux-amd64-1.1.0.tar.gz
DOCKERFY_SHA256=813d47ebf2e63c966655dd5349a29600ba94deac7a57c132bf624c56ba210445
# Obtain dockerfy binary
# TODO: Build from source
$(BUILDDIR)/dockerfy:
mkdir -pv $(BUILDDIR)/dockerfy-tmp
wget --directory-prefix=$(BUILDDIR)/dockerfy-tmp $(DOCKERFY_URL)
echo "${DOCKERFY_SHA256}" $(BUILDDIR)/dockerfy-tmp/dockerfy-linux-amd64*gz \
| sha256sum -c -
tar -C $(BUILDDIR) -xvf $(BUILDDIR)/dockerfy-tmp/dockerfy-linux-amd64*.gz
rm -r $(BUILDDIR)/dockerfy-tmp
#####################
# Rancher targets
#
# These targets are for deploying built linotp images to rancher
# Override with ID e.g. branch name, tag or git commit
LINOTP_IMAGE_TAG=$(shell git rev-parse --short HEAD)
RANCHER_STACK_ID=$(shell git rev-parse --short HEAD)
# Override with type, e.g. prod, qa
RANCHER_STACK_TYPE=dev
RANCHER_STACK_NAME=linotp-$(RANCHER_STACK_TYPE)-$(RANCHER_STACK_ID)
DOCKER_REGISTRY=$(subst https://,,$(DOCKER_REGISTRY_URL))
$(BUILDDIR)/rancher/docker-compose.yml:
$(MAKE) rancher-prepare
rancher-prepare:
# Overrides to compose file specific to this stack
mkdir -pv $(BUILDDIR)/rancher
( echo 'version: "2"' ;\
echo 'services:' ;\
echo ' linotp:' ;\
echo ' image: $(DOCKER_REGISTRY)/linotp:$(LINOTP_IMAGE_TAG)' ;\
) > $(BUILDDIR)/rancher/docker-compose.yml
RANCHER_COMPOSE=rancher-compose --project-name $(RANCHER_STACK_NAME)
RANCHER_COMPOSE_FILES_LINOTP=-f linotpd/src/docker-compose.yml \
-f $(BUILDDIR)/rancher/docker-compose.yml
# Uncomment to aid debugging
# export RANCHER_CLIENT_DEBUG=true
# Run a given command
rancher-linotp-do:
$(RANCHER_COMPOSE) $(RANCHER_COMPOSE_FILES_LINOTP) $(CMD)
.PHONY: rancher-prepare rancher-linotp-do
rancher-linotp-create: rancher-prepare
$(MAKE) rancher-linotp-do CMD=create
rancher-linotp-rm: $(BUILDDIR)/rancher/docker-compose.yml
$(MAKE) rancher-linotp-do CMD=rm
rancher-linotp-start: $(BUILDDIR)/rancher/docker-compose.yml
$(MAKE) rancher-linotp-do CMD="start -d"
rancher-linotp-stop: $(BUILDDIR)/rancher/docker-compose.yml
$(MAKE) rancher-linotp-do CMD=stop
rancher-linotp-up: $(BUILDDIR)/rancher/docker-compose.yml
$(MAKE) rancher-linotp-do CMD="up -d"
rancher-linotp-down: $(BUILDDIR)/rancher/docker-compose.yml
$(MAKE) rancher-linotp-do CMD=down
.PHONY: rancher-linotp-create rancher-linotp-rm
.PHONY: rancher-linotp-start rancher-linotp-stop
.PHONY: rancher-linotp-up rancher-linotp-down