-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
142 lines (120 loc) · 4.6 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
include .bingo/Variables.mk
SHELL=/usr/bin/env bash -o pipefail
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
OS ?= $(shell uname -s | tr '[A-Z]' '[a-z]')
ARCH ?= $(shell uname -m)
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/rules-objstore
BIN_NAME ?= rules-objstore
default: $(BIN_NAME)
all: clean lint test $(BIN_NAME)
.PHONY: deps
deps: go.mod go.sum
go mod tidy
go mod download
go mod verify
$(BIN_NAME): deps main.go $(wildcard *.go) $(wildcard */*.go)
CGO_ENABLED=0 GO111MODULE=on GOPROXY=https://proxy.golang.org go build -a -ldflags '-s -w' -o $@ .
.PHONY: build
build: $(BIN_NAME)
.PHONY: format
format: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --fix --enable-all -c .golangci.yml
.PHONY: go-fmt
go-fmt: $(GOFUMPT)
@fmt_res=$$($(GOFUMPT) -l -w $$(find . -type f -name '*.go')); 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) go-fmt
$(GOLANGCI_LINT) run -v --enable-all -c .golangci.yml
.PHONY: test
test: build test-unit
.PHONY: test-unit
test-unit:
CGO_ENABLED=1 GO111MODULE=on go test -v -race -short ./...
.PHONY: test-e2e
test-e2e: container-test
CGO_ENABLED=1 GO111MODULE=on go test -v -race -short --tags integration ./test/e2e
.PHONY: clean
clean:
-rm $(BIN_NAME)
.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
container: Dockerfile
@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: container-test
container-test: # Use 'shortcut' to build test image if on Linux, otherwise full build.
ifeq ($(OS), linux)
container-test: build
@docker build \
-f Dockerfile.e2e-test \
-t $(DOCKER_REPO):local_e2e_test .
else
container-test:
@docker build \
-f Dockerfile \
-t $(DOCKER_REPO):local_e2e_test .
endif