-
Notifications
You must be signed in to change notification settings - Fork 84
/
Makefile
109 lines (90 loc) · 3.45 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
# Copyright 2017 The Kubernetes Authors.
#
# 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.
all: build
.PHONY: all
-include $(CONFIG)
-include $(CONFIG)-token
GIT_TAG ?= $(shell git describe --tags --always --dirty)
# Image variables
IMG_REGISTRY ?= gcr.io/k8s-staging-publishing-bot
IMG_NAME = k8s-publishing-bot
IMG_VERSION ?= v0.0.0-2
# TODO(image): Consider renaming this variable
DOCKER_REPO ?= $(IMG_REGISTRY)/$(IMG_NAME)
NAMESPACE ?=
TOKEN ?=
KUBECTL ?= kubectl
SCHEDULE ?= 0 5 * * *
INTERVAL ?= 86400
CPU_LIMITS ?= 2
CPU_REQUESTS ?= 300m
MEMORY_REQUESTS ?= 200Mi
MEMORY_LIMITS ?= 1639Mi
GOOS ?= linux
build_cmd = mkdir -p _output && GOOS=$(GOOS) CGO_ENABLED=0 go build -o _output/$(1) ./cmd/$(1)
prepare_spec = sed 's,DOCKER_IMAGE,$(DOCKER_REPO),g;s,CPU_LIMITS,$(CPU_LIMITS),g;s,CPU_REQUESTS,$(CPU_REQUESTS),g;s,MEMORY_REQUESTS,$(MEMORY_REQUESTS),g;s,MEMORY_LIMITS,$(MEMORY_LIMITS),g'
SHELL := /bin/bash
build:
$(call build_cmd,collapsed-kube-commit-mapper)
$(call build_cmd,publishing-bot)
$(call build_cmd,sync-tags)
$(call build_cmd,init-repo)
$(call build_cmd,gomod-zip)
$(call build_cmd,update-rules)
.PHONY: build
build-image: build
docker build \
-t $(DOCKER_REPO):$(GIT_TAG) \
-t $(DOCKER_REPO):$(IMG_VERSION) \
-t $(DOCKER_REPO):latest \
.
.PHONY: build-image
push-image:
docker push $(DOCKER_REPO):$(GIT_TAG)
docker push $(DOCKER_REPO):$(IMG_VERSION)
docker push $(DOCKER_REPO):latest
build-and-push-image: build-image push-image
.PHONY: build-and-push-image
clean:
rm -rf _output
.PHONY: clean
update-deps:
go mod tidy
.PHONY: update-deps
validate:
if [ -f $(CONFIG)-rules-configmap.yaml ]; then \
go run ./cmd/validate-rules <(sed '1,/config: /d;s/^ //' $(CONFIG)-rules-configmap.yaml); \
else \
go run ./cmd/validate-rules $$(grep "rules-file: " $(CONFIG)-configmap.yaml | sed 's/.*rules-file: //'); \
fi
.PHONY: validate
init-deploy: validate
$(KUBECTL) delete -n "$(NAMESPACE)" --ignore-not-found=true replicaset publisher
$(KUBECTL) delete -n "$(NAMESPACE)" --ignore-not-found=true pod publisher
while $(KUBECTL) get pod -n "$(NAMESPACE)" publisher -a &>/dev/null; do echo -n .; sleep 1; done
$(KUBECTL) apply -n "$(NAMESPACE)" -f artifacts/manifests/storage-class.yaml || true
$(KUBECTL) get StorageClass ssd
$(KUBECTL) apply -n "$(NAMESPACE)" -f $(CONFIG)-configmap.yaml
$(KUBECTL) apply -n "$(NAMESPACE)" -f $(CONFIG)-rules-configmap.yaml; \
$(KUBECTL) apply -n "$(NAMESPACE)" -f artifacts/manifests/pvc.yaml
run: init-deploy
{ cat artifacts/manifests/pod.yaml && sed 's/^/ /' artifacts/manifests/podspec.yaml; } | \
$(call prepare_spec) | $(KUBECTL) apply -n "$(NAMESPACE)" -f -
deploy: init-deploy
$(KUBECTL) apply -n "$(NAMESPACE)" -f artifacts/manifests/service.yaml
{ cat artifacts/manifests/rs.yaml && sed 's/^/ /' artifacts/manifests/podspec.yaml; } | \
$(call prepare_spec) | sed 's/-interval=0/-interval=$(INTERVAL)/g' | \
$(KUBECTL) apply -n "$(NAMESPACE)" -f -
test: ## Run go tests
go test -v -coverprofile=coverage.out ./...