forked from hyperledger-archives/fabric-cop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
146 lines (117 loc) · 4.19 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
# 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 = hyperledger/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/fabric-cop
pkgmap.cop := $(PKGNAME)
IMAGES = cop 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 build/docker/bin build/docker/cop/pkg
@$(DRUN) \
-v $(abspath build/docker/bin):/opt/gopath/bin \
-v $(abspath build/docker/cop/pkg):/opt/gopath/pkg \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
go install -ldflags "$(DOCKER_GO_LDFLAGS)" $(pkgmap.cop)/cli
mv build/docker/bin/cli build/docker/bin/cop
@touch $@
build/docker/busybox:
@echo "Building $@"
@$(DRUN) \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
make -f busybox/Makefile install BINDIR=$(@D)
build/image/cop/$(DUMMY): build/image/runtime/$(DUMMY)
# payload definitions'
build/image/cop/payload: build/docker/bin/cop
build/image/runtime/payload: build/docker/busybox
build/image/%/payload:
mkdir -p $@
cp $^ $@
build/image/cop/$(DUMMY): Makefile build/image/cop/payload
@echo "Building docker fabric-cop image"
@cat images/cop/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
$(DBUILD) -t $(PROJECT_NAME) $(@D)
docker tag $(PROJECT_NAME) $(PROJECT_NAME):$(DOCKER_TAG)
@touch $@
build/image/runtime/$(DUMMY): Makefile build/image/runtime/payload
@echo "Building docker fabric-cop-runtime image"
@cat images/runtime/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
$(DBUILD) -t $(PROJECT_NAME)-runtime $(@D)
docker tag $(PROJECT_NAME)-runtime $(PROJECT_NAME)-runtime:$(DOCKER_TAG)
@touch $@
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 $(PROJECT_NAME)-$(TARGET) | 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: