This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
73 lines (58 loc) · 2.45 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
.PHONY: build build-alpine clean test help default
BIN_NAME=rubban
VERSION := $(shell git describe --exact-match --tags 2> /dev/null || git describe --tags )
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+dirty" || true)
GIT_COMMIT=$(shell git rev-parse --short HEAD)${GIT_DIRTY}
BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
IMAGE_NAME := sherifabdlnaby/rubban
FLAGS := -X github.com/sherifabdlnaby/rubban/version.GitCommit=${GIT_COMMIT} -X github.com/sherifabdlnaby/rubban/version.Version=${VERSION} -X github.com/sherifabdlnaby/rubban/version.BuildDate=${BUILD_DATE}
default: run
help:
@echo 'Management commands for rubban:'
@echo
@echo 'Usage:'
@echo ' make build Compile the project.'
@echo ' make run Compile and run the project.'
@echo ' make build-alpine Compile optimized for alpine linux.'
@echo ' make package Build final docker image with just the go binary inside'
@echo ' make tag Tag image created by package with latest, git commit and version'
@echo ' make test Run tests on a compiled project.'
@echo ' make push Push tagged images to registry'
@echo ' make clean Clean the directory tree.'
@echo
build:
@echo "building ${BIN_NAME} ${VERSION}"
@echo "GOPATH=${GOPATH}"
go build -ldflags "${FLAGS}" -o bin/${BIN_NAME}
run:
make build
bin/${BIN_NAME}
build-alpine:
@echo "building ${BIN_NAME} ${VERSION}"
@echo "GOPATH=${GOPATH}"
GOOS=linux GOARCH=amd64 go build -ldflags ' -w -s ${FLAGS} ' -o bin/${BIN_NAME}
build-image:
@echo "building image ${BIN_NAME} ${VERSION} $(GIT_COMMIT)"
docker build --build-arg VERSION=${VERSION} \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE_NAME):local .
tag:
@echo "Tagging: latest ${VERSION} $(GIT_COMMIT)"
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):$(GIT_COMMIT)
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):${VERSION}
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):latest
tag-image:
@echo "Tagging: latest ${VERSION}"
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):${VERSION}
docker tag $(IMAGE_NAME):local $(IMAGE_NAME):latest
push-image: tag-image
@echo "Pushing docker image to registry: latest ${VERSION} $(GIT_COMMIT)"
docker push $(IMAGE_NAME):${VERSION}
docker push $(IMAGE_NAME):latest
clean:
@test ! -e bin/${BIN_NAME} || rm bin/${BIN_NAME}
test:
go test -race ./...
lint:
golangci-lint run --print-issued-lines --fix