|
| 1 | +PLATFORMS ?= linux/$(TARGETARCH) |
| 2 | +TARGETARCH ?= amd64 |
| 3 | + |
| 4 | +DOCKER_BUILDX_CMD ?= docker buildx |
| 5 | +IMAGE_BUILD_CMD ?= $(DOCKER_BUILDX_CMD) build |
| 6 | +IMAGE_BUILD_EXTRA_OPTS ?= |
| 7 | + |
| 8 | +IMAGE_REGISTRY ?= quay.io/trustyai |
| 9 | +IMAGE_NAME := nemo-guardrails-server |
| 10 | +IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME) |
| 11 | +IMAGE_TAG ?= $(IMAGE_REPO):$(GIT_TAG) |
| 12 | + |
| 13 | +GIT_COMMIT_SHA ?= $(shell git rev-parse HEAD) |
| 14 | +GIT_TAG ?= $(or $(shell git describe --abbrev=0 2>/dev/null),$(shell git rev-parse --short HEAD)) |
| 15 | +BUILD_REF ?= $(or $(shell git describe --abbrev=0 2>/dev/null),$(GIT_TAG)) # release tag or fallback to git commit hash |
| 16 | + |
| 17 | +# The name of the kind cluster to use for the "kind-load" target. |
| 18 | +KIND_CLUSTER ?= kind |
| 19 | + |
1 | 20 | .PHONY: all test tests test_watch test_coverage test_profile docs docs-strict docs-serve docs-update-cards docs-check-cards docs-watch-cards pre_commit help |
2 | 21 |
|
3 | 22 | # Default target executed when no specific target is provided to make. |
@@ -46,6 +65,35 @@ pre_commit: |
46 | 65 | pre-commit install |
47 | 66 | pre-commit run --all-files |
48 | 67 |
|
| 68 | +# BUILD |
| 69 | +.PHONY: image-build |
| 70 | +image-build: # Build the image using Docker buildx. |
| 71 | + $(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \ |
| 72 | + --file Dockerfile.server \ |
| 73 | + --platform=$(PLATFORMS) \ |
| 74 | + --build-arg COMMIT_SHA=${GIT_COMMIT_SHA} \ |
| 75 | + --build-arg BUILD_REF=${BUILD_REF} \ |
| 76 | + $(PUSH) \ |
| 77 | + $(LOAD) \ |
| 78 | + $(IMAGE_BUILD_EXTRA_OPTS) ./ |
| 79 | + |
| 80 | +# Build the container image for the server |
| 81 | +.PHONY: image-local-build |
| 82 | +image-local-build: # Build the image using Docker buildx |
| 83 | + set -e; \ |
| 84 | + builder=$$($(DOCKER_BUILDX_CMD) create --use); \ |
| 85 | + trap '$(DOCKER_BUILDX_CMD) rm -f "$$builder"' EXIT; \ |
| 86 | + $(MAKE) image-build PUSH="$(PUSH)" LOAD="$(LOAD)" |
| 87 | + |
| 88 | +.PHONY: image-local-push |
| 89 | +image-local-push: # Push the image to the local Docker registry |
| 90 | +image-local-push: PUSH=--push # Build the image for local development and push it to $IMAGE_REPO. |
| 91 | +image-local-push: image-local-build |
| 92 | + |
| 93 | +.PHONY: image-kind |
| 94 | +image-kind: LOAD=--load |
| 95 | +image-kind: image-build # Build the image and load it to kind cluster $KIND_CLUSTER ("kind" by default) |
| 96 | + kind load docker-image $(IMAGE_TAG) --name $(KIND_CLUSTER) |
49 | 97 |
|
50 | 98 | # HELP |
51 | 99 |
|
|
64 | 112 | @echo 'docs-watch-cards - watch for file changes and auto-update cards' |
65 | 113 | @echo 'docs-check-redirects - validate that all redirect targets exist' |
66 | 114 | @echo 'pre_commit - run pre-commit hooks' |
| 115 | + @echo 'image-build - build the image using Docker buildx' |
| 116 | + @echo 'image-local-build - build the image using Docker buildx for local development' |
| 117 | + @echo 'image-local-push - build the image and push it to the local Docker registry' |
| 118 | + @echo 'image-kind - build the image and load it to kind cluster $KIND_CLUSTER ("kind" by default)' |
0 commit comments