Skip to content

Commit d2bdb8e

Browse files
authored
Fix the make build command and add main tag to the latest image (#127)
1 parent a931809 commit d2bdb8e

File tree

3 files changed

+58
-55
lines changed

3 files changed

+58
-55
lines changed

Makefile

+38-43
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,20 @@ CONTAINER_TOOL ?= docker
2121
SHELL = /usr/bin/env bash -o pipefail
2222
.SHELLFLAGS = -ec
2323

24-
.PHONY: all
25-
all: build
24+
GIT_TAG ?= $(shell git describe --tags --dirty --always)
25+
PLATFORMS ?= linux/amd64,linux/arm64
26+
DOCKER_BUILDX_CMD ?= docker buildx
27+
IMAGE_BUILD_CMD ?= $(DOCKER_BUILDX_CMD) build
28+
IMAGE_BUILD_EXTRA_OPTS ?=
29+
IMAGE_REGISTRY ?= us-central1-docker.pkg.dev/k8s-staging-images/llm-instance-gateway
30+
IMAGE_NAME := epp
31+
IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME)
32+
IMAGE_TAG ?= $(IMAGE_REPO):$(GIT_TAG)
33+
34+
# Use distroless as minimal base image to package the manager binary
35+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
36+
BASE_IMAGE ?= gcr.io/distroless/static:nonroot
37+
BUILDER_IMAGE ?= golang:$(GO_VERSION)
2638

2739
##@ General
2840

@@ -108,47 +120,30 @@ verify: vet fmt-verify manifests generate ## ci-lint add back when all lint erro
108120

109121
##@ Build
110122

111-
.PHONY: build
112-
build: manifests generate fmt vet ## Build manager binary.
113-
go build -o bin/manager cmd/main.go
114-
115-
.PHONY: run
116-
run: manifests generate fmt vet ## Run a controller from your host.
117-
go run ./cmd/main.go
118-
119-
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
120-
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
121-
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
122-
.PHONY: docker-build
123-
docker-build: ## Build docker image with the manager.
124-
$(CONTAINER_TOOL) build -t ${IMG} .
125-
126-
.PHONY: docker-push
127-
docker-push: ## Push docker image with the manager.
128-
$(CONTAINER_TOOL) push ${IMG}
129-
130-
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
131-
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
132-
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
133-
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
134-
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
135-
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
136-
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
137-
.PHONY: docker-buildx
138-
docker-buildx: ## Build and push docker image for the manager for cross-platform support
139-
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
140-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
141-
- $(CONTAINER_TOOL) buildx create --name api-builder
142-
$(CONTAINER_TOOL) buildx use api-builder
143-
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
144-
- $(CONTAINER_TOOL) buildx rm api-builder
145-
rm Dockerfile.cross
146-
147-
.PHONY: build-installer
148-
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
149-
mkdir -p dist
150-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
151-
$(KUSTOMIZE) build config/default > dist/install.yaml
123+
# Build the container image
124+
.PHONY: image-local-build
125+
image-local-build:
126+
BUILDER=$(shell $(DOCKER_BUILDX_CMD) create --use)
127+
$(MAKE) image-build PUSH=$(PUSH)
128+
$(DOCKER_BUILDX_CMD) rm $$BUILDER
129+
130+
.PHONY: image-local-push
131+
image-local-push: PUSH=--push
132+
image-local-push: image-local-build
133+
134+
.PHONY: image-build
135+
image-build:
136+
$(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \
137+
--platform=$(PLATFORMS) \
138+
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
139+
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
140+
$(PUSH) \
141+
$(IMAGE_BUILD_EXTRA_OPTS) ./
142+
143+
.PHONY: image-push
144+
image-push: PUSH=--push
145+
image-push: image-build
146+
152147

153148
##@ Docs
154149

cloudbuild.yaml

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
# See https://cloud.google.com/cloud-build/docs/build-config
2+
timeout: 3000s
3+
# A build step specifies an action that you want Prow to perform.
4+
# For each build step, Prow executes a job.
15
steps:
2-
- name: gcr.io/cloud-builders/docker
6+
# see https://github.com/kubernetes/test-infra/tree/master/config/jobs/image-pushing
7+
- name: gcr.io/k8s-testimages/gcb-docker-gcloud:v20220830-45cbff55bc
8+
entrypoint: make
39
args:
4-
- build
5-
- --tag=us-central1-docker.pkg.dev/k8s-staging-images/llm-instance-gateway/epp:$_GIT_TAG
6-
- .
10+
- image-push
11+
env:
12+
- GIT_TAG=$_GIT_TAG
13+
- EXTRA_TAG=$_PULL_BASE_REF
14+
- DOCKER_BUILDX_CMD=/buildx-entrypoint
715
substitutions:
8-
_GIT_TAG: '12345'
9-
# this prevents errors if you don't use both _GIT_TAG
10-
# or any new substitutions added in the future.
16+
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and
17+
# can be used as a substitution
18+
_GIT_TAG: '0.0.0'
19+
# _PULL_BASE_REF will contain the ref that was pushed to trigger this build -
20+
# a branch like 'main' or 'release-0.2', or a tag like 'v0.2'.
21+
_PULL_BASE_REF: 'main'
1122
options:
1223
substitution_option: ALLOW_LOOSE
13-
# this will push these images, or cause the build to fail if they weren't built.
14-
images:
15-
- 'us-central1-docker.pkg.dev/k8s-staging-images/llm-instance-gateway/epp:$_GIT_TAG'

pkg/manifests/ext_proc.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ spec:
4949
containers:
5050
- name: inference-gateway-ext-proc
5151
# TODO(https://github.com/kubernetes-sigs/llm-instance-gateway/issues/34) Update the image and args.
52-
image: <BUILT-IMAGE>
52+
image: us-central1-docker.pkg.dev/k8s-staging-images/llm-instance-gateway/epp:main
5353
args:
5454
- -serverPoolName
5555
- "vllm-llama2-7b-pool"
@@ -108,4 +108,4 @@ spec:
108108
targetRef:
109109
group: gateway.networking.k8s.io
110110
kind: HTTPRoute
111-
name: llm-route
111+
name: llm-route

0 commit comments

Comments
 (0)