-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMakefile
188 lines (154 loc) · 6.53 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
include .bingo/Variables.mk
SHELL=/usr/bin/env bash -o pipefail
TMP_DIR := $(shell pwd)/tmp
BIN_DIR ?= $(TMP_DIR)/bin
LIB_DIR ?= $(TMP_DIR)/lib
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
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/token-refresher
THANOS ?= $(BIN_DIR)/thanos
THANOS_VERSION ?= 0.13.0
OBSERVATORIUM ?= $(BIN_DIR)/observatorium
UP ?= $(BIN_DIR)/up
HYDRA ?= $(BIN_DIR)/hydra
GOLANGCILINT ?= $(FIRST_GOPATH)/bin/golangci-lint
GOLANGCILINT_VERSION ?= v1.21.0
EMBEDMD ?= $(BIN_DIR)/embedmd
SHELLCHECK ?= $(BIN_DIR)/shellcheck
MEMCACHED ?= $(BIN_DIR)/memcached
default: token-refresher
all: clean lint test token-refresher
tmp/help.txt: token-refresher
./token-refresher --help 2>&1 | head -n -1 > tmp/help.txt || true
README.md: $(EMBEDMD) tmp/help.txt
$(EMBEDMD) -w README.md
token-refresher: vendor main.go $(wildcard *.go) $(wildcard */*.go)
CGO_ENABLED=0 GOEXPERIMENT=boringcrypto GOOS=$(OS) GOARCH=$(GOARCH) GO111MODULE=on GOPROXY=https://proxy.golang.org go build -mod vendor -a -ldflags '-s -w' -o $@ .
.PHONY: build
build: token-refresher
.PHONY: vendor
vendor: go.mod go.sum
go mod tidy
go mod vendor
.PHONY: format
format: $(GOLANGCILINT)
$(GOLANGCILINT) run --fix --enable-all -c .golangci.yml
.PHONY: go-fmt
go-fmt:
@fmt_res=$$(gofmt -d -s $$(find . -type f -name '*.go' -not -path './vendor/*' -not -path './jsonnet/vendor/*' -not -path '${TMP_DIR}/*')); 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: shellcheck
shellcheck: $(SHELLCHECK)
$(SHELLCHECK) $(shell find . -type f -name "*.sh" -not -path "*vendor*" -not -path "${TMP_DIR}/*")
.PHONY: lint
lint: $(GOLANGCILINT) vendor go-fmt shellcheck
$(GOLANGCILINT) run -v --enable-all -c .golangci.yml
.PHONY: test
test: build test-unit test-integration
.PHONY: test-unit
test-unit:
CGO_ENABLED=1 GO111MODULE=on go test -mod vendor -v -race -short ./...
.PHONY: test-integration
test-integration: build integration-test-dependencies
PATH=$(BIN_DIR):$(FIRST_GOPATH)/bin:$$PATH LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(LIB_DIR) ./test/integration.sh
.PHONY: clean
clean:
-rm tmp/help.txt
-rm -rf tmp/bin
-rm token-refresher
.PHONY: manifests
manifests: jsonnet/example/manifests
jsonnet/example/manifests: jsonnet/example/main.jsonnet $(JSONNET) $(GOJSONTOYAML)
-rm -rf jsonnet/example/manifests
-mkdir jsonnet/example/manifests
$(JSONNET) -m jsonnet/example/manifests jsonnet/example/main.jsonnet | xargs -I{} sh -c 'cat {} | $(GOJSONTOYAML) > {}.yaml' -- {}
find jsonnet/example/manifests -type f ! -name '*.yaml' -delete
.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: 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 \
.
.PHONY: integration-test-dependencies
integration-test-dependencies: $(THANOS) $(UP) $(HYDRA) $(OBSERVATORIUM)
$(BIN_DIR):
mkdir -p $(BIN_DIR)
$(LIB_DIR):
mkdir -p $@
$(THANOS): | $(BIN_DIR)
@echo "Downloading Thanos"
curl -L "https://github.com/thanos-io/thanos/releases/download/v$(THANOS_VERSION)/thanos-$(THANOS_VERSION).$$(go env GOOS)-$$(go env GOARCH).tar.gz" | tar --strip-components=1 -xzf - -C $(BIN_DIR)
$(OBSERVATORIUM): | vendor $(BIN_DIR)
go build -mod=vendor -o $@ github.com/observatorium/observatorium
$(UP): | vendor $(BIN_DIR)
go build -mod=vendor -o $@ github.com/observatorium/up/cmd/up
$(HYDRA): | vendor $(BIN_DIR)
@echo "Downloading Hydra"
curl -L "https://github.com/ory/hydra/releases/download/v1.7.4/hydra_1.7.4_linux_64-bit.tar.gz" | tar -xzf - -C $(BIN_DIR) hydra
$(EMBEDMD): | vendor $(BIN_DIR)
go build -mod=vendor -o $@ github.com/campoy/embedmd
$(GOLANGCILINT):
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCILINT_VERSION)/install.sh \
| sed -e '/install -d/d' \
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCILINT_VERSION)
$(SHELLCHECK): | $(BIN_DIR)
curl -sNL "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.$(OS).$(ARCH).tar.xz" | tar --strip-components=1 -xJf - -C $(BIN_DIR)