Skip to content

Commit 6700914

Browse files
authored
Makefile: don't globally export GOOS=linux (#221)
1 parent 4ea83e6 commit 6700914

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

Makefile

+13-26
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ kind-cluster-cleanup: kind ## Delete the kind cluster
9696

9797
##@ Build
9898

99+
BUILDCMD = sh -c 'mkdir -p $(BUILDBIN) && ${GORELEASER} build ${GORELEASER_ARGS} --single-target -o $(BUILDBIN)/manager'
100+
BUILDDEPS = manifests generate fmt vet goreleaser
101+
99102
.PHONY: build
100-
build: manifests generate fmt vet goreleaser ## Build manager binary using goreleaser for current GOOS and GOARCH.
101-
mkdir -p bin
102-
${GORELEASER} build ${GORELEASER_ARGS} --single-target -o bin/manager
103+
build: BUILDBIN = bin
104+
build: $(BUILDDEPS) ## Build manager binary using goreleaser for current GOOS and GOARCH.
105+
$(BUILDCMD)
106+
107+
.PHONY: build-linux
108+
build-linux: BUILDBIN = bin/linux
109+
build-linux: $(BUILDDEPS) ## Build manager binary using goreleaser for GOOS=linux and local GOARCH.
110+
GOOS=linux $(BUILDCMD)
103111

104112
.PHONY: run
105113
run: docker-build kind-cluster kind-load install ## Build the operator-controller then deploy it into a new kind cluster.
@@ -108,30 +116,9 @@ run: docker-build kind-cluster kind-load install ## Build the operator-controlle
108116
wait:
109117
kubectl wait --for=condition=Available --namespace=$(OPERATOR_CONTROLLER_NAMESPACE) deployment/operator-controller-controller-manager --timeout=$(WAIT_TIMEOUT)
110118

111-
# If you wish built the manager image targeting other platforms you can use the --platform flag.
112-
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
113-
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
114119
.PHONY: docker-build
115-
docker-build: export GOOS=linux
116-
docker-build: build ## Build docker image with the operator-controller.
117-
docker build -t ${IMG} -f Dockerfile ./bin/
118-
119-
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
120-
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
121-
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
122-
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
123-
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
124-
# To properly provided solutions that supports more than one platform you should use this option.
125-
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
126-
.PHONY: docker-buildx
127-
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
128-
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
129-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
130-
- docker buildx create --name project-v3-builder
131-
docker buildx use project-v3-builder
132-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
133-
- docker buildx rm project-v3-builder
134-
rm Dockerfile.cross
120+
docker-build: build-linux ## Build docker image for operator-controller with GOOS=linux and local GOARCH.
121+
docker build -t ${IMG} -f Dockerfile ./bin/linux
135122

136123
###########
137124
# Release #

0 commit comments

Comments
 (0)