-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathMakefile
174 lines (138 loc) · 6.23 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
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PWD = $(shell pwd)
GOOS ?= $(shell go env GOOS)
GOARCH = amd64
BUILD_DIR ?= ./out
COMMIT ?= $(shell git rev-parse HEAD)
VERSION ?= v0.1.0
IMAGE_TAG ?= $(COMMIT)
# TODO(aaron-prindle) add this env var for int-test configuration
# GCP_TEST_PROJECT ?= kritis-int-test
%.exe: %
mv $< $@
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
ORG := github.com/grafeas
PROJECT := kritis
RESOLVE_TAGS_PROJECT := resolve-tags
REPOPATH ?= $(ORG)/$(PROJECT)
SUPPORTED_PLATFORMS := linux-$(GOARCH) darwin-$(GOARCH) windows-$(GOARCH).exe
RESOLVE_TAGS_PATH = cmd/kritis/kubectl/plugins/resolve
RESOLVE_TAGS_PACKAGE = $(REPOPATH)/$(RESOLVE_TAGS_PATH)
RESOLVE_TAGS_KUBECTL_DIR = ~/.kube/plugins/resolve-tags
LOCAL_GAC_CREDENTIALS_PATH ?= /tmp/gac.json
.PHONY: test
test: cross
./hack/check-fmt.sh
./hack/boilerplate.sh
./hack/verify-codegen.sh
./hack/dep.sh
./hack/test.sh
./hack/linter.sh
GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GO_LD_RESOLVE_FLAGS :=""
GO_BUILD_TAGS := ""
.PRECIOUS: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform))
$(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT): $(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT)-$(GOOS)-$(GOARCH)
cp $(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT)-$(GOOS)-$(GOARCH) $@
.PHONY: cross
cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT)-$(platform))
$(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags $(GO_LD_RESOLVE_FLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(RESOLVE_TAGS_PACKAGE)
.PHONY: cross-tar
cross-tar: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT)-$(platform).tar.gz)
$(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT)-%.tar.gz: cross
tar -czf $@ -C $(RESOLVE_TAGS_PATH) plugin.yaml -C $(PWD)/out/ resolve-tags-$*
.PHONY: install-plugin
install-plugin: $(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT)
mkdir -p $(RESOLVE_TAGS_KUBECTL_DIR)
cp $(BUILD_DIR)/$(RESOLVE_TAGS_PROJECT) $(RESOLVE_TAGS_KUBECTL_DIR)
cp cmd/kritis/kubectl/plugins/resolve/plugin.yaml $(RESOLVE_TAGS_KUBECTL_DIR)
GO_LDFLAGS := -extldflags "-static"
GO_LDFLAGS += -X github.com/grafeas/kritis/cmd/kritis/version.Commit=$(COMMIT)
GO_LDFLAGS += -X github.com/grafeas/kritis/cmd/kritis/version.Version=$(VERSION)
GO_LDFLAGS += -w -s # Drop debugging symbols.
REGISTRY?=gcr.io/kritis-project
TEST_REGISTRY?=gcr.io/kritis-int-test
REPOPATH ?= $(ORG)/$(PROJECT)
SERVICE_PACKAGE = $(REPOPATH)/cmd/kritis/admission
GCB_SIGNER_PACKAGE = $(REPOPATH)/cmd/kritis/gcbsigner
KRITIS_PROJECT = $(REPOPATH)/kritis
out/kritis-server: $(GO_FILES)
GOARCH=$(GOARCH) GOOS=linux CGO_ENABLED=0 go build -ldflags "$(GO_LDFLAGS)" -o $@ $(SERVICE_PACKAGE)
out/gcb-signer: $(GO_FILES)
GOARCH=$(GOARCH) GOOS=linux CGO_ENABLED=0 go build -ldflags "$(GO_LDFLAGS)" -o $@ $(GCB_SIGNER_PACKAGE)
.PHONY: build-image
build-image: out/kritis-server
docker build -t $(REGISTRY)/kritis-server:$(IMAGE_TAG) -f deploy/Dockerfile .
.PHONY: build-test-image
build-test-image: out/kritis-server
docker build -t $(TEST_REGISTRY)/kritis-server:$(IMAGE_TAG) -f deploy/Dockerfile .
HELM_HOOKS = preinstall postinstall predelete
$(HELM_HOOKS): $(GO_FILES)
GOARCH=$(GOARCH) GOOS=linux CGO_ENABLED=0 go build -ldflags "$(GO_LDFLAGS)" -o out/$@ $(REPOPATH)/helm-hooks/$@
.PHONY: %-image
%-image: $(HELM_HOOKS)
docker build -t $(REGISTRY)/$*:$(IMAGE_TAG) -f helm-hooks/Dockerfile . --build-arg stage=$*
.PHONY: %-test-image
%-test-image: $(HELM_HOOKS)
docker build -t $(TEST_REGISTRY)/$*:$(IMAGE_TAG) -f helm-hooks/Dockerfile . --build-arg stage=$*
.PHONY: helm-release-image
helm-release-image:
docker build -t $(REGISTRY)/helm-release:$(IMAGE_TAG) -f helm-release/Dockerfile .
.PHONY: helm-install-from-head
helm-install-from-head:
helm install --set repository=$(TEST_REGISTRY)/ --set image.tag=$(COMMIT) ./kritis-charts
clean:
rm -rf $(BUILD_DIR)
.PHONY: integration
integration: cross
go test -ldflags "$(GO_LDFLAGS)" -v -tags integration $(REPOPATH)/integration -timeout 5m -- --remote=true
.PHONY: integration-local
integration-local:
go test -ldflags "$(GO_LDFLAGS)" -v -tags integration $(REPOPATH)/integration -timeout 5m -remote=false -gac-credentials=$(LOCAL_GAC_CREDENTIALS_PATH)
.PHONY: build-push-image
build-push-image: build-image preinstall-image postinstall-image predelete-image
docker push $(REGISTRY)/kritis-server:$(IMAGE_TAG)
docker push $(REGISTRY)/preinstall:$(IMAGE_TAG)
docker push $(REGISTRY)/postinstall:$(IMAGE_TAG)
docker push $(REGISTRY)/predelete:$(IMAGE_TAG)
.PHONY: build-push-test-image
build-push-test-image: build-test-image preinstall-test-image postinstall-test-image predelete-test-image
docker push $(TEST_REGISTRY)/kritis-server:$(IMAGE_TAG)
docker push $(TEST_REGISTRY)/preinstall:$(IMAGE_TAG)
docker push $(TEST_REGISTRY)/postinstall:$(IMAGE_TAG)
docker push $(TEST_REGISTRY)/predelete:$(IMAGE_TAG)
.PHONY: integration-in-docker
integration-in-docker: build-push-image
docker build \
-f deploy/kritis-int-test/Dockerfile \
--target integration \
-t $(REGISTRY)/kritis-integration:$(IMAGE_TAG) .
docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(HOME)/tmp:/tmp \
-v $(HOME)/.config/gcloud:/root/.config/gcloud \
-v $(GOOGLE_APPLICATION_CREDENTIALS):$(GOOGLE_APPLICATION_CREDENTIALS) \
-e REMOTE_INTEGRATION=true \
-e DOCKER_CONFIG=/root/.docker \
-e GOOGLE_APPLICATION_CREDENTIALS=$(GOOGLE_APPLICATION_CREDENTIALS) \
$(REGISTRY)/kritis-integration:$(IMAGE_TAG)
.PHONY: gcb-signer-image
gcb-signer-image: out/gcb-signer-image
docker build -t $(REGISTRY)/kritis-gcb-signer:$(IMAGE_TAG) -f deploy/kritis-gcb-signer/Dockerfile .
.PHONY: gcb-signer-push-image
gcb-signer-push-image: gcb-signer-image
docker push $(REGISTRY)/kritis-gcb-signer:$(IMAGE_TAG)