-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (156 loc) · 5.08 KB
/
Makefile
File metadata and controls
180 lines (156 loc) · 5.08 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
PLUGIN_PREFIX := openbao-plugin
PLUGINS := $(subst /,-,$(wildcard auth/* secrets/* databases/*))
PLUGIN := $(firstword $(PLUGINS))
REGISTRY := ghcr.io/openbao
VERSION := $(shell git describe --tags --match "$(PLUGIN)-*" | cut -d- -f3-)
TARGETS := \
linux_amd64_v1 \
linux_arm_6 \
linux_arm64_v8 \
linux_ppc64le \
linux_riscv64_rva20u64 \
linux_s390x \
darwin_amd64_v1 \
darwin_arm64_v8 \
dragonfly_amd64_v1 \
freebsd_amd64_v1 \
freebsd_arm_6 \
freebsd_arm64_v8 \
illumos_amd64_v1 \
netbsd_amd64_v1 \
netbsd_arm_6 \
netbsd_arm64_v8 \
openbsd_amd64_v1 \
openbsd_arm_6 \
openbsd_arm64_v8 \
windows_amd64_v1 \
windows_arm_6 \
windows_arm64_v8
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
TARGET := $(filter $(GOOS)_$(GOARCH)%,$(TARGETS))
# Define variables based on the target
define set_vars
ifeq ($1, linux_amd64_v1)
GOOS := linux
GOARCH := amd64
else ifeq ($1, linux_arm_6)
GOOS := linux
GOARCH := arm
GOARM := 6
else ifeq ($1, linux_arm64_v8)
GOOS := linux
GOARCH := arm64
else ifeq ($1, linux_ppc64le)
GOOS := linux
GOARCH := ppc64le
else ifeq ($1, linux_riscv64_rva20u64)
GOOS := linux
GOARCH := riscv64
else ifeq ($1, linux_s390x)
GOOS := linux
GOARCH := s390x
else ifeq ($1, darwin_amd64_v1)
GOOS := darwin
GOARCH := amd64
else ifeq ($1, darwin_arm64_v8)
GOOS := darwin
GOARCH := arm64
else ifeq ($1, dragonfly_amd64_v1)
GOOS := dragonfly
GOARCH := amd64
else ifeq ($1, freebsd_amd64_v1)
GOOS := freebsd
GOARCH := amd64
else ifeq ($1, freebsd_arm_6)
GOOS := freebsd
GOARCH := arm
GOARM := 6
else ifeq ($1, freebsd_arm64_v8)
GOOS := freebsd
GOARCH := arm64
else ifeq ($1, illumos_amd64_v1)
GOOS := illumos
GOARCH := amd64
else ifeq ($1, netbsd_amd64_v1)
GOOS := netbsd
GOARCH := amd64
else ifeq ($1, netbsd_arm_6)
GOOS := netbsd
GOARCH := arm
GOARM := 6
else ifeq ($1, netbsd_arm64_v8)
GOOS := netbsd
GOARCH := arm64
else ifeq ($1, openbsd_amd64_v1)
GOOS := openbsd
GOARCH := amd64
else ifeq ($1, openbsd_arm_6)
GOOS := openbsd
GOARCH := arm
GOARM := 6
else ifeq ($1, openbsd_arm64_v8)
GOOS := openbsd
GOARCH := arm64
else ifeq ($1, windows_amd64_v1)
GOOS := windows
GOARCH := amd64
else ifeq ($1, windows_arm_6)
GOOS := windows
GOARCH := arm
GOARM := 6
else ifeq ($1, windows_arm64_v8)
GOOS := windows
GOARCH := arm64
endif
endef
BINARIES := $(addprefix bin/$(PLUGIN_PREFIX)-$(PLUGIN)_,$(TARGETS))
ARCHIVES := $(subst bin/,dist/,$(addsuffix .tar.gz,$(filter-out bin/$(PLUGIN_PREFIX)-$(PLUGIN)_windows%,$(BINARIES))) $(addsuffix .zip,$(filter bin/$(PLUGIN_PREFIX)-$(PLUGIN)_windows%,$(BINARIES))))
SIGNATURES := $(ARCHIVES:=.sig)
SBOMS := $(ARCHIVES:=.spdx.sbom.json)
.PHONY: ci-matrix ci-targets image push
ci-matrix:
@echo -n "$(PLUGINS)" | jq -Rscr 'split(" ") | "plugins=\(.)"'
ci-targets:
@echo -n "$(TARGETS)" | jq -Rscr 'split(" ") | "targets=\(.)"'
bin dist:
@mkdir -p $@
image: Containerfile $(BINARIES)
@buildah manifest rm $(REGISTRY)/$(PLUGIN_PREFIX)-$(PLUGIN):$(VERSION) || true
@buildah manifest create $(REGISTRY)/$(PLUGIN_PREFIX)-$(PLUGIN):$(VERSION)
@$(foreach target,$(TARGETS),cat $< | PLUGIN=$(PLUGIN) envsubst '$$PLUGIN' | buildah build -f - --platform $(subst _,/,$(target)) --build-arg PLUGIN=$(PLUGIN) -t $(REGISTRY)/$(PLUGIN_PREFIX)-$(PLUGIN):$(VERSION)_$(target);)
@$(foreach target,$(TARGETS),buildah manifest add $(REGISTRY)/$(PLUGIN_PREFIX)-$(PLUGIN):$(VERSION) $(REGISTRY)/$(PLUGIN_PREFIX)-$(PLUGIN):$(VERSION)_$(target);)
push: image
@buildah manifest push --all $(REGISTRY)/$(PLUGIN_PREFIX)-$(PLUGIN):$(VERSION)
dist/%.tar.gz: bin/% | dist
@echo "archiving $@"
@tar cfz $@ LICENSE -C bin $*
dist/%.zip: bin/% | dist
@echo "archiving $@"
@zip -qj $@ LICENSE $^
dist/checksums-$(PLUGIN).txt: $(ARCHIVES) | dist
@echo "creating checksums $@"
@cd dist && sha256sum $(subst dist/,,$^) > checksums-$(PLUGIN).txt
dist/%.sig: dist/% | dist
@echo "signing $@"
@gpg --detach-sign --pinentry-mode loopback --passphrase $(GPG_PASSWORD) --batch --output $@ $<
dist/%.spdx.sbom.json: dist/% | dist
@echo "creating SBOM $@"
@syft scan $< -q -o cyclonedx-json=$@
$(BINARIES): bin/$(PLUGIN_PREFIX)-$(PLUGIN)_%: | bin
$(eval $(call set_vars,$*))
@echo "building $@"
@GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_ENABLED=0 go build -o $@ -ldflags '-s -w -X github.com/openbao/openbao-plugins/$(subst -,/,$(PLUGIN)).pluginVersion=$(VERSION)' ./$(subst -,/,$(PLUGIN))/cmd
$(PLUGINS): %:
@$(MAKE) --no-print-directory build PLUGIN=$*
$(PLUGINS:=-test): %-test:
@$(MAKE) --no-print-directory test PLUGIN=$*
bin/$(PLUGIN_PREFIX)-$(PLUGIN).test: $(subst -,/,$(PLUGIN))/*.go $(subst -,/,$(PLUGIN))/**/*.go | bin
@go test -c ./$(subst -,/,$(PLUGIN)) -o $@
./$@ -test.v -test.short
build: bin/$(PLUGIN_PREFIX)-$(PLUGIN)_$(TARGET)
build-all: $(BINARIES)
release: dist/checksums-$(PLUGIN).txt $(SIGNATURES) $(SBOMS)
test: bin/$(PLUGIN_PREFIX)-$(PLUGIN).test
clean:
@rm -rf $(TESTS) bin dist