-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
95 lines (75 loc) · 2.21 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
NAME := terraform-repo-executor
REPO := quay.io/app-sre/$(NAME)
REVIVE_VERSION := v1.3.7
STATICCHECK_VERSION := 2023.1.7
TAG := $(shell git rev-parse --short HEAD)
PKGS := $(shell go list ./... | grep -v -E '/vendor/|/test')
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
CONTAINER_ENGINE ?= $(shell which podman >/dev/null 2>&1 && echo podman || echo docker)
GOOS := $(shell go env GOOS)
CTR_STRUCTURE_IMG := quay.io/app-sre/container-structure-test:latest
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: vet
CGO_ENABLED=0 GOOS=$(GOOS) go build -o $(NAME) .
.PHONY: image
image:
ifeq ($(CONTAINER_ENGINE), podman)
@DOCKER_BUILDKIT=1 $(CONTAINER_ENGINE) build -t $(REPO):latest . --progress=plain
else
@DOCKER_BUILDKIT=1 $(CONTAINER_ENGINE) --config=$(DOCKER_CONF) build -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: lint
lint: revive staticcheck
.PHONY: revive
revive:
go install github.com/mgechev/revive@$(REVIVE_VERSION)
go run github.com/mgechev/revive@$(REVIVE_VERSION) -config revive.toml -set_exit_status ./...
.PHONY: staticcheck
staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION)
go run honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION) ./...
test: test-app test-container-image
.PHONY: vet
vet: test-app
go vet ./...
.PHONY: test-app
test-app:
CGO_ENABLED=0 GOOS=$(GOOS) go test -v ./...
.PHONY: test-container-image
test-container-image: image
@CONTAINER_ENGINE=$(CONTAINER_ENGINE) \
CTR_STRUCTURE_IMG=$(CTR_STRUCTURE_IMG) \
CURDIR=$(CURDIR) \
IMAGE_NAME=$(REPO) \
IMAGE_TAG=$(TAG) \
$(CURDIR)/run-test-container-image.sh