-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
108 lines (94 loc) · 2.96 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
SHELL = bash
WORKSPACE = $(shell pwd)
MAINTAINER = "Aerospike <[email protected]>"
DESCRIPTION = "Aerospike Backup Service"
HOMEPAGE = "https://www.aerospike.com"
VENDOR = "Aerospike INC"
LICENSE = "Apache License 2.0"
BINARY_NAME=aerospike-backup-service
CMD_DIR = cmd/backup
BUILD_DIR = build
TARGET_DIR = $(BUILD_DIR)/target
PACKAGE_DIR = $(BUILD_DIR)/package
ARCHS=linux/amd64 linux/arm64
PACKAGERS=deb rpm
TARGET=$(TARGET_DIR)/$(BINARY_NAME)
ifneq ($(strip $(OS))$(strip $(ARCH)),)
TARGET=$(TARGET_DIR)/$(BINARY_NAME)_$(OS)_$(ARCH)
endif
GIT_COMMIT:=$(shell git rev-parse HEAD)
VERSION:=$(shell cat VERSION)
# Go parameters
GO ?= $(shell which go || echo "/usr/local/go/bin/go")
NFPM ?= $(shell which nfpm)
OS ?= $($(GO) env GOOS)
ARCH ?= $($(GO) env GOARCH)
REGISTRY ?= "docker.io"
RH_REGISTRY ?= "registry.access.redhat.com"
GOBUILD = GOOS=$(OS) GOARCH=$(ARCH) $(GO) build \
-ldflags="-X main.commit=$(GIT_COMMIT) -X main.buildTime=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')"
GOTEST = $(GO) test
GOCLEAN = $(GO) clean
GOBIN_VERSION = $(shell $(GO) version 2>/dev/null)
.PHONY: submodules
submodules:
git submodule update --init --recursive
.PHONY: buildx
buildx:
@for arch in $(ARCHS); do \
OS=$$(echo $$arch | cut -d/ -f1); \
ARCH=$$(echo $$arch | cut -d/ -f2); \
OS=$$OS ARCH=$$ARCH $(MAKE) build; \
done
.PHONY: build
build: submodules
mkdir -p $(TARGET_DIR)
$(GOBUILD) -o $(TARGET) ./$(CMD_DIR)
.PHONY: packages
packages: buildx
@for arch in $(ARCHS); do \
OS=$$(echo $$arch | cut -d/ -f1); \
ARCH=$$(echo $$arch | cut -d/ -f2); \
OS=$$OS ARCH=$$ARCH \
NAME=$(BINARY_NAME) \
VERSION=$(VERSION) \
WORKSPACE=$(WORKSPACE) \
MAINTAINER=$(MAINTAINER) \
DESCRIPTION=$(DESCRIPTION) \
HOMEPAGE=$(HOMEPAGE) \
VENDOR=$(VENDOR) \
LICENSE=$(LICENSE) \
envsubst '$$OS $$ARCH $$NAME $$VERSION $$WORKSPACE $$MAINTAINER $$DESCRIPTION $$HOMEPAGE $$VENDOR $$LICENSE' \
< $(PACKAGE_DIR)/nfpm.tmpl.yaml > $(PACKAGE_DIR)/nfpm-$$OS-$$ARCH.yaml; \
for packager in $(PACKAGERS); do \
$(NFPM) package \
--config $(PACKAGE_DIR)/nfpm-$$OS-$$ARCH.yaml \
--packager $$(echo $$packager) \
--target $(TARGET_DIR); \
done; \
done; \
$(MAKE) checksums
.PHONY: checksums
checksums:
@find . -type f \
\( -name '*.deb' -o -name '*.rpm' \) \
-exec sh -c 'sha256sum "$$1" | cut -d" " -f1 > "$$1.sha256"' _ {} \;
.PHONY: docker-build
docker-build:
docker build --tag aerospike/aerospike-backup-service:$(TAG) --build-arg REGISTRY=$(REGISTRY) --build-arg RH_REGISTRY=$(RH_REGISTRY) --file $(WORKSPACE)/Dockerfile .
.PHONY: docker-buildx
docker-buildx:
cd ./build/scripts && ./docker-buildx.sh --tag $(TAG) --registry $(REGISTRY) --rh-registry $(RH_REGISTRY)
.PHONY: test
test:
$(GOTEST) -v ./...
.PHONY: release
release:
cd ./build/scripts && ./release.sh $(NEXT_VERSION)
.PHONY: clean
clean:
$(GOCLEAN)
rm $(TARGET_DIR)/*
@find . -type f -name 'nfpm-*-*.yaml' -exec rm -f {} +
git submodule foreach --recursive git clean -fd; \
git submodule deinit --all -f