|
| 1 | +GIT_COMMIT := $(shell git rev-parse HEAD) |
| 2 | +GIT_TREE_STATE := $(shell test -n "`git status --porcelain`" && echo "-dirty" || echo "") |
| 3 | + |
1 | 4 | # Image URL to use all building/pushing image targets |
2 | | -IMG ?= nb-backend:latest |
3 | | -# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. |
4 | | -ENVTEST_K8S_VERSION = 1.31.0 |
| 5 | +REGISTRY ?= ghcr.io/kubeflow/notebooks |
| 6 | +NAME ?= workspaces-backend |
| 7 | +TAG ?= sha-$(GIT_COMMIT)$(GIT_TREE_STATE) |
| 8 | +IMG ?= $(REGISTRY)/$(NAME):$(TAG) |
| 9 | +ARCH ?= linux/arm64/v8,linux/amd64,linux/ppc64le |
| 10 | + |
5 | 11 |
|
6 | 12 | # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
7 | 13 | ifeq (,$(shell go env GOBIN)) |
|
13 | 19 | # Backend default port |
14 | 20 | PORT ?= 4000 |
15 | 21 |
|
16 | | -# CONTAINER_TOOL defines the container tool to be used for building images. |
17 | | -# Be aware that the target commands are only tested with Docker which is |
18 | | -# scaffolded by default. However, you might want to replace it to use other |
19 | | -# tools. (i.e. podman) |
20 | | -CONTAINER_TOOL ?= docker |
21 | | - |
22 | 22 | # Setting SHELL to bash allows bash commands to be executed by recipes. |
23 | 23 | # Options are set to exit when a recipe line exits non-zero or a piped command fails. |
24 | 24 | SHELL = /usr/bin/env bash -o pipefail |
@@ -86,34 +86,24 @@ build: fmt vet swag ## Build backend binary. |
86 | 86 | run: fmt vet swag ## Run a backend from your host. |
87 | 87 | go run ./cmd/main.go --port=$(PORT) |
88 | 88 |
|
89 | | -# If you wish to build the manager image targeting other platforms you can use the --platform flag. |
90 | | -# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. |
91 | | -# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
92 | 89 | .PHONY: docker-build |
93 | | -docker-build: ## Build docker image with the backend. |
94 | | - $(CONTAINER_TOOL) build -f Dockerfile -t $(IMG) .. |
95 | | - |
| 90 | +docker-build: |
| 91 | + # NOTE: we are building in the context of the parent directory (..) |
| 92 | + docker build --tag ${IMG} --file Dockerfile .. |
96 | 93 |
|
97 | 94 | .PHONY: docker-push |
98 | | -docker-push: ## Push docker image with the backend. |
99 | | - $(CONTAINER_TOOL) push ${IMG} |
100 | | - |
101 | | -# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple |
102 | | -# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: |
103 | | -# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/ |
104 | | -# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
105 | | -# - 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) |
106 | | -# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option. |
107 | | -PLATFORMS ?= linux/arm64/v8,linux/amd64,linux/ppc64le |
108 | | -.PHONY: docker-buildx |
109 | | -docker-buildx: ## Build and push docker image for the manager for cross-platform support |
110 | | - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile |
111 | | - sed '1,// s/^FROM/FROM --platform=$${BUILDPLATFORM}/' Dockerfile > Dockerfile.cross |
112 | | - - $(CONTAINER_TOOL) buildx create --name project-v3-builder |
113 | | - $(CONTAINER_TOOL) buildx use project-v3-builder |
114 | | - - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .. |
115 | | - - $(CONTAINER_TOOL) buildx rm project-v3-builder |
116 | | - rm Dockerfile.cross |
| 95 | +docker-push: |
| 96 | + docker push ${IMG} |
| 97 | + |
| 98 | +.PHONY: docker-build-multi-arch |
| 99 | +docker-build-multi-arch: |
| 100 | + # NOTE: we are building in the context of the parent directory (..) |
| 101 | + docker buildx build --platform ${ARCH} --tag ${IMG} --file Dockerfile .. |
| 102 | + |
| 103 | +.PHONY: docker-build-push-multi-arch |
| 104 | +docker-build-push-multi-arch: |
| 105 | + # NOTE: we are building in the context of the parent directory (..) |
| 106 | + docker buildx build --platform ${ARCH} --tag ${IMG} --file Dockerfile --push .. |
117 | 107 |
|
118 | 108 | ##@ Dependencies |
119 | 109 |
|
|
0 commit comments