forked from bloomberg/spire-tpm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
46 lines (35 loc) · 1.86 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
.ONESHELL:
BINARIES ?= tpm_attestor_server tpm_attestor_agent get_tpm_pubhash
OSES ?= linux
ARCHITECTURES ?= amd64 arm64
VERSION ?= develop
DOCKER_REGISTRY ?= docker.io
DOCKER_REPOSITORY_PREFIX ?= boxboat/spire-tpm-plugin
BUILD_DIR ?= ./build
RELEASES_DIR ?= ./releases
PLATFORMS ?= $(foreach os, $(OSES), $(foreach architecture, $(ARCHITECTURES), --platform $(os)/$(architecture)))
BUILD_TARGETS := $(foreach binary, $(BINARIES), $(foreach os, $(OSES), $(foreach architecture, $(ARCHITECTURES), $(binary)-$(os)-$(architecture))))
RELEASE_TARGETS := $(foreach build, $(BUILD_TARGETS), $(build)-release)
DOCKER_TARGETS := $(foreach binary, $(BINARIES), $(binary)-docker)
target_words = $(subst -, ,$@)
target_binary = $(word 1, $(target_words))
target_os = $(word 2, $(target_words))
target_architecture = $(word 3, $(target_words))
target_binary_hyphens = $(subst _,-,$(target_binary))
build: $(BUILD_TARGETS)
$(BUILD_TARGETS):
CGO_ENABLED=0 GOOS=$(target_os) GOARCH=$(target_architecture) go build -ldflags="-s -w -extldflags -static" -o $(BUILD_DIR)/$(target_os)/$(target_architecture)/$(target_binary) cmd/$(target_binary)/main.go
test:
go test ./...
release: $(RELEASE_TARGETS)
$(RELEASE_TARGETS):
mkdir -p releases
tar -cvzf $(RELEASES_DIR)/spire_tpm_plugin_$(target_binary)_$(target_os)_$(target_architecture)_$(VERSION).tar.gz -C $(BUILD_DIR)/$(target_os)/$(target_architecture) $(target_binary)
docker: $(DOCKER_TARGETS)
$(DOCKER_TARGETS):
docker build $(PLATFORMS) --build-arg BINARY=$(target_binary) -t $(DOCKER_REGISTRY)/$(DOCKER_REPOSITORY_PREFIX)-$(target_binary_hyphens):$(VERSION) . --push
docker-build:
CGO_ENABLED=0 GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -ldflags="-s -w -extldflags -static" -o ${BINARY} cmd/${BINARY}/main.go
clean:
rm -rf $(BUILD_DIR) $(RELEASES_DIR)
.PHONY: $(BUILD_TARGETS) $(RELEASE_TARGETS) $(DOCKER_TARGETS) build test release docker clean