Skip to content

Commit 9c939c7

Browse files
authored
feat: add support in Makefile for better local deveopment (#90)
- use local.mk with pre-set env varibles: "make image IMG=XXX" and simplify to "make image" - introduce new variable "IMG_TAG" to be keep old behavior - rename target from "docker-build"/"docker-push" to "image-build"/"image-push" since we support podman by default - create new target "clean" - update documents and other place referred to updates test: 1. made local.mk with ``` VERSION=25.7.2 IMAGE_TAG_BASE=quay.io/wenzhou/llama-stack-k8s-operator IMG_TAG=$(VERSION) ``` then ran `make image build-installer` generated `quay.io/wenzhou/llama-stack-k8s-operator:25.7.2` 2. removed local.mk to run `make image build-installer` it calls `podman build -t quay.io/llamastack/llama-stack-k8s-operator:latest .` Approved-by: VaishnaviHire
1 parent ffa3f7a commit 9c939c7

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

.github/workflows/build-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
password: ${{ secrets.APP_QUAY_TOKEN }}
3030

3131
- name: Build and push latest image
32-
run: make docker-build docker-push -e IMG=quay.io/llamastack/llama-stack-k8s-operator:latest
32+
run: make image-build image-push -e IMG=quay.io/llamastack/llama-stack-k8s-operator:latest

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ COPY pkg/ pkg/
2424
USER root
2525

2626
# GOARCH is intentionally left empty to automatically detect the host architecture
27-
# This ensures the binary matches the platform where docker-build is executed
27+
# This ensures the binary matches the platform where image-build is executed
2828
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o manager main.go
2929

3030
# Use distroless as minimal base image to package the manager binary

Makefile

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ OPERATOR_SDK_VERSION ?= v1.39.2
5353
ENVTEST_K8S_VERSION = 1.31.0
5454

5555
# Image URL to use all building/pushing image targets
56-
IMG ?= quay.io/llamastack/llama-stack-k8s-operator:latest
56+
IMG_TAG ?= latest
57+
IMG ?= $(IMAGE_TAG_BASE):$(IMG_TAG)
5758

5859
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5960
ifeq (,$(shell go env GOBIN))
@@ -63,7 +64,7 @@ GOBIN=$(shell go env GOBIN)
6364
endif
6465

6566
# CONTAINER_TOOL defines the container tool to be used for building images.
66-
# Be aware that the target commands are only tested with Docker which is
67+
# Be aware that the target commands are only tested with Docker/Podman which is
6768
# scaffolded by default. However, you might want to replace it to use other
6869
# tools. (i.e. podman)
6970
CONTAINER_TOOL ?= podman
@@ -77,6 +78,9 @@ SHELL = /usr/bin/env bash -o pipefail
7778
# See README.md, default go test timeout 10m
7879
E2E_TEST_FLAGS = -timeout 30m
7980

81+
# Include local.mk if it exists (for custom overrides)
82+
-include local.mk
83+
8084
.PHONY: all
8185
all: build
8286

@@ -108,12 +112,21 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
108112
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
109113

110114
GOLANGCI_TMP_FILE = .golangci.mktmp.yml
115+
111116
.PHONY: fmt
112117
fmt: golangci-lint yq ## Formats code and imports.
113118
go fmt ./...
114119
$(YQ) e '.linters = {"disable-all": true, "enable": ["gci"]}' .golangci.yml > $(GOLANGCI_TMP_FILE)
115120
$(GOLANGCI_LINT) run --config=$(GOLANGCI_TMP_FILE) --fix
116-
CLEANFILES += $(GOLANGCI_TMP_FILE)
121+
122+
.PHONY: clean
123+
clean: ## Remove temporary files, caches, and downloaded tools
124+
@# Clean golangci-lint cache only if golangci-lint is available
125+
@if command -v $(GOLANGCI_LINT) >/dev/null 2>&1; then \
126+
$(GOLANGCI_LINT) cache clean; \
127+
fi
128+
rm -f $(GOLANGCI_TMP_FILE) Dockerfile.cross cover.out
129+
rm -rf $(LOCALBIN)
117130

118131
.PHONY: vet
119132
vet: ## Run go vet against code.
@@ -125,7 +138,7 @@ test: manifests generate fmt vet envtest ## Run tests.
125138

126139
.PHONY: test-e2e
127140
test-e2e: ## Run e2e tests
128-
./hack/deploy-ollama.sh # Deploy Ollama
141+
./hack/deploy-ollama.sh # Deploy Ollama for e2e tests
129142
go test -v ./tests/e2e/ -run ^TestE2E -v ${E2E_TEST_FLAGS}
130143

131144
GOLANGCI_LINT_TIMEOUT ?= 5m0s
@@ -150,12 +163,12 @@ run: manifests generate fmt vet ## Run a controller from your host.
150163
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
151164
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
152165
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
153-
.PHONY: docker-build
154-
docker-build: ## Build docker image with the manager.
166+
.PHONY: image-build
167+
image-build: ## Build image with the manager.
155168
$(CONTAINER_TOOL) build -t ${IMG} .
156169

157-
.PHONY: docker-push
158-
docker-push: ## Push docker image with the manager.
170+
.PHONY: image-push
171+
image-push: ## Push image with the manager.
159172
$(CONTAINER_TOOL) push ${IMG}
160173

161174
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
@@ -183,7 +196,7 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi
183196
$(KUSTOMIZE) build config/default > release/operator.yaml
184197

185198
.PHONY: image
186-
image: docker-build docker-push ## Build and push image with the manager.
199+
image: image-build image-push ## Build and push image with the manager.
187200

188201
##@ Deployment
189202

@@ -322,7 +335,7 @@ bundle-build: ## Build the bundle image.
322335

323336
.PHONY: bundle-push
324337
bundle-push: ## Push the bundle image.
325-
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
338+
$(MAKE) image-push IMG=$(BUNDLE_IMG)
326339

327340
.PHONY: opm
328341
OPM = $(LOCALBIN)/opm
@@ -358,12 +371,12 @@ endif
358371
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
359372
.PHONY: catalog-build
360373
catalog-build: opm ## Build a catalog image.
361-
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
374+
$(OPM) index add --container-tool $(CONTAINER_TOOL) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
362375

363376
# Push the catalog image.
364377
.PHONY: catalog-push
365378
catalog-push: ## Push a catalog image.
366-
$(MAKE) docker-push IMG=$(CATALOG_IMG)
379+
$(MAKE) image-push IMG=$(CATALOG_IMG)
367380

368381
# Pre-commit checks called explicitly
369382
.PHONY: pre-commit

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ kubectl apply -f config/samples/example-with-configmap.yaml
100100
```
101101

102102
The default image used is `quay.io/llamastack/llama-stack-k8s-operator:latest` when not supply argument for `make image`
103+
To create a local file `local.mk` with env variables can overwrite the default values set in the `Makefile`.
103104

104105
- Once the image is created, the operator can be deployed directly. For each deployment method a
105106
kubeconfig should be exported

docs/create-operator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The operator's container image needs to be built and pushed to a container regis
4444
**Note:** Replace `<your-namespace>` with your actual registry and namespace.
4545

4646
```bash
47-
make docker-build IMG=$REGISTRY/$REGISTRY_NAMESPACE/llama-stack-operator:$TAG
47+
make image-build IMG=$REGISTRY/$REGISTRY_NAMESPACE/llama-stack-operator:$TAG
4848
podman push $REGISTRY/$REGISTRY_NAMESPACE/llama-stack-operator:$TAG
4949
```
5050

0 commit comments

Comments
 (0)