forked from janeczku/go-rancher-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
75 lines (59 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
DOCKER_USER := finboxio
DOCKER_IMAGE := rancher-conf
PLATFORM := linux
ARCH := amd64
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_REPO := $(shell git remote -v | grep origin | grep "(fetch)" | awk '{ print $$2 }')
GIT_DIRTY := $(shell git status --porcelain | wc -l)
GIT_DIRTY := $(shell if [[ "$(GIT_DIRTY)" -gt "0" ]]; then echo "yes"; else echo "no"; fi)
VERSION := $(shell git describe --abbrev=0)
VERSION_DIRTY := $(shell git log --pretty=format:%h $(VERSION)..HEAD | wc -l | tr -d ' ')
BUILD_COMMIT := $(shell if [[ "$(GIT_DIRTY)" == "yes" ]]; then echo $(GIT_COMMIT)+dev; else echo $(GIT_COMMIT); fi)
BUILD_COMMIT := $(shell echo $(BUILD_COMMIT) | cut -c1-12)
BUILD_VERSION := $(shell if [[ "$(VERSION_DIRTY)" -gt "0" ]]; then echo "$(VERSION)-$(BUILD_COMMIT)"; else echo $(VERSION); fi)
BUILD_VERSION := $(shell if [[ "$(VERSION_DIRTY)" -gt "0" ]] || [[ "$(GIT_DIRTY)" == "yes" ]]; then echo "$(BUILD_VERSION)-dev"; else echo $(BUILD_VERSION); fi)
BUILD_VERSION := $(shell if [[ "$(GIT_BRANCH)" != "master" ]]; then echo $(GIT_BRANCH)-$(BUILD_VERSION); else echo $(BUILD_VERSION); fi)
DOCKER_IMAGE := $(shell if [[ "$(DOCKER_REGISTRY)" ]]; then echo $(DOCKER_REGISTRY)/$(DOCKER_USER)/$(DOCKER_IMAGE); else echo $(DOCKER_USER)/$(DOCKER_IMAGE); fi)
DOCKER_VERSION := $(shell echo "$(DOCKER_IMAGE):$(BUILD_VERSION)")
DOCKER_LATEST := $(shell if [[ "$(VERSION_DIRTY)" -gt "0" ]] || [[ "$(GIT_DIRTY)" == "yes" ]]; then echo "$(DOCKER_IMAGE):dev"; else echo $(DOCKER_IMAGE):latest; fi)
help:
@echo "make build - build binary for the target environment"
@echo "make deps - install build dependencies"
@echo "make vet - run vet & gofmt checks"
@echo "make test - run tests"
@echo "make image - build release image"
@echo "make clean - remove build artifacts"
@echo "make info - print build details"
build: build-dir deps
go build -o ./build/rancher-conf ./cmd/rancher-conf
deps:
go mod download
vet:
scripts/vet
test: build
docker-compose -f test/docker-compose.yml -f test/docker-compose.local.yml up --build --force-recreate
clean:
go clean
rm -fr ./build
image:
docker build -t $(DOCKER_IMAGE):$(VERSION) -f Dockerfile .
build-dir:
@rm -rf build && mkdir build
docker.build: build
@docker build -t $(DOCKER_VERSION) -t $(DOCKER_LATEST) .
docker.push: docker.build
@docker push $(DOCKER_VERSION)
@docker push $(DOCKER_LATEST)
info:
@echo "git branch: $(GIT_BRANCH)"
@echo "git commit: $(GIT_COMMIT)"
@echo "git repo: $(GIT_REPO)"
@echo "git dirty: $(GIT_DIRTY)"
@echo "version: $(VERSION)"
@echo "commits since: $(VERSION_DIRTY)"
@echo "build commit: $(BUILD_COMMIT)"
@echo "build version: $(BUILD_VERSION)"
@echo "docker images: $(DOCKER_VERSION)"
@echo " $(DOCKER_LATEST)"
.PHONY: help build deps vet test clean image build-dir docker.build docker.push info