-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
77 lines (61 loc) · 1.87 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
.PHONY: all push container clean container-name container-latest push-latest
BIN := drae
PROJECT := drae
REPO := github.com/squat/$(PROJECT)
REGISTRY ?= index.docker.io
IMAGE ?= squat/$(PROJECT)
TAG := $(shell git describe --abbrev=0 --tags HEAD 2>/dev/null)
COMMIT := $(shell git rev-parse HEAD)
VERSION := $(COMMIT)
ifneq ($(TAG),)
ifeq ($(COMMIT), $(shell git rev-list -n1 $(TAG)))
VERSION := $(TAG)
endif
endif
DIRTY := $(shell test -z "$$(git diff --shortstat 2>/dev/null)" || echo -dirty)
VERSION := $(VERSION)$(DIRTY)
LD_FLAGS := -ldflags \"-X $(REPO)/pkg/version.Version=$(VERSION)\"
SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
BUILD_IMAGE ?= golang:1.9.1-alpine
all: build
build: bin/$(BIN)
bin:
@mkdir -p bin
bin/$(BIN): bin $(SRC) glide.yaml
@echo "building: $@"
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/go/src/$(REPO) \
-v $$(pwd)/bin:/go/bin \
-w /go/src/$(REPO) \
$(BUILD_IMAGE) \
/bin/sh -c " \
GOOS=linux \
CGO_ENABLED=0 \
go build -o bin/$(BIN) \
$(LD_FLAGS) \
./cmd/$(BIN)/... \
"
container: .container-$(VERSION) container-name
.container-$(VERSION): bin/$(BIN) Dockerfile
@docker build -t $(IMAGE):$(VERSION) .
@docker images -q $(IMAGE):$(VERSION) > $@
container-latest: .container-$(VERSION)
@docker tag $(IMAGE):$(VERSION) $(IMAGE):latest
@echo "container: $(IMAGE):latest"
container-name:
@echo "container: $(IMAGE):$(VERSION)"
push: .push-$(VERSION) push-name
.push-$(VERSION): .container-$(VERSION)
@docker push $(REGISTRY)/$(IMAGE):$(VERSION)
@docker images -q $(IMAGE):$(VERSION) > $@
push-latest: container-latest
@docker push $(REGISTRY)/$(IMAGE):latest
@echo "pushed: $(IMAGE):latest"
push-name:
@echo "pushed: $(IMAGE):$(VERSION)"
clean: container-clean bin-clean
container-clean:
rm -rf .container-* .push-*
bin-clean:
rm -rf bin