-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
67 lines (50 loc) · 2.09 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
# Set shell to bash
SHELL := /bin/bash
# Current version of the project.x`
VERSION ?= v0.0.3
# This repo's root import path (under GOPATH).
ROOT := github.com/cd1989/harbor-cleaner
# A list of all packages.
PKGS := $(shell go list ./... | grep -v /vendor | grep -v /test)
# Git commit sha.
COMMIT := $(shell git rev-parse --short HEAD)
# Project main package location (can be multiple ones).
CMD_DIR := ./cmd
# Project output directory.
OUTPUT_DIR := ./bin
# Build direcotory.
BUILD_DIR := ./build
# Golang standard bin directory.
BIN_DIR := $(GOPATH)/bin
GOMETALINTER := $(BIN_DIR)/gometalinter
UNAME := $(shell uname)
# All targets.
.PHONY: lint test build
lint: $(GOMETALINTER)
golangci-lint run --disable=gosimple --deadline=300s ./pkg/... ./cmd/...
$(GOMETALINTER):
go get -u github.com/alecthomas/gometalinter
gometalinter --install &> /dev/null
test:
go test $(PKGS)
build-local:
CGO_ENABLED=0 GOARCH=amd64 go build -i -v -o ./bin/harbor-cleaner -ldflags "-s -w" ./cmd
build:
docker run --rm \
-v $(PWD):/go/src/$(ROOT) \
-w /go/src/$(ROOT) \
-e GOOS=linux \
-e GOARCH=amd64 \
-e GOPATH=/go \
-e CGO_ENABLED=0 \
golang:1.10-alpine3.8 \
go build -i -v -o $(OUTPUT_DIR)/cleaner \
-ldflags "-s -w -X $(ROOT)/pkg/version.VERSION=$(VERSION) \
-X $(ROOT)/pkg/version.COMMIT=$(COMMIT) \
-X $(ROOT)/pkg/version.REPOROOT=$(ROOT)" \
$(CMD_DIR);
image: build
docker build -t k8sdevops/harbor-cleaner:$(VERSION) -f ./build/Dockerfile .
.PHONY: clean
clean:
-rm -vrf ${OUTPUT_DIR}