-
Notifications
You must be signed in to change notification settings - Fork 54
/
Makefile
137 lines (103 loc) · 4.13 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
VERSION := $(shell git describe --dirty=-dirty --always --long --tags)
APP_NAME := atlas.pubsub
# Absolute github repository name.
REPO := github.com/infobloxopen/atlas-pubsub
SRC = examples/server
# Source directory path relative to $GOPATH/src.
SRCDIR = $(REPO)/$(SRC)
# Output binary name.
BIN = pubsub
# Build directory absolute path.
BINDIR = $(CURDIR)/bin
# Utility docker image to generate Go files from .proto definition.
# https://github.com/infobloxopen/buildtool
BUILDTOOL_IMAGE := infoblox/buildtool
DEFAULT_REGISTRY := infobloxcto
REGISTRY ?=$(DEFAULT_REGISTRY)
DEFAULT_NAMESPACE := atlas
PUBSUB_NAMESPACE ?=$(DEFAULT_NAMESPACE)
# Buildtool
BUILDER := docker run --rm -v $(CURDIR):/go/src/$(REPO) -w /go/src/$(REPO) $(BUILDTOOL_IMAGE)
IMAGE_NAME := $(REGISTRY)/$(APP_NAME):$(VERSION)
IMAGE_NAME_PUB := $(REGISTRY)/$(APP_NAME)-pub:$(VERSION)
IMAGE_NAME_SUB := $(REGISTRY)/$(APP_NAME)-sub:$(VERSION)
PROJECT_ROOT := github.com/infobloxopen/atlas-pubsub
# configuration for the protobuf gentool
SRCROOT_ON_HOST := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
SRCROOT_IN_CONTAINER := /home/go/src/$(PROJECT_ROOT)
DOCKERPATH := /home/go/src
DOCKER_RUNNER := docker run --rm
DOCKER_RUNNER += -v $(SRCROOT_ON_HOST):$(SRCROOT_IN_CONTAINER)
DOCKER_GENERATOR := infoblox/atlas-gentool:v19
GENERATOR := $(DOCKER_RUNNER) $(DOCKER_GENERATOR)
default: build
build: fmt bin
@$(BUILDER) go build $(GO_BUILD_FLAGS) -o "bin/$(BIN)" "$(SRCDIR)"
# Builds example hello publisher and subscriber
build-example: fmt bin build
@$(BUILDER) go build $(GO_BUILD_FLAGS) -o "bin/$(BIN)-pub" "$(REPO)/examples/hello/publisher"
@$(BUILDER) go build $(GO_BUILD_FLAGS) -o "bin/$(BIN)-sub" "$(REPO)/examples/hello/subscriber"
# formats the repo
fmt:
$(BUILDER) go fmt -x "$(REPO)/..."
deps:
@echo "Getting dependencies..."
@dep ensure
bin:
mkdir -p "$(BINDIR)"
clean:
@rm -rf "$(BINDIR)"
@rm -rf .glide
show-image-name:
@echo $(IMAGE_NAME)
# --- Docker commands ---
# Builds the docker image
image:
@docker build --pull -t $(IMAGE_NAME) -f docker/Dockerfile .
# Builds the hello example images
image-example:
@docker build --pull -t $(IMAGE_NAME_PUB) -f docker/Dockerfile.publisher .
@docker build --pull -t $(IMAGE_NAME_SUB) -f docker/Dockerfile.subscriber .
# Pushes the image to docker
push: image
@docker push $(IMAGE_NAME)
# Pushes the hello example images to docker
push-example: image-example
@docker push $(IMAGE_NAME_PUB)
@docker push $(IMAGE_NAME_SUB)
# Runs the tests
test:
echo "" > coverage.txt
for d in `go list ./... | grep -v vendor`; do \
t=$$(date +%s); \
go test -v -coverprofile=cover.out -covermode=atomic $$d || exit 1; \
echo "Coverage test $$d took $$(($$(date +%s)-t)) seconds"; \
if [ -f cover.out ]; then \
cat cover.out >> coverage.txt; \
rm cover.out; \
fi; \
done
# --- Kuberenetes deployment ---
# Deploy the pubsub service in kubernetes
deploy-server:
cat deploy/pubsub.yaml | sed 's/\$$PUBSUB_NAMESPACE/$(PUBSUB_NAMESPACE)/g' | @kubectl create -f -
# Deployes the hello example publisher and subscriber
deploy-example:
cat deploy/pubsub-pub.yaml | sed 's/\$$PUBSUB_NAMESPACE/$(PUBSUB_NAMESPACE)/g' | @kubectl create -f -
cat deploy/pubsub-sub.yaml | sed 's/\$$PUBSUB_NAMESPACE/$(PUBSUB_NAMESPACE)/g' | @kubectl create -f -
# Removes the kubernetes pod
remove:
cat deploy/pubsub.yaml | sed 's/\$$PUBSUB_NAMESPACE/$(PUBSUB_NAMESPACE)/g' | @kubectl delete -f -
# Removes the example hello publisher and subscriber pods
remove-example:
cat deploy/pubsub-pub.yaml | sed 's/\$$PUBSUB_NAMESPACE/$(PUBSUB_NAMESPACE)/g' | @kubectl delete -f -
cat deploy/pubsub-sub.yaml | sed 's/\$$PUBSUB_NAMESPACE/$(PUBSUB_NAMESPACE)/g' | @kubectl delete -f -
vendor:
glide update -v
temp-create-pubsub:
cat pubsub.yaml | envsubst ' $AWS_ACCESS_KEY$AWS_ACCESS_KEY_ID$AWS_SECRET_ACCESS_KEY$AWS_SECRET_KEY'| ks create -f pubsub.yaml
protobuf:
$(GENERATOR) \
-I/home/go/src/github.com/infobloxopen/atlas-pubsub \
--go_out="plugins=grpc:$(SRCROOT_IN_CONTAINER)" \
grpc/server.proto