-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathMakefile
More file actions
119 lines (97 loc) · 3.27 KB
/
Makefile
File metadata and controls
119 lines (97 loc) · 3.27 KB
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
# Copyright 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
#
# https://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.
REPO_ROOT:=${CURDIR}
OUT_DIR=$(REPO_ROOT)/bin
# disable CGO by default for static binaries
CGO_ENABLED=0
export GOROOT GO111MODULE CGO_ENABLED
build: build-dranet build-dranetctl
build-dranet:
go build -v -o "$(OUT_DIR)/dranet" ./cmd/dranet
build-dranetctl:
go build -v -o "$(OUT_DIR)/dranetctl" ./cmd/dranetctl
clean:
rm -rf "$(OUT_DIR)/"
test:
CGO_ENABLED=1 go test -v -race -count 1 ./...
e2e-test:
bats --verbose-run tests/
# code linters
lint:
hack/lint.sh
helm-lint:
helm lint --strict deployments/helm/dranet
update:
go mod tidy
.PHONY: ensure-buildx
ensure-buildx:
./hack/init-buildx.sh
HELM_VERSION_SHA?=a2369ca71c0ef633bf6e4fccd66d634eb379b371 # v3.20.1
.PHONY: ensure-helm
ensure-helm:
@if ! helm version >/dev/null 2>&1; then \
echo "Helm not found, installing helm@$(HELM_VERSION_SHA) ..."; \
go install helm.sh/helm/v3/cmd/helm@$(HELM_VERSION_SHA); \
fi
# get image name from directory we're building
IMAGE_NAME=dranet
# docker image registry, default to upstream
REGISTRY?=gcr.io/k8s-staging-networking
# tag based on date-sha
TAG?=$(shell echo "$$(date +v%Y%m%d)-$$(git describe --always --dirty)")
# the full image tag
IMAGE?=$(REGISTRY)/$(IMAGE_NAME):$(TAG)
CHART_REGISTRY?=$(REGISTRY)/charts/$(IMAGE_NAME)
HELM_TAG?=$(shell git describe --tags --exact-match 2>/dev/null)
# for helm chart version strip 'v' to have valid semver (example: v0.1.0 → 0.1.0)
CHART_VERSION=$(shell echo "$(HELM_TAG)" | sed 's/^v//')
PLATFORMS?=linux/amd64,linux/arm64
# base images (defaults are in the Dockerfile)
BUILD_ARGS?=
ifdef GOLANG_IMAGE
BUILD_ARGS+=--build-arg GOLANG_IMAGE=$(GOLANG_IMAGE)
endif
ifdef BASE_IMAGE
BUILD_ARGS+=--build-arg BASE_IMAGE=$(BASE_IMAGE)
endif
# required to enable buildx
export DOCKER_CLI_EXPERIMENTAL=enabled
image-build: ensure-buildx
docker buildx build . \
$(BUILD_ARGS) \
--tag="${IMAGE}" \
--load
image-push: ensure-buildx
docker buildx build . \
--platform=$(PLATFORMS) \
$(BUILD_ARGS) \
--tag="${IMAGE}" \
--push
helm-package:
@test -n "$(CHART_VERSION)" || (echo "ERROR: not on an exact git tag, cannot package helm chart"; exit 1)
helm package deployments/helm/dranet \
--version "$(CHART_VERSION)" \
--app-version "$(HELM_TAG)" \
--destination $(OUT_DIR)
helm-push: helm-package
helm push $(OUT_DIR)/dranet-$(CHART_VERSION).tgz oci://$(CHART_REGISTRY)
kind-cluster:
kind create cluster --name dra --config kind.yaml
kind-image: image-build
docker tag ${IMAGE} registry.k8s.io/networking/dranet:stable
kind load docker-image registry.k8s.io/networking/dranet:stable --name dra
kubectl delete -f install.yaml || true
kubectl apply -f install.yaml
# The main release target, which pushes all images and helm charts
release: ensure-helm image-push helm-push