Skip to content

Commit

Permalink
make: simplify personal docker builds
Browse files Browse the repository at this point in the history
```
PLATFORMS=linux/whatever make docker-build
```

now lets you more easily choose a selection of platforms to build.

You can also push with

BUILDX_ACTION=--push make docker-build

This is advantageous over `docker-build` + `docker-push` if you build
using remote hosts, as you avoid pulling the image back to your local
machine.

And when you use a personal repo/registry for developing in clusters you
can maintain the default tag by only overriding `IMG_REPO`.

```
IMG_REPO=rg.fr-par.scw.cloud/dlancashire-public/spin-operator-dev make docker-build-and-publish-all
```

Signed-off-by: Danielle Lancashire <dani@builds.terrible.systems>
  • Loading branch information
endocrimes committed Feb 21, 2024
1 parent 674a502 commit de7e823
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ PKG_LDFLAGS := github.com/prometheus/common/version
LDFLAGS := -s -w -X ${PKG_LDFLAGS}.Version=${VERSION} -X ${PKG_LDFLAGS}.Revision=${COMMIT} -X ${PKG_LDFLAGS}.BuildDate=${DATE} -X ${PKG_LDFLAGS}.Branch=${BRANCH}

# Image URL to use all building/pushing image targets
DEFAULT_IMG_REPO := ghcr.io/spinkube/spin-operator
IMG ?= $(DEFAULT_IMG_REPO):$(shell git rev-parse --short HEAD)-dev
IMG_REPO ?= ghcr.io/spinkube/spin-operator
IMG ?= $(IMG_REPO):$(shell git rev-parse --short HEAD)-dev

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.3
Expand Down Expand Up @@ -116,17 +116,20 @@ run: manifests generate fmt vet ## Run a controller from your host.
go run -ldflags "${LDFLAGS}" ./cmd/main.go

.PHONY: docker-build
docker-build: GOARCH=$(shell go env GOARCH)
docker-build: PLATFORMS ?= linux/$(GOARCH)
docker-build: BUILDX_ACTION ?= --load
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build --load -t ${IMG} .
$(CONTAINER_TOOL) buildx build --platform=$(PLATFORMS) $(BUILDX_ACTION) -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
$(CONTAINER_TOOL) push ${IMG}

PLATFORMS ?= linux/arm64,linux/amd64
.PHONY: docker-build-and-publish-all
docker-build-and-publish-all: ## Build the docker image for all supported platforms
$(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} .
docker-build-and-publish-all: PLATFORMS ?= linux/arm64,linux/amd64
docker-build-and-publish-all: BUILDX_ACTION ?= --push
docker-build-and-publish-all: docker-build ## Build the docker image for all supported platforms

##@ Package

Expand Down

0 comments on commit de7e823

Please sign in to comment.