-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
86 lines (69 loc) · 2.38 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
REPO := github.com/infobloxopen/atlas-db
BUILD_PATH := bin
# configuration for image
DEFAULT_APP_NAME := atlas-db
APP_NAME ?= $(DEFAULT_APP_NAME)
DEFAULT_REGISTRY := infoblox
REGISTRY ?= $(DEFAULT_REGISTRY)
DEFAULT_VERSION := $(shell git describe --dirty=-dirty --always)
VERSION ?= $(DEFAULT_VERSION)
IMAGE_NAME := $(REGISTRY)/$(APP_NAME):$(VERSION)
IMAGE_LATEST := $(REGISTRY)/$(APP_NAME):latest
# configuration for source
SRC = atlas-db-controller
SRCDIR = $(REPO)/$(SRC)
# configuration for building
BUILD_TYPE ?= "default"
ifeq ($(BUILD_TYPE), "default")
GO_PATH := /go
SRCROOT_ON_HOST := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
SRCROOT_IN_CONTAINER := $(GO_PATH)/src/$(REPO)
GO_CACHE := -pkgdir $(SRCROOT_IN_CONTAINER)/$(BUILD_PATH)/go-cache
DOCKER_RUNNER := docker run --rm
DOCKER_RUNNER += -v $(SRCROOT_ON_HOST):$(SRCROOT_IN_CONTAINER)
DOCKER_BUILDER := infoblox/buildtool:v8
BUILDER := $(DOCKER_RUNNER) -w $(SRCROOT_IN_CONTAINER) $(DOCKER_BUILDER)
endif
GO_BUILD_FLAGS ?= $(GO_CACHE) -i -v
GO_TEST_FLAGS ?= -v -cover
# TEMPORARY FIX
IGNORE_FAKE := grep -v fake
GO_TEST_PACKAGES := $(shell $(BUILDER) go list ./... | grep -v "./vendor/"|$(IGNORE_FAKE))
SEARCH_GOFILES := $(BUILDER) find . -not -path '*/vendor/*' -type f -name "*.go"
.PHONY: default
default: build
# formats the repo
fmt:
@echo "Running 'go fmt ...'"
@$(SEARCH_GOFILES) -exec gofmt -s -w {} \;
deps:
@echo "Getting dependencies..."
$(BUILDER) dep ensure
clean:
@docker rmi "$(IMAGE_NAME)"
@docker rmi "$(IMAGE_LATEST)"
# Builds the docker image
build: deps fmt
@docker build --no-cache -t $(IMAGE_NAME) -f Dockerfile .
@docker tag $(IMAGE_NAME) $(IMAGE_LATEST)
# Pushes the image to docker
push: build
@docker push $(IMAGE_LATEST)
# Runs the tests
test: check-fmt
@echo "Running test cases..."
@$(BUILDER) go test $(GO_TEST_FLAGS) $(GO_TEST_PACKAGES)
check-fmt:
@echo "Checking go formatting..."
@test -z `go fmt $(GO_TEST_PACKAGES)`
# --- Kuberenetes deployment ---
# Deploy the service in kubernetes
up:
@kubectl apply -f deploy/crd.yaml
@kubectl apply -f deploy/namespace.yaml
@kubectl apply -f deploy/atlas-db.yaml
down:
@kubectl delete -f deploy/crd.yaml
@kubectl delete -f deploy/namespace.yaml
vendor:
$(BUILDER) dep update -v