This repository has been archived by the owner on Nov 30, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
151 lines (121 loc) · 4.49 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
# Copyright IBM Corp All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -------------------------------------------------------------
# This makefile defines the following targets
#
# - all (default) - builds all targets and runs all tests
# - license - check all go files for license headers
# - cop - builds the cop executable
# - unit-tests - Performs checks first and runs the go-test based unit tests
# - checks - runs all check conditions (license, format, imports, lint and vet)
# - ldap-tests - runs the LDAP tests
# - docker[-clean] - ensures all docker images are available[/cleaned]
# - clean - cleans the build area
PROJECT_NAME = fabric-cop
BASE_VERSION = 0.7.0
IS_RELEASE = false
ifneq ($(IS_RELEASE),true)
EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD)
PROJECT_VERSION=$(BASE_VERSION)-$(EXTRA_VERSION)
else
PROJECT_VERSION=$(BASE_VERSION)
endif
# Check that all dependencies are installed
EXECUTABLES = go docker git curl
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies")))
ARCH=$(shell uname -m)
BASEIMAGE_RELEASE = 0.2.2
PKGNAME = github.com/hyperledger/$(PROJECT_NAME)
SAMPLECONFIG = $(shell git ls-files images/cop/config)
DOCKER_ORG = hyperledger
IMAGES = $(PROJECT_NAME) $(PROJECT_NAME)-runtime
image-path-map.fabric-cop := cop
image-path-map.fabric-cop-runtime := runtime
include docker-env.mk
all: docker unit-tests
docker: $(patsubst %,build/image/%/$(DUMMY), $(IMAGES))
checks: license vet lint format imports
license: .FORCE
@scripts/check_license
format: .FORCE
@scripts/check_format
imports: .FORCE
@scripts/check_imports
lint: .FORCE
@scripts/check_lint
vet: .FORCE
@scripts/check_vet
cop:
@echo "Building cop in bin directory ..."
@mkdir -p bin && cd cli && go build -o ../bin/cop
@echo "Built bin/cop"
# We (re)build a package within a docker context but persist the $GOPATH/pkg
# directory so that subsequent builds are faster
build/docker/bin/cop:
@echo "Building $@"
@mkdir -p $(@D) build/docker/$(@F)/pkg
@$(DRUN) \
-v $(abspath build/docker/bin):/opt/gopath/bin \
-v $(abspath build/docker/$(@F)/pkg):/opt/gopath/pkg \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
go install -ldflags "$(DOCKER_GO_LDFLAGS)" $(PKGNAME)/cli
mv build/docker/bin/cli $@
@touch $@
build/docker/busybox:
@echo "Building $@"
@$(DRUN) \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
make -f busybox/Makefile install BINDIR=$(@D)
build/image/$(PROJECT_NAME)/$(DUMMY): build/image/$(PROJECT_NAME)-runtime/$(DUMMY)
# payload definitions
build/image/$(PROJECT_NAME)/payload: build/docker/bin/cop \
build/sampleconfig.tar.bz2
build/image/$(PROJECT_NAME)-runtime/payload: build/docker/busybox
build/image/%/payload:
mkdir -p $@
cp images/cop/root.pem $@/root.pem
cp images/cop/tls_client-cert.pem $@/tls_client-cert.pem
cp images/cop/tls_client-key.pem $@/tls_client-key.pem
cp images/cop/ec.pem $@/ec.pem
cp images/cop/ec-key.pem $@/ec-key.pem
cp $^ $@
build/image/%/$(DUMMY): Makefile build/image/%/payload
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
$(eval DOCKER_NAME = $(DOCKER_ORG)/$(TARGET))
@echo "Building docker $(TARGET) image"
@cat images/$(image-path-map.$(TARGET))/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
$(DBUILD) -t $(DOCKER_NAME) $(@D)
docker tag $(DOCKER_NAME) $(DOCKER_NAME):$(DOCKER_TAG)
@touch $@
build/sampleconfig.tar.bz2: $(SAMPLECONFIG)
tar -jc -C images/cop/config $(patsubst images/cop/config/%,%,$(SAMPLECONFIG)) > $@
unit-tests: checks cop
@scripts/run_tests
container-tests: ldap-tests
ldap-tests:
@scripts/run_ldap_tests
%-docker-clean:
$(eval TARGET = ${patsubst %-docker-clean,%,${@}})
-docker images -q $(DOCKER_ORG)/$(TARGET):latest | xargs -I '{}' docker rmi -f '{}'
-@rm -rf build/image/$(TARGET) ||:
docker-clean: $(patsubst %,%-docker-clean, $(IMAGES))
.PHONY: clean
clean: docker-clean
-@rm -rf build bin ||:
.FORCE: