Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
54 lines (44 loc) · 1.6 KB
/
Copy pathMakefile
File metadata and controls
54 lines (44 loc) · 1.6 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
# Not the checkout's directory name: .gitignore covers /mark, and the image
# is mark whatever the directory is called.
NAME = mark
# The tag HEAD is exactly at. Anywhere else the version is left unset, so that
# Go's pseudo-version names the commit rather than an older tag.
VERSION = $(shell git describe --tags --exact-match 2>/dev/null)
# The newest tag, which the image is tagged with.
RELEASE = $(shell git describe --tags --abbrev=0 2>/dev/null)
# "+dirty" when the tree has changes, untracked files too, as go build reports it.
DIRTY = $(if $(shell git status --porcelain 2>/dev/null),+dirty)
COMMIT = $(shell git rev-parse HEAD 2>/dev/null)$(DIRTY)
GO111MODULE = on
REMOTE = kovetskiy
version:
@echo $(RELEASE)
get:
go mod download
build:
@echo :: building go binary $(or $(VERSION),$(COMMIT))
CGO_ENABLED=0 go build -trimpath \
-ldflags "$(if $(VERSION),-X main.version=$(VERSION)) $(if $(COMMIT),-X main.commit=$(COMMIT))" \
-o $(NAME) \
./cmd/mark
test:
go test -race -coverprofile=profile.cov ./... -v
image:
@echo :: building image $(NAME):$(RELEASE)
@docker build -t $(NAME):$(RELEASE) -f Dockerfile \
--build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) .
docker tag $(NAME):$(RELEASE) $(NAME):latest
push:
$(if $(REMOTE),,$(error REMOTE is not set))
$(eval RELEASE ?= latest)
$(eval TAG ?= $(REMOTE)/$(NAME):$(RELEASE))
@echo :: pushing image $(TAG)
@docker tag $(NAME):$(RELEASE) $(TAG)
@docker push $(TAG)
@docker tag $(NAME):$(RELEASE) $(REMOTE)/$(NAME):latest
@docker push $(REMOTE)/$(NAME):latest
release: image push
git tag -f $(RELEASE)
git push --tags
clean:
rm -rf $(NAME)