-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
100 lines (83 loc) · 2.71 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
############
# DEFAULTS #
############
GO ?= go
BUILD ?= build
IMAGE_TAG ?= 2.0.0
#############
# VARIABLES #
#############
GIT_SHA := $(shell git rev-parse HEAD)
KOCACHE ?= /tmp/ko-cache
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
REGISTRY ?= ghcr.io
OWNER ?= kyverno
KO_REGISTRY := ko.local
LD_FLAGS := "-s -w"
LOCAL_PLATFORM := linux/$(GOARCH)
PLATFORMS := all
IMAGE := policy-reporter-ui
REPO := $(REGISTRY)/$(OWNER)/$(IMAGE)
KO_TAGS := $(shell git rev-parse --short HEAD)
COMMA := ,
ifndef VERSION
KO_TAGS := $(shell git rev-parse --short HEAD)
else
KO_TAGS := $(VERSION)
endif
#########
# TOOLS #
#########
TOOLS_DIR := $(PWD)/.tools
KO := $(TOOLS_DIR)/ko
KO_VERSION := v0.16.0
GCI := $(TOOLS_DIR)/gci
GCI_VERSION := v0.13.5
GOFUMPT := $(TOOLS_DIR)/gofumpt
GOFUMPT_VERSION := v0.7.0
$(KO):
@echo Install ko... >&2
@GOBIN=$(TOOLS_DIR) go install github.com/google/ko@$(KO_VERSION)
$(GCI):
@echo Install gci... >&2
@GOBIN=$(TOOLS_DIR) go install github.com/daixiang0/gci@$(GCI_VERSION)
$(GOFUMPT):
@echo Install gofumpt... >&2
@GOBIN=$(TOOLS_DIR) go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
.PHONY: gci
gci: $(GCI)
@echo "Running gci"
@$(GCI) write -s standard -s default -s "prefix(github.com/kyverno/policy-reporter-ui)" ./backend
.PHONY: gofumpt
gofumpt: $(GOFUMPT)
@echo "Running gofumpt"
@$(GOFUMPT) -w ./backend
.PHONY: fmt
fmt: gci gofumpt
###########
# CODEGEN #
###########
.PHONY: build-frontend
build-frontend:
@echo Build frontend with bun... >&2
@cd frontend && bun install && bun run generate
.PHONY: ko-build
ko-build: $(KO) build-frontend
@echo Build image with ko... >&2
@rm -rf backend/kodata && mkdir backend/kodata
@cp -r frontend/dist backend/kodata/ui
@cp -r backend/templates backend/kodata/templates
@cd backend && LDFLAGS='$(LD_FLAGS)' KOCACHE=$(KOCACHE) KO_DOCKER_REPO=$(KO_REGISTRY) \
$(KO) build . --tags=$(KO_TAGS) --platform=$(LOCAL_PLATFORM)
.PHONY: ko-login
ko-login: $(KO)
@$(KO) login $(REGISTRY) --username "$(REGISTRY_USERNAME)" --password "$(REGISTRY_PASSWORD)"
.PHONY: ko-publish
ko-publish: ko-login
@echo Publishing image "$(KO_TAGS)" with ko... >&2
@rm -rf backend/kodata && mkdir backend/kodata
@cp -r frontend/dist backend/kodata/ui
@cp -r backend/templates backend/kodata/templates
@cd backend && LDFLAGS='$(LD_FLAGS)' KOCACHE=$(KOCACHE) KO_DOCKER_REPO=$(REPO) \
$(KO) build . --bare --tags=$(KO_TAGS) --push --platform=$(PLATFORMS)