-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
71 lines (56 loc) · 1.46 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
NAME := acs-cve-prom-exporter
REPO := quay.io/app-sre/$(NAME)
TAG := $(shell git rev-parse --short HEAD)
PKGS := $(shell go list ./... | grep -v -E '/vendor/|/test')
CONTAINER_ENGINE ?= $(shell which podman >/dev/null 2>&1 && echo podman || echo docker)
ifneq (,$(wildcard $(CURDIR)/.docker))
DOCKER_CONF := $(CURDIR)/.docker
else
DOCKER_CONF := $(HOME)/.docker
endif
.PHONY: all
all: test image
.PHONY: clean
clean:
# Remove all files and directories ignored by git.
git clean -Xfd .
############
# Building #
############
.PHONY: build
build:
CGO_ENABLED=0 go build -o $(NAME) .
.PHONY: image
image:
ifeq ($(CONTAINER_ENGINE), podman)
@DOCKER_BUILDKIT=1 $(CONTAINER_ENGINE) build --no-cache -t $(REPO):latest . --progress=plain
else
@DOCKER_BUILDKIT=1 $(CONTAINER_ENGINE) --config=$(DOCKER_CONF) build --no-cache -t $(REPO):latest . --progress=plain
endif
@$(CONTAINER_ENGINE) tag $(REPO):latest $(REPO):$(TAG)
.PHONY: image-push
image-push:
$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(REPO):$(TAG)
$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(REPO):latest
##############
# Formatting #
##############
.PHONY: format
format: go-fmt
.PHONY: go-fmt
go-fmt:
go fmt $(PKGS)
###########
# Testing #
###########
.PHONY: vet
vet:
go vet ./...
.PHONY: test
test: vet test-unit
.PHONY: test-unit
test-unit:
go test -race -short $(PKGS) -count=1
.PHONY: container-test
container-test:
$(CONTAINER_ENGINE) build --target test -t $(REPO):pr-$(TAG) -f Dockerfile .