forked from jetstack/kube-lego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
104 lines (79 loc) · 3 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
ACCOUNT=jetstack
APP_NAME=kube-lego
PACKAGE_NAME=github.com/${ACCOUNT}/${APP_NAME}
GO_VERSION=1.8
GOOS := linux
GOARCH := amd64
DOCKER_IMAGE=${ACCOUNT}/${APP_NAME}
BUILD_DIR=_build
TEST_DIR=_test
CONTAINER_DIR=/go/src/${PACKAGE_NAME}
BUILD_TAG := build
IMAGE_TAGS := canary
PACKAGES=$(shell find . -name "*_test.go" | xargs -n1 dirname | grep -v 'vendor/' | sort -u | xargs -n1 printf "%s.test_pkg ")
.PHONY: version
all: test build
codegen:
which mockgen
mockgen -imports .=github.com/jetstack/kube-lego/pkg/kubelego_const -package=mocks -source=pkg/kubelego_const/interfaces.go > pkg/mocks/mocks.go
depend:
rm -rf $(TEST_DIR)/
rm -rf ${BUILD_DIR}/
mkdir $(TEST_DIR)/
mkdir $(BUILD_DIR)/
version:
$(eval GIT_STATE := $(shell if test -z "`git status --porcelain 2> /dev/null`"; then echo "clean"; else echo "dirty"; fi))
$(eval GIT_COMMIT := $(shell git rev-parse HEAD))
$(eval APP_VERSION ?= $(shell cat VERSION))
echo $(APP_VERSION)
test_prepare: depend
which gocover-cobertura || go get github.com/t-yuki/gocover-cobertura
which go2xunit || go get github.com/tebeka/go2xunit
which ngrok || curl -sL "https://bin.equinox.io/a/mU8jSiqMekT/ngrok-2.1.14-linux-amd64.tar.gz" | tar xvzf - -C "${GOPATH}/bin"
go build -i
test: test_prepare $(PACKAGES)
echo $(PACKAGES)
%.test_pkg: test_prepare
$(eval PKG := ./$*)
$(eval PKG_CLEAN := $(shell echo "$*" | sed "s#^p#.p#" | sed "s#/#-#g"))
@echo "test $(PKG_CLEAN) ($(PKG))"
bash -o pipefail -c "go test -v -coverprofile=$(TEST_DIR)/coverage$(PKG_CLEAN).txt -covermode count $(PKG) | tee $(TEST_DIR)/test$(PKG_CLEAN).out"
cat $(TEST_DIR)/test$(PKG_CLEAN).out | go2xunit > $(TEST_DIR)/test$(PKG_CLEAN).xml
gocover-cobertura < $(TEST_DIR)/coverage$(PKG_CLEAN).txt > $(TEST_DIR)/coverage$(PKG_CLEAN).xml
build: depend version
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-a -tags netgo \
-o ${BUILD_DIR}/${APP_NAME}-$(GOOS)-$(GOARCH) \
-ldflags "-X main.AppGitState=${GIT_STATE} -X main.AppGitCommit=${GIT_COMMIT} -X main.AppVersion=${APP_VERSION}"
docker: docker_all
docker_%:
# create a container
$(eval CONTAINER_ID := $(shell docker create \
-i \
-w $(CONTAINER_DIR) \
golang:${GO_VERSION} \
/bin/bash -c "tar xf - && make $*" \
))
# run build inside container
tar cf - . | docker start -a -i $(CONTAINER_ID)
# copy artifacts over
rm -rf $(BUILD_DIR)/ $(TEST_DIR)/
docker cp $(CONTAINER_ID):$(CONTAINER_DIR)/$(BUILD_DIR)/ .
docker cp $(CONTAINER_ID):$(CONTAINER_DIR)/$(TEST_DIR)/ .
# remove container
docker rm $(CONTAINER_ID)
image: docker_all version
docker build --build-arg VCS_REF=$(GIT_COMMIT) -t $(DOCKER_IMAGE):$(BUILD_TAG) .
push: image
set -e; \
for tag in $(IMAGE_TAGS); do \
docker tag $(DOCKER_IMAGE):$(BUILD_TAG) $(DOCKER_IMAGE):$${tag} ; \
docker push $(DOCKER_IMAGE):$${tag}; \
done
release:
ifndef VERSION
$(error VERSION is not set)
endif
@echo "Preparing release of version $(VERSION)"
echo $(VERSION) > VERSION
find examples -name '*.yaml' -type f -exec sed -i 's/kube-lego:[0-9\.]*$$/kube-lego:$(VERSION)/g' {} \;