-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMakefile
162 lines (136 loc) · 5.31 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
include .bingo/Variables.mk
BIN_DIR ?= ./tmp/bin
THANOS=$(BIN_DIR)/thanos
LOKI ?= $(BIN_DIR)/loki
LOKI_VERSION ?= 1.5.0
OS ?= $(shell uname -s | tr '[A-Z]' '[a-z]')
ARCH ?= $(shell uname -m)
GOARCH ?= $(shell go env GOARCH)
VERSION := $(strip $(shell [ -d .git ] && git describe --always --tags --dirty))
BUILD_DATE := $(shell date -u +"%Y-%m-%d")
BUILD_TIMESTAMP := $(shell date -u +"%Y-%m-%dT%H:%M:%S%Z")
VCS_BRANCH := $(strip $(shell git rev-parse --abbrev-ref HEAD))
VCS_REF := $(strip $(shell [ -d .git ] && git rev-parse --short HEAD))
DOCKER_REPO ?= quay.io/observatorium/up
EXAMPLES := examples
MANIFESTS := ${EXAMPLES}/manifests
all: build generate validate
build: up
.PHONY: up
up: vendor
CGO_ENABLED=0 go build -v -ldflags '-w -extldflags '-static'' ./cmd/up
.PHONY: generate
generate: jsonnet-fmt ${MANIFESTS} README.md
.PHONY: validate
validate: $(KUBEVAL) $(MANIFESTS)
$(KUBEVAL) --ignore-missing-schemas $(MANIFESTS)/*.yaml
.PHONY: vendor
vendor: go.mod go.sum
go mod tidy
go mod vendor
.PHONY: go-fmt
go-fmt:
@fmt_res=$$(gofmt -d -s $$(find . -type f -name '*.go' -not -path './vendor/*' -not -path './jsonnet/vendor/*')); if [ -n "$$fmt_res" ]; then printf '\nGofmt found style issues. Please check the reported issues\nand fix them if necessary before submitting the code for review:\n\n%s' "$$fmt_res"; exit 1; fi
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v -c .golangci.yml
.PHONY: container-dev
container-dev:
@docker build \
--build-arg BUILD_DATE="$(BUILD_TIMESTAMP)" \
--build-arg VERSION="$(VERSION)" \
--build-arg VCS_REF="$(VCS_REF)" \
--build-arg VCS_BRANCH="$(VCS_BRANCH)" \
--build-arg DOCKERFILE_PATH="/Dockerfile" \
-t $(DOCKER_REPO):$(VCS_BRANCH)-$(BUILD_DATE)-$(VERSION) \
.
docker tag $(DOCKER_REPO):$(VCS_BRANCH)-$(BUILD_DATE)-$(VERSION) $(DOCKER_REPO):latest
.PHONY: clean
clean:
-rm tmp/help.txt
-rm ./up
tmp/help.txt: clean build
mkdir -p tmp
-./up --help >tmp/help.txt 2>&1
.PHONY: README.md
README.md: $(EMBEDMD) tmp/help.txt
$(EMBEDMD) -w README.md
.PHONY: test
test:
CGO_ENABLED=1 go test -v -race ./...
.PHONY: test-integration
test-integration: build test/integration.sh | $(THANOS) $(LOKI)
PATH=$$PATH:$$(pwd)/$(BIN_DIR) ./test/integration.sh
.PHONY: ${MANIFESTS}
${MANIFESTS}: jsonnet/main.jsonnet jsonnet/*.libsonnet $(JSONNET) $(GOJSONTOYAML)
@rm -rf ${MANIFESTS}
@mkdir -p ${MANIFESTS}
$(JSONNET) -J jsonnet/vendor -m ${MANIFESTS} jsonnet/main.jsonnet | xargs -I{} sh -c 'cat {} | $(GOJSONTOYAML) > {}.yaml && rm -f {}' -- {}
JSONNET_SRC = $(shell find . -name 'vendor' -prune -o -name 'examples/vendor' -prune -o -name 'tmp' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print)
JSONNETFMT_CMD := $(JSONNETFMT) -n 2 --max-blank-lines 2 --string-style s --comment-style s
.PHONY: jsonnet-fmt
jsonnet-fmt: | $(JSONNETFMT)
PATH=$$PATH:$(BIN_DIR):$(FIRST_GOPATH)/bin echo ${JSONNET_SRC} | xargs -n 1 -- $(JSONNETFMT_CMD) -i
.PHONY: format
format: $(GOLANGCI_LINT) go-fmt jsonnet-fmt
$(GOLANGCI_LINT) run --fix -c .golangci.yml
$(BIN_DIR):
mkdir -p $(BIN_DIR)
$(THANOS): $(BIN_DIR)
wget -O ./tmp/thanos.tar.gz https://github.com/thanos-io/thanos/releases/download/v0.11.0/thanos-0.11.0.linux-amd64.tar.gz
tar xvfz ./tmp/thanos.tar.gz -C ./tmp
mv ./tmp/thanos-0.11.0.linux-amd64/thanos $@
$(LOKI): $(BIN_DIR)
loki_pkg="loki-$$(go env GOOS)-$$(go env GOARCH)" && \
cd $(BIN_DIR) && curl -O -L "https://github.com/grafana/loki/releases/download/v$(LOKI_VERSION)/$$loki_pkg.zip" && \
unzip $$loki_pkg.zip && \
mv $$loki_pkg loki && \
rm $$loki_pkg.zip
.PHONY: container-build
container-build:
git update-index --refresh
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-to type=local,dest=./.buildxcache/ \
--build-arg BUILD_DATE="$(BUILD_TIMESTAMP)" \
--build-arg VERSION="$(VERSION)" \
--build-arg VCS_REF="$(VCS_REF)" \
--build-arg VCS_BRANCH="$(VCS_BRANCH)" \
--build-arg DOCKERFILE_PATH="/Dockerfile" \
-t $(DOCKER_REPO):$(VCS_BRANCH)-$(BUILD_DATE)-$(VERSION) \
-t $(DOCKER_REPO):latest \
.
.PHONY: container-build-push
container-build-push:
git update-index --refresh
@docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
--cache-to type=local,dest=./.buildxcache/ \
--build-arg BUILD_DATE="$(BUILD_TIMESTAMP)" \
--build-arg VERSION="$(VERSION)" \
--build-arg VCS_REF="$(VCS_REF)" \
--build-arg VCS_BRANCH="$(VCS_BRANCH)" \
--build-arg DOCKERFILE_PATH="/Dockerfile" \
-t $(DOCKER_REPO):$(VCS_BRANCH)-$(BUILD_DATE)-$(VERSION) \
-t $(DOCKER_REPO):latest \
.
.PHONY: conditional-container-build-push
conditional-container-build-push:
build/conditional-container-push.sh $(DOCKER_REPO):$(VCS_BRANCH)-$(BUILD_DATE)-$(VERSION)
.PHONY: container-release-build-push
container-release-build-push: VERSION_TAG = $(strip $(shell [ -d .git ] && git tag --points-at HEAD))
container-release-build-push: container-build-push
# https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---points-atltobjectgt
@docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
--cache-from type=local,src=./.buildxcache/ \
--build-arg BUILD_DATE="$(BUILD_TIMESTAMP)" \
--build-arg VERSION="$(VERSION)" \
--build-arg VCS_REF="$(VCS_REF)" \
--build-arg VCS_BRANCH="$(VCS_BRANCH)" \
--build-arg DOCKERFILE_PATH="/Dockerfile" \
-t $(DOCKER_REPO):$(VERSION_TAG) \
-t $(DOCKER_REPO):latest \
.