-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
91 lines (72 loc) · 2.91 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
.PHONY: all test clean images
.DEFAULT_GOAL := all
# Boiler plate for bulding Docker containers.
# All this must go at top of file I'm afraid.
IMAGE_PREFIX := weaveworks
IMAGE_TAG := $(shell ./tools/image-tag)
UPTODATE := .uptodate
# Building Docker images is now automated. The convention is every directory
# with a Dockerfile in it builds an image calls quay.io/weaveworks/<dirname>.
# Dependencies (i.e. things that go in the image) still need to be explicitly
# declared.
%/$(UPTODATE): %/Dockerfile
$(SUDO) docker build -t $(IMAGE_PREFIX)/$(shell basename $(@D)) $(@D)/
$(SUDO) docker tag $(IMAGE_PREFIX)/$(shell basename $(@D)) $(IMAGE_PREFIX)/$(shell basename $(@D)):$(IMAGE_TAG)
touch $@
# Get a list of directories containing Dockerfiles
DOCKERFILES := $(shell find . -type f -name Dockerfile ! -path "./tools/*" ! -path "./vendor/*")
UPTODATE_FILES := $(patsubst %/Dockerfile,%/$(UPTODATE),$(DOCKERFILES))
DOCKER_IMAGE_DIRS=$(patsubst %/Dockerfile,%,$(DOCKERFILES))
IMAGE_NAMES=$(foreach dir,$(DOCKER_IMAGE_DIRS),$(patsubst %,$(IMAGE_PREFIX)/%,$(shell basename $(dir))))
images:
$(info $(IMAGE_NAMES))
# List of exes please
LOKI_EXE := cmd/loki/loki
EXES = $(LOKI_EXE)
all: $(UPTODATE_FILES)
# And what goes into each exe
$(LOKI_EXE): $(shell find . -name '*.go') pkg/zipkin-ui/bindata.go pkg/annotation/parse.go
pkg/zipkin-ui/bindata.go: $(shell find pkg/zipkin-ui/static)
pkg/annotation/parse.go: pkg/annotation/parse.y
# And now what goes into each image
loki-build/$(UPTODATE): loki-build/*
cmd/loki/$(UPTODATE): $(LOKI_EXE)
# All the boiler plate for building golang follows:
SUDO := $(shell docker info >/dev/null 2>&1 || echo "sudo -E")
BUILD_IN_CONTAINER := true
RM := --rm
GO_FLAGS := -ldflags "-extldflags \"-static\" -linkmode=external -s -w" -tags netgo -i
NETGO_CHECK = @strings $@ | grep cgo_stub\\\.go >/dev/null || { \
rm $@; \
echo "\nYour go standard library was built without the 'netgo' build tag."; \
echo "To fix that, run"; \
echo " sudo go clean -i net"; \
echo " sudo go install -tags netgo std"; \
false; \
}
ifeq ($(BUILD_IN_CONTAINER),true)
$(EXES) pkg/zipkin-ui/bindata.go pkg/annotation/parse.go lint test shell: loki-build/$(UPTODATE)
@mkdir -p $(shell pwd)/.pkg
$(SUDO) docker run $(RM) -ti \
-v $(shell pwd)/.pkg:/go/pkg \
-v $(shell pwd):/go/src/github.com/weaveworks-experiments/loki \
$(IMAGE_PREFIX)/loki-build $@
else
$(EXES): loki-build/$(UPTODATE)
go build $(GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)
pkg/zipkin-ui/bindata.go: loki-build/$(UPTODATE)
go-bindata -pkg ui -o pkg/zipkin-ui/bindata.go pkg/zipkin-ui/static/
lint: loki-build/$(UPTODATE)
./tools/lint -notestpackage -nocomment .
test: loki-build/$(UPTODATE)
./tools/test -no-go-get -netgo
shell: loki-build/$(UPTODATE)
bash
%.go: %.y
goyacc -o $@ $<
endif
clean:
$(SUDO) docker rmi $(IMAGE_NAMES) >/dev/null 2>&1 || true
rm -rf $(UPTODATE_FILES) $(EXES) pkg/zipkin-ui/bindata.go pkg/annotation/parse.go
go clean ./...