-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
85 lines (67 loc) · 2.27 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
COMMIT_ID = $(shell git describe --abbrev=40 --always --exclude='*' --dirty=+ 2>/dev/null)
GIT_VERSION = $(shell git describe --match='v[0-9]*.[0-9]' --match='v[0-9]*.[0-9].[0-9]' 2>/dev/null || echo "(unset)")
# Image URL to use all building/pushing image targets
TAG ?= latest
IMG ?= quay.io/samba.org/svcwatch:$(TAG)
CONTAINER_BUILD_OPTS ?=
CONTAINER_CMD ?=
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD:=$(shell docker version >/dev/null 2>&1 && echo docker)
endif
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD:=$(shell podman version >/dev/null 2>&1 && echo podman)
endif
build:
go build -o bin/svcwatch -ldflags "-X main.Version=$(GIT_VERSION) -X main.CommitID=$(COMMIT_ID)" main.go
.PHONY: build
# Run go vet against code
vet:
go vet ./...
# Build the container image
image-build:
$(CONTAINER_CMD) build \
--build-arg=GIT_VERSION="$(GIT_VERSION)" \
--build-arg=COMMIT_ID="$(COMMIT_ID)" \
$(CONTAINER_BUILD_OPTS) $(CONTAINER_BUILD_OPTS) . -t ${IMG} -f Containerfile
.PHONY: image-build
.PHONY: image-build-buildah
image-build-buildah: build
cn=$$(buildah from registry.access.redhat.com/ubi8/ubi-minimal:latest) && \
buildah copy $$cn bin/svcwatch /svcwatch && \
buildah config --cmd='[]' $$cn && \
buildah config --entrypoint='["/svcwatch"]' $$cn && \
buildah commit $$cn $(IMG)
# Push the container image
container-push:
$(CONTAINER_CMD) push ${IMG}
.PHONY: check check-revive check-format
check: check-revive check-format vet
check-format:
! gofmt $(CHECK_GOFMT_FLAGS) . | sed 's,^,formatting error: ,' | grep 'go$$'
check-revive: revive
# revive's checks are configured using .revive.toml
# See: https://github.com/mgechev/revive
$(REVIVE) -config .revive.toml $$(go list ./... | grep -v /vendor/)
.PHONY: revive
revive:
ifeq (, $(shell command -v revive ;))
@echo "revive not found in PATH, checking in GOBIN ($(GOBIN))..."
ifeq (, $(shell command -v $(GOBIN)/revive ;))
@{ \
set -e ;\
echo "revive not found in GOBIN, getting revive..." ;\
REVIVE_TMP_DIR=$$(mktemp -d) ;\
cd $$REVIVE_TMP_DIR ;\
go mod init tmp ;\
go get github.com/mgechev/revive ;\
rm -rf $$REVIVE_TMP_DIR ;\
}
@echo "revive installed in GOBIN"
else
@echo "revive found in GOBIN"
endif
REVIVE=$(shell command -v $(GOBIN)/revive ;)
else
@echo "revive found in PATH"
REVIVE=$(shell command -v revive ;)
endif