forked from vmware-tanzu/velero-plugin-for-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (109 loc) · 4.01 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
# Copyright 2017, 2019 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.
PKG := github.com/vmware-tanzu/velero-plugin-for-aws
BIN := velero-plugin-for-aws
REGISTRY ?= jibutech-registry.cn-hangzhou.cr.aliyuncs.com/ys1000
VERSION ?= main
CONTAINER_PLATFORMS ?= amd64 arm64 # ppc64le arm
# Jibu version and tag
IMAGE_TAG:=$(shell ./hack/image-tag.sh)
TAG ?= ${IMAGE_TAG}
JIBU_IMG ?= ${REGISTRY}/velero-plugin-for-aws:$(TAG)
# Which architecture to build.
# if the 'local' rule is being run, detect the GOOS/GOARCH from 'go env'
# if it wasn't specified by the caller.
local: GOOS ?= $(shell go env GOOS)
GOOS ?= linux
local: GOARCH ?= $(shell go env GOARCH)
GOARCH ?= amd64
# Set default base image dynamically for each arch
ifeq ($(GOARCH),amd64)
DOCKERFILE ?= Dockerfile
endif
ifeq ($(GOARCH),arm)
DOCKERFILE ?= Dockerfile-arm
endif
ifeq ($(GOARCH),arm64)
DOCKERFILE ?= Dockerfile-arm64
endif
MULTIARCH_IMAGE = $(REGISTRY)/$(BIN)
IMAGE ?= $(REGISTRY)/$(BIN)-$(GOARCH)
# If you want to build all containers, see the 'all-containers' rule.
# If you want to build AND push all containers, see the 'all-push' rule.
container-%:
@$(MAKE) --no-print-directory GOARCH=$* container
push-%:
@$(MAKE) --no-print-directory GOARCH=$* push
all-containers: $(addprefix container-, $(CONTAINER_PLATFORMS))
all-push: $(addprefix push-, $(CONTAINER_PLATFORMS))
all-manifests:
@$(MAKE) manifest
# local builds the binary using 'go build' in the local environment.
local: build-dirs
GOOS=$(GOOS) \
GOARCH=$(GOARCH) \
PKG=$(PKG) \
BIN=$(BIN) \
OUTPUT_DIR=$$(pwd)/_output \
./hack/build.sh
# test runs unit tests using 'go test' in the local environment.
test:
CGO_ENABLED=0 go test -v -timeout 60s ./...
# ci is a convenience target for CI builds.
ci: verify-modules test
# container builds a Docker image containing the binary.
.PHONY: container
container:
docker build -t $(IMAGE):$(VERSION) -f $(DOCKERFILE) .
@echo "container: $(IMAGE):$(VERSION)"
# push pushes the Docker image to its registry.
.PHONY: push
push: container
@docker push $(IMAGE):$(VERSION)
@echo "pushed: $(IMAGE):$(VERSION)"
ifeq ($(TAG_LATEST), true)
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest
docker push $(IMAGE):latest
@echo "pushed: $(IMAGE):latest"
endif
manifest:
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(MULTIARCH_IMAGE):$(VERSION) \
$(foreach arch, $(CONTAINER_PLATFORMS), $(MULTIARCH_IMAGE)-$(arch):$(VERSION))
@DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(MULTIARCH_IMAGE):$(VERSION)
@echo "pushed: $(MULTIARCH_IMAGE):$(VERSION)"
ifeq ($(TAG_LATEST), true)
@DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(MULTIARCH_IMAGE):latest \
$(foreach arch, $(CONTAINER_PLATFORMS), $(MULTIARCH_IMAGE)-$(arch):latest)
@DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(MULTIARCH_IMAGE):latest
@echo "pushed: $(MULTIARCH_IMAGE):latest)"
endif
# build-dirs creates the necessary directories for a build in the local environment.
build-dirs:
@mkdir -p _output
.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
# clean removes build artifacts from the local environment.
clean:
@echo "cleaning"
rm -rf _output
build-image:
docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile -t $(JIBU_IMG) .
push-image:
docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile -t $(JIBU_IMG) . --push