-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
131 lines (103 loc) · 3.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
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
.PHONY: all clean dep lint agent bootstrap service
.SUFFIXES:
DOCKER ?= docker
# Inspiration taken from https://github.com/weaveworks/flux/blob/master/Makefile
# NB because this outputs absolute file names, you have to be careful
# if you're testing out the Makefile with `-W` (pretend a file is
# new); use the full path to the pretend-new file, e.g.,
# `make -W $PWD/registry/registry.go`
godeps=$(shell go list -f '{{join .Deps "\n"}}' $1 | grep -v /vendor/ | xargs go list -f '{{if not .Standard}}{{ $$dep := . }}{{range .GoFiles}}{{$$dep.Dir}}/{{.}} {{end}}{{end}}' 2>/dev/null)
AGENT_DEPS := $(call godeps,./agent)
BOOTSTRAP_DEPS := $(call godeps,./bootstrap)
SERVICE_DEPS := $(call godeps,./service)
GIT_VERSION :=$(shell git describe --always --long --dirty)
GIT_HASH :=$(shell git rev-parse HEAD)
IMAGE_TAG:=$(shell ./docker/image-tag)
# We can't install go packages on CircleCI without being root (or using sudo).
# Because the compilation is done only once there, it doesn't matter if we
# don't install the packages.
ifneq ($(CI),true)
INSTALL_FLAG := -i
endif
BUILDFLAGS := $(INSTALL_FLAG)
LDFLAGS:=-ldflags "-X github.com/weaveworks/launcher/pkg/version.Version=$(GIT_VERSION) -X github.com/weaveworks/launcher/pkg/version.Revision=$(GIT_HASH)"
all: dep agent bootstrap service
agent: build/.agent.done
bootstrap: build/.bootstrap.done
service: build/.service.done
docker/Dockerfile.service: docker/Dockerfile.service.in Makefile
@echo Generating $@
@sed -e 's/@@GIT_HASH@@/$(GIT_HASH)/g' < $< > [email protected] && mv [email protected] $@
build/.%.done: docker/Dockerfile.%
mkdir -p ./build/docker/$*
cp -r $^ ./build/docker/$*/
${DOCKER} build --build-arg=revision=$(GIT_HASH) -t weaveworks/launcher-$* -t weaveworks/launcher-$*:$(IMAGE_TAG) -f build/docker/$*/Dockerfile.$* ./build/docker/$*
touch $@
#
# Vendoring
#
dep: build/dep.done
build/dep.done:
go mod download
mkdir -p ./build
touch $@
#
# lint
#
lint:
@./scripts/go-lint.sh
#
# Agent
#
build/.agent.done: build/agent build/kubectl
build/agent: $(AGENT_DEPS)
build/agent: agent/*.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(BUILDFLAGS) -o $@ $(LDFLAGS) ./agent
include docker/kubectl.version
build/kubectl: cache/kubectl-$(KUBECTL_VERSION) docker/kubectl.version
cp cache/kubectl-$(KUBECTL_VERSION) $@
strip $@
chmod a+x $@
cache/kubectl-$(KUBECTL_VERSION):
mkdir -p cache
curl -L -o $@ "https://storage.googleapis.com/kubernetes-release/release/$(KUBECTL_VERSION)/bin/linux/amd64/kubectl"
# Bootstrap
#
build/.bootstrap.done: $(BOOTSTRAP_DEPS)
build/.bootstrap.done: bootstrap/*.go
for arch in amd64; do \
for os in linux darwin; do \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build $(BUILDFLAGS) -o "build/bootstrap/bootstrap_"$$os"_"$$arch $(LDFLAGS) ./bootstrap; \
done; \
done
touch $@
#
# Service
#
build/.service.done: build/service build/static
build/service: $(SERVICE_DEPS)
build/service: service/*.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(BUILDFLAGS) -o $@ $(LDFLAGS) ./service
# If we are not in CircleCI, we are local so use launcher-agent
# If we are in CircleCI, only use launcher-agent if we are building main, otherwise
# use build-tmp-public so we can run integration tests.
service/static/agent.yaml: service/static/agent.yaml.in
@echo Generating $@
if [ -z "$${CIRCLECI}" -o \( -z "$${CIRCLE_TAG}" -a "$${CIRCLE_BRANCH}" = "main" \) ]; then \
sed -e 's|@@IMAGE_URL@@|weaveworks/launcher-agent:$(IMAGE_TAG)|g' < $< > [email protected] && mv [email protected] $@; \
else \
sed -e 's|@@IMAGE_URL@@|weaveworks/build-tmp-public:launcher-agent-$(IMAGE_TAG)|g' < $< > [email protected] && mv [email protected] $@; \
fi
build/static: service/static/* service/static/agent.yaml
mkdir -p $@
cp $^ $@
#
# Local integration tests
#
integration-tests: all
./integration-tests/setup/reset-local-cluster.sh
./integration-tests/setup/setup-local-cluster.sh
./integration-tests/tests/install-update-flow.sh
clean:
rm -rf build cache vendor
rm -f docker/Dockerfile.service service/static/agent.yaml