-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
91 lines (70 loc) · 2.78 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
BINARY = $(shell ls cmd)
ifdef IMAGE_PREFIX
PREFIX="$(IMAGE_PREFIX)-"
endif
TAG="latest"
ifdef IMAGE_TAG
TAG="$(IMAGE_TAG)"
endif
ifneq (, $(findstring gcr.io,$(REGISTRY)))
PREFIX_CMD="gcloud"
DOCKER_OPTS="--"
endif
OUTDIR=_output
BUILDDIR=build
LOCAL_TARGET=local
COV_TARGET=coverity
FEDERATOR:=federator
OPSSIGHT_CORE:=opssight-core
CURRENT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD_TIME:=$(shell date)
LAST_COMMIT=$(shell git rev-parse HEAD)
.PHONY: all clean test push test ${BINARY} container local
all: build
build: ${OUTDIR} $(BINARY)
${LOCAL_TARGET}: ${OUTDIR} $(BINARY)
${COV_TARGET}: ${OUTDIR} $(BINARY)
$(BINARY):
ifeq ($(MAKECMDGOALS),${LOCAL_TARGET})
cd cmd/$@ && echo Starting build for $@ in `pwd` at `date` && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $@
else ifeq ($(MAKECMDGOALS),${COV_TARGET})
mkdir -p /go/src/github.com/blackducksoftware && ln -s `pwd` /go/src/github.com/blackducksoftware/opssight-connector && cd /go/src/github.com/blackducksoftware/opssight-connector/cmd/$@ && echo Starting build for $@ in `pwd` at `date` && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $@ ; rm /go/src/github.com/blackducksoftware/opssight-connector
else
docker run --rm -e CGO_ENABLED=0 -e GOOS=linux -e GOARCH=amd64 -e GO111MODULE=off -v "${CURRENT_DIR}":/go/src/github.com/blackducksoftware/opssight-connector -w /go/src/github.com/blackducksoftware/opssight-connector/cmd/$@ golang:1.13 go build -o $@
endif
mv cmd/$@/$@ ${OUTDIR}
container: registry_check container_prep
$(foreach p,${BINARY}, \
if [[ $(p) != $(FEDERATOR) ]]; then \
cd ${CURRENT_DIR}/${BUILDDIR}/$p; \
docker build . -t $(REGISTRY)/$(PREFIX)${p}:$(TAG) --build-arg VERSION=$(TAG) --build-arg 'BUILDTIME=$(BUILD_TIME)' --build-arg LASTCOMMIT=$(LAST_COMMIT);\
fi; \
)
container_prep: ${OUTDIR} $(BINARY)
$(foreach p,${BINARY},\
if [[ $(p) = $(FEDERATOR) ]]; then \
mkdir -p ${CURRENT_DIR}/${BUILDDIR}/opssight-core; \
cp ${CURRENT_DIR}/cmd/$p/* ${OUTDIR}/$p ${CURRENT_DIR}/${BUILDDIR}/opssight-core; \
else \
mkdir -p ${CURRENT_DIR}/${BUILDDIR}/$p; \
cp ${CURRENT_DIR}/cmd/$p/* LICENSE ${OUTDIR}/$p ${CURRENT_DIR}/${BUILDDIR}/$p; \
fi; \
)
push: container
$(foreach p,${BINARY}, \
if [[ $(p) != $(FEDERATOR) ]]; then \
$(PREFIX_CMD) docker $(DOCKER_OPTS) push $(REGISTRY)/$(PREFIX)${p}:$(TAG);\
fi; \
)
test:
docker run --rm -e CGO_ENABLED=0 -e GOOS=linux -e GOARCH=amd64 -e GO111MODULE=off -v "${CURRENT_DIR}":/go/src/github.com/blackducksoftware/opssight-connector -w /go/src/github.com/blackducksoftware/opssight-connector golang:1.13 go test ./pkg/...
clean:
rm -rf ${OUTDIR} ${BUILDDIR}
$(foreach p,${BINARY},rm -f cmd/$p/$p;)
${OUTDIR}:
mkdir -p ${OUTDIR}
registry_check:
ifndef REGISTRY
echo "Must set REGISTRY to create containers"
exit 1
endif