@@ -21,8 +21,20 @@ CONTAINER_TOOL ?= docker
21
21
SHELL = /usr/bin/env bash -o pipefail
22
22
.SHELLFLAGS = -ec
23
23
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 )
26
38
27
39
# #@ General
28
40
@@ -108,47 +120,30 @@ verify: vet fmt-verify manifests generate ## ci-lint add back when all lint erro
108
120
109
121
# #@ Build
110
122
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
+
152
147
153
148
# #@ Docs
154
149
0 commit comments