generated from falcosecurity/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
162 lines (131 loc) · 4.68 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2023 The Falco Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Ensure Make is run with bash shell as some syntax below is bash-specific
SHELL=/bin/bash -o pipefail
.DEFAULT_GOAL:=help
GOPATH := $(shell go env GOPATH)
GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
GOPROXY := $(shell go env GOPROXY)
ifeq ($(GOPROXY),)
GOPROXY := https://proxy.golang.org
endif
export GOPROXY
GO ?= go
DOCKER ?= docker
TEST_FLAGS ?= -v -race
# Directories.
TOOLS_DIR := tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
GO_INSTALL = tools/go_install.sh
# Binaries.
GOLANGCI_LINT_VER := v1.52.2
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
GIT_TAG ?= dirty-tag
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
GIT_HASH ?= $(shell git rev-parse HEAD)
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ'
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
endif
GIT_TREESTATE = "clean"
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
ifeq ($(DIFF), 1)
GIT_TREESTATE = "dirty"
endif
PKG = github.com/falcosecurity/falcosidekick-ui/configuration
LDFLAGS=-X $(PKG).GitVersion=$(GIT_VERSION) -X $(PKG).GitCommit=$(GIT_HASH) -X $(PKG).GitTreeState=$(GIT_TREESTATE) -X $(PKG).BuildDate=$(BUILD_DATE)
## --------------------------------------
## Dev
## --------------------------------------
.PHONY: server
server:
cd ./frontend && yarn serve
## --------------------------------------
## Docs
## --------------------------------------
.PHONY: docs
docs:
swag fmt
swag init
## --------------------------------------
## Build
## --------------------------------------
.PHONY: frontend
frontend:
cd frontend \
&& yarn install \
&& yarn build
.PHONY: falcosidekick-ui
falcosidekick-ui: frontend
$(GO) mod download
$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o falcosidekick-ui .
.PHONY: falcosidekick-ui-linux-amd64
falcosidekick-ui-linux-amd64: frontend
$(GO) mod download
GOOS=linux GOARCH=amd64 $(GO) build -gcflags all=-trimpath=/src -asmflags all=-trimpath=/src -a -installsuffix cgo -o falcosidekick-ui .
.PHONY: falcosidekick-ui-backend-only
falcosidekick-ui-backend-only:
$(GO) mod download
$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o falcosidekick-ui .
.PHONY: falcosidekick-ui-linux-amd64-backend-only
falcosidekick-ui-linux-amd64:
$(GO) mod download
GOOS=linux GOARCH=amd64 $(GO) build -gcflags all=-trimpath=/src -asmflags all=-trimpath=/src -a -installsuffix cgo -o falcosidekick-ui .
.PHONY: build-image
build-image:
$(DOCKER) build -t falcosecurity/falcosidekick-ui:latest . --no-cache
## --------------------------------------
## Test
## --------------------------------------
.PHONY: test
test:
$(GO) vet ./...
$(GO) test ${TEST_FLAGS} ./...
.PHONY: test-coverage
test-coverage:
$(GO) test ./outputs -count=1 -cover -v ./...
## --------------------------------------
## Linting
## --------------------------------------
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Lint codebase
$(GOLANGCI_LINT) run -v
lint-full: $(GOLANGCI_LINT) ## Run slower linters to detect possible issues
$(GOLANGCI_LINT) run -v --fast=false
## --------------------------------------
## Release
## --------------------------------------
.PHONY: goreleaser
goreleaser: ## Release using goreleaser
LDFLAGS="$(LDFLAGS)" goreleaser release --clean
.PHONY: goreleaser-snapshot
goreleaser-snapshot: ## Release snapshot using goreleaser
LDFLAGS="$(LDFLAGS)" goreleaser --snapshot --skip-sign --clean
## --------------------------------------
## Tooling Binaries
## --------------------------------------
$(GOLANGCI_LINT): ## Build golangci-lint from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
## --------------------------------------
## Cleanup / Verification
## --------------------------------------
.PHONY: clean
clean:
rm -rf hack/tools/bin
rm -rf dist