forked from open-component-model/ocm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
167 lines (129 loc) · 5.58 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
163
164
165
166
167
# SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
#
# SPDX-License-Identifier: Apache-2.0
NAME := ocm
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
GITHUBORG ?= open-component-model
OCMREPO ?= ghcr.io/$(GITHUBORG)/ocm
VERSION := $(shell go run pkg/version/generate/release_generate.go print-rc-version $(CANDIDATE))
EFFECTIVE_VERSION := $(VERSION)+$(shell git rev-parse HEAD)
GIT_TREE_STATE := $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] && echo clean || echo dirty)
COMMIT := $(shell git rev-parse --verify HEAD)
CONTROLLER_TOOLS_VERSION ?= v0.9.0
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
CREDS ?=
OCM := go run $(REPO_ROOT)/cmds/ocm $(CREDS)
CTF_TYPE ?= tgz
GEN := $(REPO_ROOT)/gen
SOURCES := $(shell go list -f '{{$$I:=.Dir}}{{range .GoFiles }}{{$$I}}/{{.}} {{end}}' ./... )
GOPATH := $(shell go env GOPATH)
NOW := $(shell date -u +%FT%T%z)
BUILD_FLAGS := "-s -w \
-X github.com/open-component-model/ocm/pkg/version.gitVersion=$(EFFECTIVE_VERSION) \
-X github.com/open-component-model/ocm/pkg/version.gitTreeState=$(GIT_TREE_STATE) \
-X github.com/open-component-model/ocm/pkg/version.gitCommit=$(COMMIT) \
-X github.com/open-component-model/ocm/pkg/version.buildDate=$(NOW)"
COMPONENTS ?= ocmcli helminstaller demoplugin ecrplugin helmdemo subchartsdemo
build: ${SOURCES}
mkdir -p bin
CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/ocm ./cmds/ocm
CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/helminstaller ./cmds/helminstaller
CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/demo ./cmds/demoplugin
CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/ecrplugin ./cmds/ecrplugin
.PHONY: install-requirements
install-requirements:
@make -C hack $@
.PHONY: prepare
prepare: generate format generate-deepcopy build test check
.PHONY: format
format:
@$(REPO_ROOT)/hack/format.sh $(REPO_ROOT)/pkg $(REPO_ROOT)/cmds/ocm $(REPO_ROOT)/cmds/helminstaller $(REPO_ROOT)/cmds/ecrplugin $(REPO_ROOT)/cmds/demoplugin
.PHONY: check
check:
@$(REPO_ROOT)/hack/check.sh --golangci-lint-config=./.golangci.yaml $(REPO_ROOT)/cmds/ocm $(REPO_ROOT)/cmds/helminstaller/... $(REPO_ROOT)/cmds/ecrplugin/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/pkg/...
.PHONY: force-test
force-test:
@go test --count=1 $(REPO_ROOT)/cmds/ocm $(REPO_ROOT)/cmds/helminstaller $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/ecrplugin/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/pkg/...
.PHONY: test
test:
@echo "> Test"
@go test ./examples/lib/... $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/pkg/...
.PHONY: generate
generate:
@$(REPO_ROOT)/hack/generate.sh $(REPO_ROOT)/pkg... $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/helminst/...
.PHONY: generate-deepcopy
generate-deepcopy: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths=./pkg/contexts/ocm/compdesc/versions/... paths=./pkg/contexts/ocm/compdesc/meta/...
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: verify
verify: check
.PHONY: all
all: generate format test verify build
.PHONY: install
install:
@EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) ./hack/install.sh
.PHONY: cross-build
cross-build:
@EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) ./hack/cross-build.sh
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
.PHONY: info
info:
@if [ -n "$(CANDIDATE)" ]; then echo "CANDIDATE = $(CANDIDATE)"; fi
@echo "VERSION = $(VERSION)"
@echo "EFFECTIVE = $(EFFECTIVE_VERSION)"
@echo "COMMIT = $(COMMIT)"
@echo "GIT_TREE_STATE= $(GIT_TREE_STATE)"
@echo "COMPONENTS = $(COMPONENTS)"
.PHONY: generate-license
generate-license:
for f in $(shell find . -name "*.go" -o -name "*.sh"); do \
reuse addheader -r --copyright="SAP SE or an SAP affiliate company and Open Component Model contributors." --license="Apache-2.0" $$f --skip-unrecognised; \
done
$(GEN)/.exists:
@mkdir -p $(GEN)
@touch $@
.PHONY: components
components: $(GEN)/.comps
$(GEN)/.comps: $(GEN)/.exists
@rm -rf "$(GEN)"/ctf
@for i in $(COMPONENTS); do \
echo "building component $$i..."; \
(cd components/$$i; make ctf;); \
done
@touch $@
.PHONY: ctf
ctf: $(GEN)/ctf
$(GEN)/ctf: $(GEN)/.exists $(GEN)/.comps
@rm -rf "$(GEN)"/ctf
@for i in $(COMPONENTS); do \
echo "transfering component $$i..."; \
echo $(OCM) transfer cv --type $(CTF_TYPE) -V $(GEN)/$$i/ctf $(GEN)/ctf; \
$(OCM) transfer cv --type $(CTF_TYPE) -V $(GEN)/$$i/ctf $(GEN)/ctf; \
done
@touch $@
.PHONY: push
push: $(GEN)/ctf $(GEN)/.push.$(NAME)
$(GEN)/.push.$(NAME): $(GEN)/ctf
$(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO)
@touch $@
.PHONY: plain-push
plain-push: $(GEN)
$(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO)
.PHONY: plain-ctf
plain-ctf: $(GEN)
@rm -rf "$(GEN)"/ctf
@for i in $(COMPONENTS); do \
echo "transfering component $$i..."; \
echo $(OCM) transfer cv --type $(CTF_TYPE) -V $(GEN)/$$i/ctf $(GEN)/ctf; \
$(OCM) transfer cv --type $(CTF_TYPE) -V $(GEN)/$$i/ctf $(GEN)/ctf; \
done
.PHONY: clean
clean:
rm -rf "$(GEN)"