forked from avoidik/vault-unsealer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
78 lines (60 loc) · 1.84 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
GO_PKG = gitlab.jetstack.net/jetstack/vault-unsealer
REGISTRY := quay.io/jetstack
IMAGE_NAME := vault-unsealer
BUILD_TAG := build
IMAGE_TAGS := canary
BUILD_IMAGE_NAME := golang:1.10.4
GOPATH ?= /tmp/go
CI_COMMIT_TAG ?= unknown
CI_COMMIT_SHA ?= unknown
help:
# all - runs verify, build and docker_build targets
# test - runs go_test target
# build - runs go_build target
# verify - verifies generated files & scripts
# Util targets
##############
.PHONY: all build verify
all: verify build docker_build
build: go_build
verify: go_verify
.builder_image:
docker pull ${BUILD_IMAGE_NAME}
# Builder image targets
#######################
docker_%: .builder_image
docker run -it \
-v ${GOPATH}/src:/go/src \
-v $(shell pwd):/go/src/${GO_PKG} \
-w /go/src/${GO_PKG} \
-e GOPATH=/go \
${BUILD_IMAGE_NAME} \
/bin/sh -c "make $*"
# Docker targets
################
docker_build:
docker build -t $(REGISTRY)/$(IMAGE_NAME):$(BUILD_TAG) .
docker_push: docker_build
set -e; \
for tag in $(IMAGE_TAGS); do \
docker tag $(REGISTRY)/$(IMAGE_NAME):$(BUILD_TAG) $(REGISTRY)/$(IMAGE_NAME):$${tag} ; \
docker push $(REGISTRY)/$(IMAGE_NAME):$${tag}; \
done
# Go targets
#################
go_verify: go_fmt go_vet go_test
go_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w -X main.version=$(CI_COMMIT_TAG) -X main.commit=$(CI_COMMIT_SHA) -X main.date=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)' -o vault-unsealer_linux_amd64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -tags netgo -o vault-unsealer_windows_amd64
go_test:
go test $$(go list ./... | grep -v '/vendor/')
go_fmt:
@set -e; \
GO_FMT=$$(git ls-files *.go | grep -v 'vendor/' | xargs gofmt -d); \
if [ -n "$${GO_FMT}" ] ; then \
echo "Please run go fmt"; \
echo "$$GO_FMT"; \
exit 1; \
fi
go_vet:
go vet $$(go list ./... | grep -v '/vendor/')