-
Notifications
You must be signed in to change notification settings - Fork 48
/
Makefile
217 lines (172 loc) · 7.85 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
DEBUG ?= "debug"
CONFIG ?=
TESTS ?= $(shell find tests/ -maxdepth 1 -mindepth 1 -type d -exec basename {} \;)
DO_DOCKER ?= 1
DOCKER_TARGET ?= load
DOCKER_PLATFORM ?= $(shell uname -s | tr '[A-Z]' '[a-z]')/$(subst aarch64,arm64,$(subst x86_64,amd64,$(shell uname -m)))
LINUXKIT_TARGET ?= build
# ESERVER_TAG is the tag for eserver image to build
ESERVER_TAG ?= "lfedge/eden-http-server"
# ESERVER_DIR is the directory with eserver Dockerfile to build
ESERVER_DIR=$(CURDIR)/eserver
# ESERVER_VERSION is the version of eserver image to build
ESERVER_VERSION ?= $(shell git rev-parse --short HEAD:eserver)
# PROCESSING_TAG is the tag for processing image to build
PROCESSING_TAG ?= "lfedge/eden-processing"
# PROCESSING_DIR is the directory with processing Dockerfile to build
PROCESSING_DIR=$(CURDIR)/processing
# PROCESSING_VERSION is the version of processing image to build
PROCESSING_VERSION ?= $(shell git tag -l --contains HEAD)
ifeq ($(PROCESSING_VERSION),)
PROCESSING_VERSION = $(shell git describe --always)
endif
# EDEN_TAG is the tag for eden image to build
EDEN_TAG ?= "lfedge/eden"
# EDEN_VERSION is the version of eden image to build
EDEN_VERSION ?= $(shell git tag -l --contains HEAD)
ifeq ($(EDEN_VERSION),)
EDEN_VERSION = $(shell git describe --always)
endif
# SDN_DIR is the directory with eden-sdn Dockerfile to build
SDN_DIR=$(CURDIR)/sdn/vm
# HOSTARCH is the host architecture
# ARCH is the target architecture
# we need to keep track of them separately
HOSTARCH ?= $(shell uname -m)
HOSTOS ?= $(shell uname -s | tr A-Z a-z)
# canonicalized names for host architecture
override HOSTARCH := $(subst aarch64,arm64,$(subst x86_64,amd64,$(HOSTARCH)))
# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
# and for my OS
ARCH ?= $(HOSTARCH)
OS ?= $(HOSTOS)
# canonicalized names for target architecture
override ARCH := $(subst aarch64,arm64,$(subst x86_64,amd64,$(ARCH)))
WORKDIR=$(CURDIR)/dist
BINDIR := dist/bin
BIN := eden
LOCALBIN := $(BINDIR)/$(BIN)-$(OS)-$(ARCH)
BUILDTOOLS_DIR := $(CURDIR)/build-tools
EMPTY_DRIVE := $(WORKDIR)/empty
EMPTY_DRIVE_SIZE := 10M
DIRECTORY_EXPORT ?= $(CURDIR)/export
ZARCH ?= $(HOSTARCH)
export ZARCH
LINUXKIT=$(BUILDTOOLS_DIR)/linuxkit
LINUXKIT_VERSION=86cc42bf79fde5bba63519313da337144841b647
LINUXKIT_SOURCE=https://github.com/linuxkit/linuxkit.git
.DEFAULT_GOAL := help
clean: config stop
make -C tests DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) clean
$(LOCALBIN) clean --current-context=false
rm -rf $(LOCALBIN) $(BINDIR)/$(BIN) $(LOCALTESTBIN) $(WORKDIR)
$(WORKDIR):
mkdir -p $@
$(BINDIR):
mkdir -p $@
$(DIRECTORY_EXPORT):
mkdir -p $@
$(BUILDTOOLS_DIR):
mkdir -p $@
test: build-tests
make -C tests TESTS="$(TESTS)" DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) test
unit-test:
go test $(go list ./... | grep -v /eden/tests/)
# create empty drives to use as additional volumes
$(EMPTY_DRIVE).%:
qemu-img create -f $* $@ $(EMPTY_DRIVE_SIZE)
build-tests: build testbin
install: build
CGO_ENABLED=0 go install .
build: $(BIN) $(EMPTY_DRIVE).raw $(EMPTY_DRIVE).qcow2 $(EMPTY_DRIVE).qcow $(EMPTY_DRIVE).vmdk $(EMPTY_DRIVE).vhdx $(LINUXKIT)
$(LOCALBIN): $(BINDIR) cmd/*.go pkg/*/*.go pkg/*/*/*.go
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags "-s -w" -o $@ .
mkdir -p dist/scripts/shell
cp -r shell-scripts/* dist/scripts/shell/
build-tools: $(LINUXKIT)
@echo Done building $<
$(BIN): $(LOCALBIN)
ln -sf $(BIN)-$(OS)-$(ARCH) $(BINDIR)/$@
ln -sf $(LOCALBIN) $@
ln -sf bin/$@ $(WORKDIR)/$@
$(LINUXKIT): $(BUILDTOOLS_DIR)
@rm -rf /tmp/linuxkit
@git clone $(LINUXKIT_SOURCE) /tmp/linuxkit
@cd /tmp/linuxkit && git checkout $(LINUXKIT_VERSION)
@cd /tmp/linuxkit/src/cmd/linuxkit && GO111MODULE=on CGO_ENABLED=0 go build -o $@ -mod=vendor .
@rm -rf /tmp/linuxkit
testbin: config
make -C tests DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) build
config: build
ifeq ($(OS), $(HOSTOS))
$(LOCALBIN) config add default -v $(DEBUG) $(CONFIG)
endif
setup: config build-tests
make -C tests DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) setup
$(LOCALBIN) setup -v $(DEBUG)
run: build setup
$(LOCALBIN) start -v $(DEBUG)
stop: build
$(LOCALBIN) stop -v $(DEBUG)
dist: build-tests
tar cvzf dist/eden_dist.tgz dist/bin dist/scripts dist/tests dist/*.txt
.PHONY: all clean test build build-tests tests-export config setup stop testbin dist
push-multi-arch-eserver:
@echo "Build and $(DOCKER_TARGET) eserver image $(ESERVER_TAG):$(ESERVER_VERSION)"
@docker buildx build --$(DOCKER_TARGET) --platform $(DOCKER_PLATFORM) --tag $(ESERVER_TAG):$(ESERVER_VERSION) $(ESERVER_DIR)
push-multi-arch-eden:
@echo "Build and $(DOCKER_TARGET) eden image $(EDEN_TAG):$(EDEN_VERSION)"
@docker buildx build --$(DOCKER_TARGET) --platform $(DOCKER_PLATFORM) --tag $(EDEN_TAG):$(EDEN_VERSION) .
push-multi-arch-sdn: $(LINUXKIT)
$(eval SDN_TAG = $(shell $(LINUXKIT) pkg show-tag $(SDN_DIR)))
@echo "$(LINUXKIT_TARGET) eden-sdn image $(SDN_TAG)"
@$(LINUXKIT) pkg $(LINUXKIT_TARGET) --force --platforms $(DOCKER_PLATFORM) --docker --build-yml build.yml $(SDN_DIR)
push-multi-arch-processing:
@echo "Build and $(DOCKER_TARGET) processing image $(PROCESSING_TAG):$(PROCESSING_VERSION)"
@docker buildx build --$(DOCKER_TARGET) --platform $(DOCKER_PLATFORM) --tag $(PROCESSING_TAG):$(PROCESSING_VERSION) $(PROCESSING_DIR)
build-docker: push-multi-arch-processing push-multi-arch-eserver push-multi-arch-eden push-multi-arch-sdn
make -C tests DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) DOCKER_TARGET=$(DOCKER_TARGET) DOCKER_PLATFORM=$(DOCKER_PLATFORM) build-docker
tests-export: $(DIRECTORY_EXPORT) build-tests
@cp -af $(WORKDIR)/tests/* $(DIRECTORY_EXPORT)
@echo "Your tests inside $(DIRECTORY_EXPORT)"
yetus:
@echo Running yetus
docker run -it --rm -v $(CURDIR):/src:delegated -v /tmp:/tmp apache/yetus:0.14.0 \
--basedir=/src \
--dirty-workspace \
--empty-patch \
--plugins=all
validate:
@echo Running static validation checks...
@echo ...on model files
@tar -cf - models/*.json | docker run -i alpine sh -c \
'tar xf - && apk add jq >&2 && for i in models/*.json; do echo "$$i" >&2 && jq -r ".logo | to_entries[] | .value" "$$i" || exit 1; done' |\
while read logo; do echo "$$logo" ; if [ ! -f models/`basename "$$logo"` ]; then echo "can't find $$logo" && exit 1; fi; done
help:
@echo "EDEN is the harness for testing EVE and ADAM"
@echo
@echo "This Makefile automates commons tasks of building and running"
@echo " * EVE"
@echo " * ADAM"
@echo
@echo "Commonly used maintenance and development targets:"
@echo " dist make distribution archive dist/eden_dist.tgz"
@echo " run run ADAM and EVE"
@echo " test run tests"
@echo " config generate required config files"
@echo " setup download and/or build required files"
@echo " stop stop ADAM and EVE"
@echo " clean full cleanup of test harness"
@echo " build build utilities (OS and ARCH options supported, for ex. OS=linux ARCH=arm64)"
@echo " build-docker build all docker images of EDEN"
@echo " build-tools build linuxkit (used to build SDN VM)"
@echo
@echo "You can use some parameters:"
@echo " CONFIG additional parameters for 'eden config add default', for ex. \"make CONFIG='--devmodel RPi4' run\" or \"make CONFIG='--devmodel GCP' run\""
@echo " TESTS list of tests for 'make test' to run, for ex. make TESTS='lim units' test"
@echo " DEBUG debug level for 'eden' command ('debug' by default)"
@echo "yetus run Apache Yetus to check the quality of the source tree"
@echo "tests-export exports escripts into export directory, content of export directory should be inside tests directory in root of another repo"
@echo
@echo "You need install requirements for EVE (look at https://github.com/lf-edge/eve#install-dependencies)."
@echo "You need access to docker socket and installed qemu packages."