-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
79 lines (68 loc) · 2.64 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
REV ?= $$(git rev-parse --short=8 HEAD)
BRANCH ?= $$(git rev-parse --abbrev-ref HEAD | tr / _)
DEFAULT_BRANCH = dev
EXECUTABLE = romulusd
IMAGE = romulusd
REMOTE_REPO = quay.io/timeline_labs/romulusd
LDFLAGS = "-s -X main.SHA=$(REV)"
TEST_COMMAND = godep go test
.PHONY: all container dep-save dep-restore test test-verbose build build-image install publish
all: test build install
container: build-image publish
help:
@echo "Available targets:"
@echo ""
@echo " all : Run targets test, build, install (default)"
@echo " container : Run targets build-image publish"
@echo ""
@echo " build : Build binary (go build)"
@echo " build-image : Build binary and container image"
@echo " dep-restore : Restore dependencies (godep restore)"
@echo " dep-save : Save dependencies (godep save)"
@echo " install : Install binary (go install)"
@echo " publish : Publish container image to remote repo"
@echo " test : Run package tests"
@echo " test-verbose : Run package tests with verbose output"
dep-save:
@echo "--> Saving dependencies to ./Godeps"
@godep save -t -v ./...
dep-restore:
@echo "--> Restoring dependencies from ./Godeps"
@godep restore -v
test:
@echo "--> Running all tests"
@echo ""
@$(TEST_COMMAND) ./...
test-verbose:
@echo "--> Running all tests (verbose output)"
@echo ""
@$(TEST_COMMAND) -test.v ./...
build:
@echo "--> Building $(EXECUTABLE) with ldflags '$(LDFLAGS)'"
@godep go build -ldflags $(LDFLAGS) -o bin/$(EXECUTABLE) *.go
build-image:
@echo "--> Building $(EXECUTABLE)-linux with ldflags '$(LDFLAGS)'"
@GOOS=linux CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags $(LDFLAGS) -o bin/$(EXECUTABLE)-linux *.go
@echo "--> Building docker image '$(IMAGE)'"
@docker build -t $(IMAGE) .
publish:
@echo "--> Publishing $(EXECUTABLE) to $(REMOTE_REPO)"
@echo "--> Tagging with '$(BRANCH)' and pushing"
@docker rmi $(REMOTE_REPO):$(BRANCH) >/dev/null 2>&1 || true
@docker tag $(IMAGE) $(REMOTE_REPO):$(BRANCH)
@docker push $(REMOTE_REPO):$(BRANCH)
@docker rmi $(REMOTE_REPO):$(BRANCH)
@echo "--> Tagging with '$(REV)' and pushing"
@docker rmi $(REMOTE_REPO):$(REV) >/dev/null 2>&1 || true
@docker tag $(IMAGE) $(REMOTE_REPO):$(REV)
@docker push $(REMOTE_REPO):$(REV)
@docker rmi $(REMOTE_REPO):$(REV)
@if [ "$(BRANCH)" = "$(DEFAULT_BRANCH)" ]; then \
docker rmi $(REMOTE_REPO):latest >/dev/null 2>&1 || true ;\
docker tag $(IMAGE) $(REMOTE_REPO):latest ;\
docker push $(REMOTE_REPO):latest ;\
docker rmi $(REMOTE_REPO):latest ;\
fi
install:
@echo "--> Installing $(EXECUTABLE) with ldflags '$(LDFLAGS)'"
@godep go install -ldflags $(LDFLAGS) $(BINARY)