forked from AliyunContainerService/velero-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (154 loc) · 5.48 KB
/
Copy pathMakefile
File metadata and controls
180 lines (154 loc) · 5.48 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
# Copyright the Velero contributors.
#
# 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.
# The binary to build (just the basename).
BIN ?= velero-plugin-alibabacloud
# This repo's root import path.
PKG := github.com/AliyunContainerService/velero-plugin
# Where to push the docker image.
REGISTRY ?= velero
# Image name
IMAGE ?= $(REGISTRY)/$(BIN)
# We allow the Dockerfile to be configurable to enable the use of custom Dockerfiles
# that pull base images from different registries.
VELERO_DOCKERFILE ?= Dockerfile
# Container runtime to use (docker or podman)
# Default to docker, but can be overridden with CONTAINER_RUNTIME=podman
CONTAINER_RUNTIME ?= docker
# Which architecture to build - see $(ALL_ARCH) for options.
# if the 'local' rule is being run, detect the ARCH from 'go env'
# if it wasn't specified by the caller.
local : ARCH ?= $(shell go env GOOS)-$(shell go env GOARCH)
ARCH ?= linux-amd64
VERSION ?= main
TAG_LATEST ?= false
ifeq ($(TAG_LATEST), true)
IMAGE_TAGS ?= $(IMAGE):$(VERSION) $(IMAGE):latest
else
IMAGE_TAGS ?= $(IMAGE):$(VERSION)
endif
# Detect buildx support based on container runtime
ifeq ($(CONTAINER_RUNTIME), podman)
# Podman 4.0+ supports buildx, but multi-arch support may be limited
# Check if podman buildx is available
ifeq ($(shell $(CONTAINER_RUNTIME) buildx version 2>/dev/null | head -n1),)
BUILDX_ENABLED ?= false
PODMAN_MULTIARCH ?= false
else
BUILDX_ENABLED ?= true
# Podman may not fully support multi-arch, so we'll use single arch for podman
PODMAN_MULTIARCH ?= false
endif
else
# Docker buildx detection
ifeq ($(shell $(CONTAINER_RUNTIME) buildx inspect 2>/dev/null | awk '/Status/ { print $$2 }'), running)
BUILDX_ENABLED ?= true
else
BUILDX_ENABLED ?= false
endif
PODMAN_MULTIARCH ?= false
endif
define BUILDX_ERROR
buildx not enabled, refusing to run this recipe
see: https://velero.io/docs/main/build-from-source/#making-images-and-updating-velero for more info
endef
# Convert ARCH format (linux-amd64) to platform format (linux/amd64) for buildx
BUILDX_PLATFORMS ?= $(subst -,/,$(ARCH))
BUILDX_OUTPUT_TYPE ?= docker
# set git sha and tree state
GIT_SHA = $(shell git rev-parse HEAD)
ifneq ($(shell git status --porcelain 2> /dev/null),)
GIT_TREE_STATE ?= dirty
else
GIT_TREE_STATE ?= clean
endif
###
### These variables should not need tweaking.
###
platform_temp = $(subst -, ,$(ARCH))
GOOS = $(word 1, $(platform_temp))
GOARCH = $(word 2, $(platform_temp))
# GOPROXY can be set to use a custom proxy (e.g., https://goproxy.cn for China)
GOPROXY ?= https://proxy.golang.org
local: build-dirs
GOOS=$(GOOS) \
GOARCH=$(GOARCH) \
VERSION=$(VERSION) \
REGISTRY=$(REGISTRY) \
PKG=$(PKG) \
BIN=$(BIN) \
GIT_SHA=$(GIT_SHA) \
GIT_TREE_STATE=$(GIT_TREE_STATE) \
OUTPUT_DIR=$$(pwd)/_output/bin/$(GOOS)/$(GOARCH) \
./hack/build.sh
# test runs unit tests using 'go test' in the local environment.
test:
CGO_ENABLED=0 go test -v -coverprofile=coverage.out -timeout 60s ./...
# ci is a convenience target for CI builds.
ci: verify-modules test
container:
@if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \
echo "building with $(CONTAINER_RUNTIME) (single architecture: $(BUILDX_PLATFORMS))"; \
$(CONTAINER_RUNTIME) build --pull \
--platform $(BUILDX_PLATFORMS) \
$(addprefix -t , $(IMAGE_TAGS)) \
--build-arg=GOPROXY=$(GOPROXY) \
--build-arg=PKG=$(PKG) \
--build-arg=BIN=$(BIN) \
--build-arg=VERSION=$(VERSION) \
--build-arg=GIT_SHA=$(GIT_SHA) \
--build-arg=GIT_TREE_STATE=$(GIT_TREE_STATE) \
-f $(VELERO_DOCKERFILE) .; \
echo "container: $(IMAGE):$(VERSION)"; \
else \
if [ "$(BUILDX_ENABLED)" != "true" ]; then \
echo "buildx not enabled, refusing to run this recipe"; \
echo "see: https://velero.io/docs/main/build-from-source/#making-images-and-updating-velero for more info"; \
exit 1; \
fi; \
echo "building with $(CONTAINER_RUNTIME) buildx (platform: $(BUILDX_PLATFORMS))"; \
$(CONTAINER_RUNTIME) buildx build --pull \
--output=type=$(BUILDX_OUTPUT_TYPE) \
--platform $(BUILDX_PLATFORMS) \
$(addprefix -t , $(IMAGE_TAGS)) \
--build-arg=GOPROXY=$(GOPROXY) \
--build-arg=PKG=$(PKG) \
--build-arg=BIN=$(BIN) \
--build-arg=VERSION=$(VERSION) \
--build-arg=GIT_SHA=$(GIT_SHA) \
--build-arg=GIT_TREE_STATE=$(GIT_TREE_STATE) \
-f $(VELERO_DOCKERFILE) .; \
echo "container: $(IMAGE):$(VERSION)"; \
if [ "$(BUILDX_OUTPUT_TYPE)_$(REGISTRY)" = "registry_velero" ]; then \
$(CONTAINER_RUNTIME) pull $(IMAGE):$(VERSION); \
rm -f $(BIN)-$(VERSION).tar; \
$(CONTAINER_RUNTIME) save $(IMAGE):$(VERSION) -o $(BIN)-$(VERSION).tar; \
gzip -f $(BIN)-$(VERSION).tar; \
fi; \
fi
build-dirs:
@mkdir -p _output/bin/$(GOOS)/$(GOARCH)
.PHONY: modules
modules:
go mod tidy
.PHONY: verify-modules
verify-modules: modules
@if !(git diff --quiet HEAD -- go.sum go.mod); then \
echo "go module files are out of date, please commit the changes to go.mod and go.sum"; exit 1; \
fi
changelog:
hack/release-tools/changelog.sh
# clean removes build artifacts from the local environment.
clean:
@echo "cleaning"
rm -rf _output