Skip to content

Commit

Permalink
Merge pull request #979 from luncj/build/release-1.1-cross-compile
Browse files Browse the repository at this point in the history
cherry-pick #926 #936 #978 to release-1.1
  • Loading branch information
k8s-ci-robot authored Jan 10, 2022
2 parents 9426906 + bde9333 commit c96252f
Show file tree
Hide file tree
Showing 4 changed files with 1,157 additions and 569 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.16.6-stretch AS builder
FROM --platform=linux/amd64 golang:1.16.6-stretch AS builder

ARG ENABLE_GIT_COMMAND=true
ARG ARCH=amd64

WORKDIR /go/src/sigs.k8s.io/cloud-provider-azure
COPY . .

Expand All @@ -24,7 +27,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
go build ./cmd/cloud-controller-manager

RUN --mount=type=cache,target=/root/.cache/go-build \
make bin/azure-cloud-controller-manager ENABLE_GIT_COMMAND=${ENABLE_GIT_COMMAND}
make bin/azure-cloud-controller-manager ENABLE_GIT_COMMAND=${ENABLE_GIT_COMMAND} ARCH=${ARCH}

FROM gcr.io/distroless/static
COPY --from=builder /go/src/sigs.k8s.io/cloud-provider-azure/bin/azure-cloud-controller-manager /usr/local/bin/cloud-controller-manager
Expand Down
39 changes: 32 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ endif
DOCKER_CLI_EXPERIMENTAL := enabled

# cloud controller manager image
ifeq ($(ARCH), amd64)
IMAGE_NAME=azure-cloud-controller-manager
else
IMAGE_NAME=azure-cloud-controller-manager-$(ARCH)
endif
IMAGE=$(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
# cloud node manager image
NODE_MANAGER_IMAGE_NAME=azure-cloud-node-manager
Expand Down Expand Up @@ -101,7 +105,7 @@ $(BIN_DIR)/azure-cloud-node-manager.exe: $(PKG_CONFIG) $(wildcard cmd/cloud-node
CGO_ENABLED=0 GOOS=windows go build -a -o $(BIN_DIR)/azure-cloud-node-manager.exe $(shell cat $(PKG_CONFIG)) ./cmd/cloud-node-manager

$(BIN_DIR)/azure-cloud-controller-manager: $(PKG_CONFIG) $(wildcard cmd/cloud-controller-manager/*) $(wildcard cmd/cloud-controller-manager/**/*) $(wildcard pkg/**/*) ## Build binary for controller-manager.
CGO_ENABLED=0 GOOS=linux go build -a -o $(BIN_DIR)/azure-cloud-controller-manager $(shell cat $(PKG_CONFIG)) ./cmd/cloud-controller-manager
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -o $(BIN_DIR)/azure-cloud-controller-manager $(shell cat $(PKG_CONFIG)) ./cmd/cloud-controller-manager

## --------------------------------------
##@ Images
Expand All @@ -121,8 +125,16 @@ buildx-setup:
docker run --rm --privileged tonistiigi/binfmt --install all

.PHONY: build-ccm-image
build-ccm-image: docker-pull-prerequisites ## Build controller-manager image.
DOCKER_BUILDKIT=1 docker build -t $(IMAGE) --build-arg ENABLE_GIT_COMMAND=$(ENABLE_GIT_COMMAND) .
build-ccm-image: buildx-setup docker-pull-prerequisites ## Build controller-manager image.
docker buildx build \
--pull \
--output=type=$(OUTPUT_TYPE) \
--platform linux/$(ARCH) \
--build-arg ENABLE_GIT_COMMAND="$(ENABLE_GIT_COMMAND)" \
--build-arg ARCH="$(ARCH)" \
--build-arg VERSION="$(VERSION)" \
--file Dockerfile \
--tag $(IMAGE) .

.PHONY: build-node-image
build-node-image: buildx-setup docker-pull-prerequisites ## Build node-manager image.
Expand Down Expand Up @@ -171,16 +183,16 @@ endif
## --------------------------------------

.PHONY: build-images
build-images: build-ccm-image build-all-node-images ## Build all images.
build-images: build-all-ccm-images build-all-node-images ## Build all images.

.PHONY: image
image: build-ccm-image build-all-node-images ## Build all images.
image: build-all-ccm-images build-all-node-images ## Build all images.

.PHONY: push-images
push-images: push-ccm-image push-all-node-images ## Push all images.
push-images: push-all-ccm-images push-all-node-images ## Push all images.

.PHONY: push
push: push-ccm-image push-all-node-images ## Push all images.
push: push-all-ccm-images push-all-node-images ## Push all images.

.PHONY: push-node-manager-manifest
push-node-manager-manifest: push-all-node-images push-all-windows-node-images ## Create and push a manifest list containing all the Windows and Linux images.
Expand Down Expand Up @@ -223,6 +235,19 @@ push-node-image-windows-%: ## Push node-manager image for Windows.
push-node-image-%:
$(MAKE) ARCH=$* push-node-image

.PHONY: build-all-ccm-images
build-all-ccm-images: $(addprefix build-ccm-image-,$(LINUX_ARCHS))

build-ccm-image-%:
$(MAKE) ARCH=$* build-ccm-image

.PHONY: push-all-ccm-images
push-all-ccm-images: $(addprefix push-ccm-image-,$(LINUX_ARCHS))

push-ccm-image-%:
$(MAKE) ARCH=$* push-ccm-image


## --------------------------------------
##@ Tests
## --------------------------------------
Expand Down
Loading

0 comments on commit c96252f

Please sign in to comment.