-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
105 lines (82 loc) · 2.85 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
# Docker
DOCKER_CMD = docker
DOCKER_BUILD = $(DOCKER_CMD) build
DOCKER_TAG ?= $(DOCKER_CMD) tag
DOCKER_PUSH ?= $(DOCKER_CMD) push
DOCKER_RUN = $(DOCKER_CMD) run
DOCKER_RMI = $(DOCKER_CMD) rmi -f
DOCKER_EXEC = $(DOCKER_CMD) exec
# escape_docker_tag escape colon char to allow use a docker tag as rule
define escape_docker_tag
$(subst :,--,$(1))
endef
# unescape_docker_tag an escaped docker tag to be use in a docker command
define unescape_docker_tag
$(subst --,:,$(1))
endef
# Docker jupyter image tag
GIT_COMMIT=$(shell git rev-parse HEAD | cut -c1-7)
GIT_DIRTY=
ifneq ($(shell git status --porcelain), )
GIT_DIRTY := -dirty
endif
DEV_PREFIX := dev
VERSION ?= $(DEV_PREFIX)-$(GIT_COMMIT)$(GIT_DIRTY)
# Docker jupyter image
JUPYTER_IMAGE ?= srcd/gitbase-spark-connector-jupyter
JUPYTER_IMAGE_VERSIONED ?= $(call escape_docker_tag,$(JUPYTER_IMAGE):$(VERSION))
# Versions
SCALA_VERSION ?= 2.11.11
SPARK_VERSION ?= 2.2.1
# if TRAVIS_SCALA_VERSION defined SCALA_VERSION is overrided
ifneq ($(TRAVIS_SCALA_VERSION), )
SCALA_VERSION := $(TRAVIS_SCALA_VERSION)
endif
# if TRAVIS_TAG defined VERSION is overrided
ifneq ($(TRAVIS_TAG), )
VERSION := $(TRAVIS_TAG)
endif
# if we are not in master, and it's not a tag the push is disabled
ifneq ($(TRAVIS_BRANCH), master)
ifeq ($(TRAVIS_TAG), )
pushdisabled = "push disabled for non-master branches"
endif
endif
# if this is a pull request, the push is disabled
ifneq ($(TRAVIS_PULL_REQUEST), false)
pushdisabled = "push disabled for pull-requests"
endif
# IS_RELEASE is "true" if tag is semantic version and not a pre-release
IS_RELEASE := $(shell echo -n $(VERSION) | grep -q -E '^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$$' && echo "true" || true)
LATEST_GIT_TAG := $(shell git tag --sort=v:refname | tail -n1 | xargs echo -n)
#SBT
SBT = ./sbt ++$(SCALA_VERSION) -Dspark.version=$(SPARK_VERSION)
# Rules
all: clean build
clean:
$(SBT) clean
test:
$(SBT) test
build:
$(SBT) assembly
travis-test:
$(SBT) clean coverage test coverageReport scalastyle test:scalastyle
docker-build:
$(if $(pushdisabled),$(error $(pushdisabled)))
$(DOCKER_BUILD) -t $(call unescape_docker_tag,$(JUPYTER_IMAGE_VERSIONED)) .
docker-clean:
$(DOCKER_RMI) $(call unescape_docker_tag,$(JUPYTER_IMAGE_VERSIONED))
docker-push: docker-build
$(if $(pushdisabled),$(error $(pushdisabled)))
@if [ "$$DOCKER_USERNAME" != "" ]; then \
$(DOCKER_CMD) login -u="$$DOCKER_USERNAME" -p="$$DOCKER_PASSWORD"; \
fi;
$(DOCKER_PUSH) $(call unescape_docker_tag,$(JUPYTER_IMAGE_VERSIONED))
if [ "$$TRAVIS_TAG" != "" ] && [ $$IS_RELEASE ] && [ "$$LATEST_GIT_TAG" == "$$TRAVIS_TAG" ]; then \
$(DOCKER_TAG) $(call unescape_docker_tag,$(JUPYTER_IMAGE_VERSIONED)) \
$(call unescape_docker_tag,$(JUPYTER_IMAGE)):latest; \
$(DOCKER_PUSH) $(call unescape_docker_tag,$(JUPYTER_IMAGE):latest); \
fi;
maven-release:
$(SBT) clean publishSigned && \
$(SBT) sonatypeRelease