-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
157 lines (118 loc) · 4.71 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
BASE_BRANCH ?= devel
# Denotes the default operator image version, exposed as a variable for the automated release
DEFAULT_IMAGE_VERSION ?= $(BASE_BRANCH)
export BASE_BRANCH
export DEFAULT_IMAGE_VERSION
DEFAULT_REPO ?= "quay.io/submariner"
BUILD_UPX=false
# Define LOCAL_BUILD to build directly on the host and not inside a Dapper container
ifdef LOCAL_BUILD
DAPPER_HOST_ARCH ?= $(shell go env GOHOSTARCH)
SHIPYARD_DIR ?= ../shipyard
SCRIPTS_DIR ?= $(SHIPYARD_DIR)/scripts/shared
export DAPPER_HOST_ARCH
export SHIPYARD_DIR
export SCRIPTS_DIR
endif
ifneq (,$(DAPPER_HOST_ARCH))
# Running in Dapper
PLATFORMS ?= linux/amd64,linux/arm64
IMAGES = subctl
MULTIARCH_IMAGES := subctl
ifneq (,$(filter ovn,$(USING)))
SETTINGS = $(DAPPER_SOURCE)/.shipyard.e2e.ovn.yml
else
SETTINGS = $(DAPPER_SOURCE)/.shipyard.e2e.yml
endif
include $(SHIPYARD_DIR)/Makefile.inc
gotodockerarch = $(patsubst arm,arm/v7,$(1))
dockertogoarch = $(patsubst arm/v7,arm,$(1))
CROSS_TARGETS := linux-amd64 linux-arm64 linux-arm linux-s390x linux-ppc64le windows-amd64.exe darwin-amd64 darwin-arm64
BINARIES := cmd/bin/subctl
CROSS_BINARIES := $(foreach cross,$(CROSS_TARGETS),$(patsubst %,cmd/bin/subctl-$(VERSION)-%,$(cross)))
CROSS_TARBALLS := $(foreach cross,$(CROSS_TARGETS),$(patsubst %,dist/subctl-$(VERSION)-%.tar.xz,$(cross))) \
$(foreach cross,$(CROSS_TARGETS),$(patsubst %,dist/subctl-$(VERSION)-%.tar.gz,$(cross)))
override E2E_ARGS += cluster1 cluster2
export DEPLOY_ARGS
override UNIT_TEST_ARGS += test internal/env
override VALIDATE_ARGS += --skip-dirs pkg/client
GO ?= go
GOARCH = $(shell $(GO) env GOARCH)
GOEXE = $(shell $(GO) env GOEXE)
GOOS = $(shell $(GO) env GOOS)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell $(GO) env GOBIN))
GOBIN=$(shell $(GO) env GOPATH)/bin
else
GOBIN=$(shell $(GO) env GOBIN)
endif
# Ensure we prefer binaries we build
export PATH := $(CURDIR)/cmd/bin:$(PATH)
# Targets to make
# Build subctl before deploying to ensure we use that
# (with the PATH set above), unless we're deploying "latest"
ifneq (latest,$(SUBCTL_VERSION))
deploy: cmd/bin/subctl
endif
# [system-test] runs system level tests for the various `subctl` commands
system-test:
scripts/test/system.sh
clean:
rm -f $(BINARIES) $(CROSS_BINARIES) $(CROSS_TARBALLS)
build: $(BINARIES)
build-cross: $(CROSS_TARBALLS) dist/subctl-checksums.txt
licensecheck: build | bin/lichen
bin/lichen -c .lichen.yaml $(BINARIES)
bin/lichen:
mkdir -p $(@D)
$(GO) build -o $@ github.com/uw-labs/lichen
cmd/bin/subctl: cmd/bin/subctl-$(VERSION)-$(GOOS)-$(GOARCH)$(GOEXE)
ln -sf $(<F) $@
dist/subctl-%.tar.xz: cmd/bin/subctl-% LICENSE
mkdir -p dist
tar -cJf $@ --transform "s|^cmd/bin/subctl-[^/]*|subctl-$(VERSION)/subctl|" $^
dist/subctl-%.tar.gz: cmd/bin/subctl-% LICENSE
mkdir -p dist
tar -czf $@ --transform "s|^cmd/bin/subctl-[^/]*|subctl-$(VERSION)/subctl|" $^
dist/subctl-checksums.txt: $(CROSS_TARBALLS)
cd $(@D) && sha256sum $(^F) >> $(@F)
# Versions may include hyphens so it's easier to use $(VERSION) than to extract them from the target
# Special case for Linux container builds
# Our container builds look for cmd/bin/linux/{amd64,arm64}/subctl,
# this builds the corresponding subctl using our distribution nomenclature
# and links it to the name expected by the container build.
cmd/bin/linux/%/subctl: cmd/bin/subctl-$(VERSION)-linux-%
mkdir -p $(dir $@)
ln -sf ../../$(<F) $@
.PRECIOUS: cmd/bin/subctl-%
cmd/bin/subctl-%: $(shell find . -name "*.go")
mkdir -p $(@D)
target=$@; \
target=$${target%.exe}; \
components=($$(echo $${target//-/ })); \
GOOS=$${components[-2]}; \
GOARCH=$${components[-1]}; \
export GOARCH GOOS; \
LDFLAGS="-X 'github.com/submariner-io/subctl/pkg/version.Version=$(VERSION)' \
-X 'github.com/submariner-io/submariner-operator/api/v1alpha1.DefaultSubmarinerOperatorVersion=$${DEFAULT_IMAGE_VERSION#v}' \
-X 'github.com/submariner-io/submariner-operator/api/v1alpha1.DefaultRepo=$(DEFAULT_REPO)'" \
$(SCRIPTS_DIR)/compile.sh $@ ./cmd
cmd/bin/non_deploy_subctl:
mkdir -p $(@D)
$(GO) build -o $@ --tags non_deploy \
-ldflags="-X 'github.com/submariner-io/subctl/pkg/version.Version=$(VERSION)' \
-X 'github.com/submariner-io/submariner-operator/api/v1alpha1.DefaultSubmarinerOperatorVersion=$${DEFAULT_IMAGE_VERSION#v}' \
-X 'github.com/submariner-io/submariner-operator/api/v1alpha1.DefaultRepo=$(DEFAULT_REPO)'" \
./cmd
ci: golangci-lint markdownlint unit build images
.PHONY: build ci clean generate-clientset system-test
else
# Not running in Dapper
Makefile.dapper:
@echo Downloading $@
@curl -sfLO https://raw.githubusercontent.com/submariner-io/shipyard/$(BASE_BRANCH)/$@
include Makefile.dapper
.PHONY: deploy licensecheck
endif
# Disable rebuilding Makefile
Makefile Makefile.inc: ;