From e2533bcb4799f7bf536159f8f7d7040184adfbf1 Mon Sep 17 00:00:00 2001 From: ahg-g Date: Fri, 20 Dec 2024 23:17:59 +0000 Subject: [PATCH] Fix the make build command and add main tag to the latest image --- Makefile | 81 +++++++++++++++++-------------------- cloudbuild.yaml | 28 ++++++++----- pkg/manifests/ext_proc.yaml | 4 +- 3 files changed, 58 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index 2901bf54..74bb958e 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,20 @@ CONTAINER_TOOL ?= docker SHELL = /usr/bin/env bash -o pipefail .SHELLFLAGS = -ec -.PHONY: all -all: build +GIT_TAG ?= $(shell git describe --tags --dirty --always) +PLATFORMS ?= linux/amd64,linux/arm64 +DOCKER_BUILDX_CMD ?= docker buildx +IMAGE_BUILD_CMD ?= $(DOCKER_BUILDX_CMD) build +IMAGE_BUILD_EXTRA_OPTS ?= +IMAGE_REGISTRY ?= us-central1-docker.pkg.dev/k8s-staging-images/llm-instance-gateway +IMAGE_NAME := epp +IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME) +IMAGE_TAG ?= $(IMAGE_REPO):$(GIT_TAG) + +# Use distroless as minimal base image to package the manager binary +# Refer to https://github.com/GoogleContainerTools/distroless for more details +BASE_IMAGE ?= gcr.io/distroless/static:nonroot +BUILDER_IMAGE ?= golang:$(GO_VERSION) ##@ General @@ -108,47 +120,30 @@ verify: vet fmt-verify manifests generate ## ci-lint add back when all lint erro ##@ Build -.PHONY: build -build: manifests generate fmt vet ## Build manager binary. - go build -o bin/manager cmd/main.go - -.PHONY: run -run: manifests generate fmt vet ## Run a controller from your host. - go run ./cmd/main.go - -# If you wish to build the manager image targeting other platforms you can use the --platform flag. -# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. -# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ -.PHONY: docker-build -docker-build: ## Build docker image with the manager. - $(CONTAINER_TOOL) build -t ${IMG} . - -.PHONY: docker-push -docker-push: ## Push docker image with the manager. - $(CONTAINER_TOOL) push ${IMG} - -# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple -# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: -# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/ -# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/ -# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=> then the export will fail) -# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option. -PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le -.PHONY: docker-buildx -docker-buildx: ## Build and push docker image for the manager for cross-platform support - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - - $(CONTAINER_TOOL) buildx create --name api-builder - $(CONTAINER_TOOL) buildx use api-builder - - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . - - $(CONTAINER_TOOL) buildx rm api-builder - rm Dockerfile.cross - -.PHONY: build-installer -build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment. - mkdir -p dist - cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} - $(KUSTOMIZE) build config/default > dist/install.yaml +# Build the container image +.PHONY: image-local-build +image-local-build: + BUILDER=$(shell $(DOCKER_BUILDX_CMD) create --use) + $(MAKE) image-build PUSH=$(PUSH) + $(DOCKER_BUILDX_CMD) rm $$BUILDER + +.PHONY: image-local-push +image-local-push: PUSH=--push +image-local-push: image-local-build + +.PHONY: image-build +image-build: + $(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \ + --platform=$(PLATFORMS) \ + --build-arg BASE_IMAGE=$(BASE_IMAGE) \ + --build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \ + $(PUSH) \ + $(IMAGE_BUILD_EXTRA_OPTS) ./ + +.PHONY: image-push +image-push: PUSH=--push +image-push: image-build + ##@ Docs diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 2dc40add..2da147f4 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,15 +1,23 @@ +# See https://cloud.google.com/cloud-build/docs/build-config +timeout: 3000s +# A build step specifies an action that you want Prow to perform. +# For each build step, Prow executes a job. steps: - - name: gcr.io/cloud-builders/docker +# see https://github.com/kubernetes/test-infra/tree/master/config/jobs/image-pushing + - name: gcr.io/k8s-testimages/gcb-docker-gcloud:v20220830-45cbff55bc + entrypoint: make args: - - build - - --tag=us-central1-docker.pkg.dev/k8s-staging-images/llm-instance-gateway/epp:$_GIT_TAG - - . + - image-push + env: + - GIT_TAG=$_GIT_TAG + - EXTRA_TAG=$_PULL_BASE_REF + - DOCKER_BUILDX_CMD=/buildx-entrypoint substitutions: - _GIT_TAG: '12345' -# this prevents errors if you don't use both _GIT_TAG -# or any new substitutions added in the future. + # _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and + # can be used as a substitution + _GIT_TAG: '0.0.0' + # _PULL_BASE_REF will contain the ref that was pushed to trigger this build - + # a branch like 'main' or 'release-0.2', or a tag like 'v0.2'. + _PULL_BASE_REF: 'main' options: substitution_option: ALLOW_LOOSE -# this will push these images, or cause the build to fail if they weren't built. -images: - - 'us-central1-docker.pkg.dev/k8s-staging-images/llm-instance-gateway/epp:$_GIT_TAG' \ No newline at end of file diff --git a/pkg/manifests/ext_proc.yaml b/pkg/manifests/ext_proc.yaml index 2ea1e4f0..7dc65bb7 100644 --- a/pkg/manifests/ext_proc.yaml +++ b/pkg/manifests/ext_proc.yaml @@ -49,7 +49,7 @@ spec: containers: - name: inference-gateway-ext-proc # TODO(https://github.com/kubernetes-sigs/llm-instance-gateway/issues/34) Update the image and args. - image: + image: us-central1-docker.pkg.dev/k8s-staging-images/llm-instance-gateway/epp:main args: - -serverPoolName - "vllm-llama2-7b-pool" @@ -108,4 +108,4 @@ spec: targetRef: group: gateway.networking.k8s.io kind: HTTPRoute - name: llm-route \ No newline at end of file + name: llm-route