|
| 1 | +# |
| 2 | +# Copyright 2024. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | + |
| 17 | +# VERSION defines the project version for the bundle. |
| 18 | +# Update this value when you upgrade the version of your project. |
| 19 | +# To re-generate a bundle for another specific version without changing the standard setup, you can: |
| 20 | +# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) |
| 21 | +# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) |
| 22 | +VERSION ?= 0.0.1 |
| 23 | +LDFLAGS="-X 'cloner/cmd.Version=v$(VERSION)'" |
| 24 | + |
| 25 | +# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images. |
| 26 | +# This variable is used to construct full image tags for bundle and catalog images. |
| 27 | +# |
| 28 | +# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both |
| 29 | +# amalthea.dev/amalthea-bundle:$VERSION and amalthea.dev/amalthea-catalog:$VERSION. |
| 30 | +IMAGE_TAG_BASE ?= renku/cloner |
| 31 | +IMG ?= $(IMAGE_TAG_BASE):$(VERSION) |
| 32 | + |
| 33 | +# CONTAINER_TOOL defines the container tool to be used for building images. |
| 34 | +# Be aware that the target commands are only tested with Docker which is |
| 35 | +# scaffolded by default. However, you might want to replace it to use other |
| 36 | +# tools. (i.e. podman) |
| 37 | +CONTAINER_TOOL ?= docker |
| 38 | + |
| 39 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 40 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 41 | +SHELL = /usr/bin/env bash -o pipefail |
| 42 | +.SHELLFLAGS = -ec |
| 43 | + |
| 44 | +.PHONY: help |
| 45 | +help: ## Display this help. |
| 46 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 47 | + |
| 48 | +.PHONY: all |
| 49 | +all: mod test vet fmt build run |
| 50 | + |
| 51 | +##@ Run |
| 52 | + |
| 53 | +.PHONY: |
| 54 | +run: fmt vet build run ## Run the proxy |
| 55 | + chmod +x bin/cloner |
| 56 | + ./bin/cloner |
| 57 | + |
| 58 | +.PHONY: install |
| 59 | +install: run ## Install the proxy |
| 60 | + go install -v ./... |
| 61 | + |
| 62 | +##@ QA |
| 63 | + |
| 64 | +.PHONY: audit |
| 65 | +audit: ## Run quality control checks |
| 66 | + go mod verify |
| 67 | + go vet ./... |
| 68 | + go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./... |
| 69 | + go run golang.org/x/vuln/cmd/govulncheck@latest ./... |
| 70 | + |
| 71 | +.PHONY: test |
| 72 | +test: build ## Run tests |
| 73 | + go test $$(go list ./... | grep -v /e2e) -race -buildvcs |
| 74 | + |
| 75 | +.PHONY: vet |
| 76 | +vet: ## Run go vet against code. |
| 77 | + go vet ./... |
| 78 | + |
| 79 | +.PHONY: fmt |
| 80 | +fmt: ## Run go fmt against code. |
| 81 | + go fmt ./... |
| 82 | + |
| 83 | +.PHONY: mod |
| 84 | +mod: ## Tidy mods |
| 85 | + go mod tidy |
| 86 | + |
| 87 | +.PHONY: code-cleanup |
| 88 | +code-cleanup: vet fmt mod ## Code cleanup |
| 89 | + |
| 90 | +##@ Build |
| 91 | + |
| 92 | +.PHONY: build |
| 93 | +build: fmt vet |
| 94 | + go build -ldflags=$(LDFLAGS) -o bin/cloner main.go |
| 95 | + |
| 96 | +# If you wish to build the manager image targeting other platforms you can use the --platform flag. |
| 97 | +# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. |
| 98 | +# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 99 | +.PHONY: docker-build |
| 100 | +docker-build: ## Build docker image with the manager. |
| 101 | + $(CONTAINER_TOOL) build -t ${IMG} . |
| 102 | + |
| 103 | +.PHONY: docker-push |
| 104 | +docker-push: ## Push docker image with the manager. |
| 105 | + $(CONTAINER_TOOL) push ${IMG} |
| 106 | + |
| 107 | +# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple |
| 108 | +# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: |
| 109 | +# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/ |
| 110 | +# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 111 | +# - 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) |
| 112 | +# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option. |
| 113 | +PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le |
| 114 | +.PHONY: docker-buildx |
| 115 | +docker-buildx: ## Build and push docker image for the manager for cross-platform support |
| 116 | + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile |
| 117 | + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross |
| 118 | + - $(CONTAINER_TOOL) buildx create --name project-v3-builder |
| 119 | + $(CONTAINER_TOOL) buildx use project-v3-builder |
| 120 | + - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . |
| 121 | + - $(CONTAINER_TOOL) buildx rm project-v3-builder |
| 122 | + rm Dockerfile.cross |
0 commit comments