This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Makefile
157 lines (120 loc) · 5.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
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
.PHONY: all install clean generated images lint unit-tests check
.DEFAULT_GOAL := all
# Boiler plate for bulding Docker containers.
# All this must go at top of file I'm afraid.
IMAGE_PREFIX := docker.io/weaveworks/wksctl-
IMAGE_TAG := $(shell tools/image-tag)
GIT_REVISION := $(shell git rev-parse HEAD)
VERSION=$(shell git describe --always)
UPTODATE := .uptodate
# Every directory with a Dockerfile in it builds an image called
# $(IMAGE_PREFIX)<dirname>. Dependencies (i.e. things that go in the image)
# still need to be explicitly declared.
%/$(UPTODATE): %/Dockerfile %/*
$(SUDO) docker build --build-arg=revision=$(GIT_REVISION) -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 . \
-name docs -prune -o \
-name tools -prune -o \
-name rpm -prune -o \
-name build -prune -o \
-name environments -prune -o \
-name test -prune -o \
-name examples -prune -o \
-type f -name 'Dockerfile' \
-print \
)
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))
@echo > /dev/null
# Define imagetag-golang, etc, for each image, which parses the dockerfile and
# prints an image tag. For example:
# FROM golang:1.8.1-stretch
# in the "foo/Dockerfile" becomes:
# $ make imagetag-foo
# 1.8.1-stretch
define imagetag_dep
.PHONY: imagetag-$(1)
$(patsubst $(IMAGE_PREFIX)%,imagetag-%,$(1)): $(patsubst $(IMAGE_PREFIX)%,%,$(1))/Dockerfile
@cat $$< | grep "^FROM " | head -n1 | sed 's/FROM \(.*\):\(.*\)/\2/'
endef
$(foreach image, $(IMAGE_NAMES), $(eval $(call imagetag_dep, $(image))))
all: $(UPTODATE_FILES) binaries
check: all lint unit-tests container-tests
BINARIES = \
cmd/wksctl/wksctl \
cmd/mock-authz-server/server \
cmd/mock-https-authz-server/server \
$(NULL)
binaries: $(BINARIES)
godeps=$(shell go list -f '{{join .Deps "\n"}}' $1 | \
xargs go list -f \
'{{if not .Standard}}{{ $$dep := . }}{{range .GoFiles}}{{$$dep.Dir}}/{{.}} {{end}}{{end}}')
DEPS=$(call godeps,./cmd/wksctl)
ADDONS_SOURCES=$(shell find addons/ -print)
pkg/addons/assets/assets_vfsdata.go: $(ADDONS_SOURCES)
go generate ./pkg/addons/assets
SCRIPTS=$(shell find pkg/apis/wksprovider/machine/scripts/all -name '*.sh' -print)
pkg/apis/wksprovider/machine/scripts/scripts_vfsdata.go: $(SCRIPTS)
go generate ./pkg/apis/wksprovider/machine/scripts
MANIFESTS=$(shell find pkg/apis/wksprovider/controller/manifests/yaml -name '*.yaml' -print)
pkg/apis/wksprovider/controller/manifests/manifests_vfsdata.go: $(MANIFESTS)
go generate ./pkg/apis/wksprovider/controller/manifests
CRDS=$(shell find config/crd -name '*.yaml' -print)
pkg/apis/wksprovider/machine/crds_vfsdata.go: $(CRDS)
go generate ./pkg/apis/wksprovider/machine/crds
generated: pkg/addons/assets/assets_vfsdata.go pkg/apis/wksprovider/controller/manifests/manifests_vfsdata.go pkg/apis/wksprovider/machine/scripts/scripts_vfsdata.go pkg/apis/wksprovider/machine/crds_vfsdata.go
cmd/wksctl/wksctl: $(DEPS) generated
cmd/wksctl/wksctl: cmd/wksctl/*.go
CGO_ENABLED=0 GOARCH=amd64 go build -ldflags "-X github.com/weaveworks/wksctl/pkg/version.Version=$(VERSION) -X github.com/weaveworks/wksctl/pkg/version.ImageTag=$(IMAGE_TAG)" -o $@ cmd/wksctl/*.go
cmd/mock-authz-server/.uptodate: cmd/mock-authz-server/server cmd/mock-authz-server/Dockerfile
cmd/mock-authz-server/server: cmd/mock-authz-server/*.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o $@ cmd/mock-authz-server/*.go
cmd/mock-https-authz-server/.uptodate: cmd/mock-https-authz-server/server cmd/mock-https-authz-server/Dockerfile
cmd/mock-https-authz-server/server: cmd/mock-https-authz-server/*.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o $@ cmd/mock-https-authz-server/*.go
ifneq ($(shell go env GOBIN),)
WKSCTL_INSTALL_PATH=$(shell go env GOBIN)
else
WKSCTL_INSTALL_PATH=$(shell go env GOPATH)/bin
endif
install: cmd/wksctl/wksctl
cp cmd/wksctl/wksctl $(WKSCTL_INSTALL_PATH)
lint:
@tools/go-lint
clean:
$(SUDO) docker rmi $(IMAGE_NAMES) >/dev/null 2>&1 || true
rm -rf $(UPTODATE_FILES)
rm -f cmd/wksctl/wksctl
push:
for IMAGE_NAME in $(IMAGE_NAMES); do \
docker push $$IMAGE_NAME:$(IMAGE_TAG); \
done
# We select which directory we want to descend into to not execute integration
# tests here.
unit-tests: generated
WKP_DEBUG=true go test -p 1 -v ./cmd/... ./pkg/...
# Tests running in containers
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))
container-tests: pkg/apis/wksprovider/machine/scripts/scripts_vfsdata.go pkg/apis/wksprovider/controller/manifests/manifests_vfsdata.go
WKP_DEBUG=true go test -v -count=1 ./test/container/...
integration-tests-container: cmd/wksctl/wksctl
APK_INDEX='https://https:dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz https://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz'
# Setting environment variable NODE_OS will run the test with the specified OS
# Valid values are centos or ubuntu, e.g NODE_OS=ubuntu make integration-tests-container
# Leaving NODE_OS unset will result in one of centos or ubuntu being chosen for the test
NODE_OS1="centos"
NODE_OS2="ubuntu"
NODE_OS=$${NODE_OS:-"$$(echo $$NODE_OS1 $$NODE_OS2 | tr ' ' '\n' | shuf | head -1)"}
WKP_DEBUG=true IMAGE_TAG=$(IMAGE_TAG) NODE_OS="$${NODE_OS}" go test -v -timeout 60m ./test/integration/container/...
FORCE:
docs-deps:
pip3 install -r docs/requirements.txt
serve-docs: docs-deps
mkdocs serve