2021-08-13 16:12:38 +03:00
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
2025-02-26 15:34:11 +04:00
# Generated on 2025-02-26T10:55:25Z by kres 1281806.
2021-08-13 16:12:38 +03:00
# common variables
SHA := $( shell git describe --match= none --always --abbrev= 8 --dirty)
2024-03-12 18:12:45 +04:00
TAG := $( shell git describe --tag --always --dirty --match v[ 0-9] \* )
2023-10-11 14:51:30 +04:00
ABBREV_TAG := $( shell git describe --tags >/dev/null 2>/dev/null && git describe --tag --always --match v[ 0-9] \* --abbrev= 0 || echo 'undefined' )
2021-08-13 16:12:38 +03:00
BRANCH := $( shell git rev-parse --abbrev-ref HEAD)
ARTIFACTS := _out
2024-05-10 12:08:16 +02:00
IMAGE_TAG ?= $( TAG)
OPERATING_SYSTEM := $( shell uname -s | tr '[:upper:]' '[:lower:]' )
GOARCH := $( shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/' )
2023-01-30 20:44:11 +04:00
WITH_DEBUG ?= false
WITH_RACE ?= false
2021-08-13 16:12:38 +03:00
REGISTRY ?= ghcr.io
2022-08-25 20:29:58 +04:00
USERNAME ?= siderolabs
2021-08-13 16:12:38 +03:00
REGISTRY_AND_USERNAME ?= $( REGISTRY) /$( USERNAME)
2025-02-26 15:34:11 +04:00
PROTOBUF_GO_VERSION ?= 1.36.5
2024-09-02 16:34:00 +03:00
GRPC_GO_VERSION ?= 1.5.1
2025-02-26 15:34:11 +04:00
GRPC_GATEWAY_VERSION ?= 2.26.1
2024-03-12 18:12:45 +04:00
VTPROTOBUF_VERSION ?= 0.6.0
2025-02-26 15:34:11 +04:00
GOIMPORTS_VERSION ?= 0.30.0
2024-03-12 18:12:45 +04:00
DEEPCOPY_VERSION ?= v0.5.6
2025-02-26 15:34:11 +04:00
GOLANGCILINT_VERSION ?= v1.64.5
2024-09-02 16:34:00 +03:00
GOFUMPT_VERSION ?= v0.7.0
2025-02-26 15:34:11 +04:00
GO_VERSION ?= 1.24.0
2023-01-30 20:44:11 +04:00
GO_BUILDFLAGS ?=
GO_LDFLAGS ?=
CGO_ENABLED ?= 0
2023-10-11 14:51:30 +04:00
GOTOOLCHAIN ?= local
2021-08-13 16:12:38 +03:00
TESTPKGS ?= ./...
2022-08-25 20:29:58 +04:00
KRES_IMAGE ?= ghcr.io/siderolabs/kres:latest
CONFORMANCE_IMAGE ?= ghcr.io/siderolabs/conform:latest
2021-08-13 16:12:38 +03:00
# docker build settings
BUILD := docker buildx build
PLATFORM ?= linux/amd64
PROGRESS ?= auto
PUSH ?= false
CI_ARGS ?=
2025-02-26 15:34:11 +04:00
BUILDKIT_MULTI_PLATFORM ?=
2021-08-13 16:12:38 +03:00
COMMON_ARGS = --file= Dockerfile
2023-10-11 14:51:30 +04:00
COMMON_ARGS += --provenance= false
2021-08-13 16:12:38 +03:00
COMMON_ARGS += --progress= $( PROGRESS)
COMMON_ARGS += --platform= $( PLATFORM)
2024-12-17 18:37:41 +03:00
COMMON_ARGS += --build-arg= BUILDKIT_MULTI_PLATFORM = $( BUILDKIT_MULTI_PLATFORM)
2025-02-26 15:34:11 +04:00
COMMON_ARGS += --push= $( PUSH)
2023-01-30 20:44:11 +04:00
COMMON_ARGS += --build-arg= ARTIFACTS = " $( ARTIFACTS) "
COMMON_ARGS += --build-arg= SHA = " $( SHA) "
COMMON_ARGS += --build-arg= TAG = " $( TAG) "
2023-10-11 14:51:30 +04:00
COMMON_ARGS += --build-arg= ABBREV_TAG = " $( ABBREV_TAG) "
2023-01-30 20:44:11 +04:00
COMMON_ARGS += --build-arg= USERNAME = " $( USERNAME) "
COMMON_ARGS += --build-arg= REGISTRY = " $( REGISTRY) "
COMMON_ARGS += --build-arg= TOOLCHAIN = " $( TOOLCHAIN) "
COMMON_ARGS += --build-arg= CGO_ENABLED = " $( CGO_ENABLED) "
COMMON_ARGS += --build-arg= GO_BUILDFLAGS = " $( GO_BUILDFLAGS) "
COMMON_ARGS += --build-arg= GO_LDFLAGS = " $( GO_LDFLAGS) "
2023-10-11 14:51:30 +04:00
COMMON_ARGS += --build-arg= GOTOOLCHAIN = " $( GOTOOLCHAIN) "
COMMON_ARGS += --build-arg= GOEXPERIMENT = " $( GOEXPERIMENT) "
2023-01-30 20:44:11 +04:00
COMMON_ARGS += --build-arg= PROTOBUF_GO_VERSION = " $( PROTOBUF_GO_VERSION) "
COMMON_ARGS += --build-arg= GRPC_GO_VERSION = " $( GRPC_GO_VERSION) "
COMMON_ARGS += --build-arg= GRPC_GATEWAY_VERSION = " $( GRPC_GATEWAY_VERSION) "
COMMON_ARGS += --build-arg= VTPROTOBUF_VERSION = " $( VTPROTOBUF_VERSION) "
2024-05-10 12:08:16 +02:00
COMMON_ARGS += --build-arg= GOIMPORTS_VERSION = " $( GOIMPORTS_VERSION) "
2023-01-30 20:44:11 +04:00
COMMON_ARGS += --build-arg= DEEPCOPY_VERSION = " $( DEEPCOPY_VERSION) "
2023-10-11 14:51:30 +04:00
COMMON_ARGS += --build-arg= GOLANGCILINT_VERSION = " $( GOLANGCILINT_VERSION) "
COMMON_ARGS += --build-arg= GOFUMPT_VERSION = " $( GOFUMPT_VERSION) "
2023-01-30 20:44:11 +04:00
COMMON_ARGS += --build-arg= TESTPKGS = " $( TESTPKGS) "
2025-02-26 15:34:11 +04:00
TOOLCHAIN ?= docker.io/golang:1.24-alpine
2021-08-13 16:12:38 +03:00
# help menu
export define HELP_MENU_HEADER
# Getting Started
To build this project, you must have the following installed :
- g i t
- m a k e
- d o c k e r ( 1 9 . 0 3 o r h i g h e r )
## Creating a Builder Instance
T h e b u i l d p r o c e s s m a k e s u s e o f e x p e r i m e n t a l D o c k e r f e a t u r e s ( b u i l d x ) .
To enable experimental features, add 'experimental : "true "' to '/etc /docker /daemon .json ' on
L i n u x o r e n a b l e e x p e r i m e n t a l f e a t u r e s i n D o c k e r G U I f o r W i n d o w s o r M a c .
To create a builder instance, run :
docker buildx create --name local --use
2024-01-21 12:30:28 +02:00
If running builds that needs to be cached aggresively create a builder instance with the following :
docker buildx create --name local --use --config= config.toml
config.toml contents :
[ w o r k e r . o c i ]
gc = true
gckeepstorage = 50000
[ [ worker.oci.gcpolicy] ]
keepBytes = 10737418240
keepDuration = 604800
filters = [ "type==source.local" , "type==exec.cachemount" , "type==source.git.checkout" ]
[ [ worker.oci.gcpolicy] ]
all = true
keepBytes = 53687091200
2021-08-13 16:12:38 +03:00
I f y o u a l r e a d y h a v e a c o m p a t i b l e b u i l d e r i n s t a n c e , y o u m a y u s e t h a t i n s t e a d .
## Artifacts
A l l a r t i f a c t s w i l l b e o u t p u t t o . / $( ARTIFACTS ) . I m a g e s w i l l b e t a g g e d w i t h t h e
2024-05-10 12:08:16 +02:00
registry "$(REGISTRY)", username "$(USERNAME)", and a dynamic tag (e.g. $(IMAGE) : $( IMAGE_TAG ) ).
2021-08-13 16:12:38 +03:00
T h e r e g i s t r y a n d u s e r n a m e c a n b e o v e r r i d d e n b y e x p o r t i n g R E G I S T R Y , a n d U S E R N A M E
r e s p e c t i v e l y .
e n d e f
2023-01-30 20:44:11 +04:00
i f n e q ( , $( filter $ ( WITH_RACE ) , t true TRUE y yes 1) )
GO_BUILDFLAGS += -race
CGO_ENABLED := 1
GO_LDFLAGS += -linkmode= external -extldflags '-static'
e n d i f
i f n e q ( , $( filter $ ( WITH_DEBUG ) , t true TRUE y yes 1) )
GO_BUILDFLAGS += -tags sidero.debug
e l s e
2024-03-12 18:12:45 +04:00
GO_LDFLAGS += -s
2023-01-30 20:44:11 +04:00
e n d i f
2024-05-10 12:08:16 +02:00
all : unit -tests discovery -service image -discovery -service snapshot -decoder lint
$(ARTIFACTS) : ## Creates artifacts directory.
@mkdir -p $( ARTIFACTS)
2021-08-13 16:12:38 +03:00
.PHONY : clean
clean : ## Cleans up all artifacts.
@rm -rf $( ARTIFACTS)
target-% : ## Builds the specified target defined in the Dockerfile. The build result will only remain in the build cache.
@$( BUILD) --target= $* $( COMMON_ARGS) $( TARGET_ARGS) $( CI_ARGS) .
2025-02-26 15:34:11 +04:00
registry-% : ## Builds the specified target defined in the Dockerfile and the output is an image. The image is pushed to the registry if PUSH=true.
@$( MAKE) target-$* TARGET_ARGS = " --tag= $( REGISTRY) / $( USERNAME) / $( IMAGE_NAME) : $( IMAGE_TAG) " BUILDKIT_MULTI_PLATFORM = 1
2021-08-13 16:12:38 +03:00
local-% : ## Builds the specified target defined in the Dockerfile using the local output type. The build result will be output to the specified local destination.
@$( MAKE) target-$* TARGET_ARGS = " --output=type=local,dest= $( DEST) $( TARGET_ARGS) "
2024-12-17 18:37:41 +03:00
@PLATFORM= $( PLATFORM) DEST = $( DEST) bash -c ' \
for platform in $$ ( tr "," "\n" <<< " $$ PLATFORM " ) ; do \
directory = " $$ {platform//\//_} " ; \
if [ [ -d " $$ DEST/ $$ directory " ] ] ; then \
2025-02-26 15:34:11 +04:00
echo $$ platform; \
2024-12-17 18:37:41 +03:00
mv -f " $$ DEST/ $$ directory/ " * $$ DEST; \
rmdir " $$ DEST/ $$ directory/ " ; \
fi ; \
done '
2021-08-13 16:12:38 +03:00
2024-05-10 12:08:16 +02:00
generate : ## Generate .proto definitions.
2025-02-26 15:34:11 +04:00
@$( MAKE) local-$@ DEST = ./
2024-05-10 12:08:16 +02:00
2021-08-13 16:12:38 +03:00
lint-golangci-lint : ## Runs golangci-lint linter.
@$( MAKE) target-$@
lint-gofumpt : ## Runs gofumpt linter.
@$( MAKE) target-$@
.PHONY : fmt
fmt : ## Formats the source code
@docker run --rm -it -v $( PWD) :/src -w /src golang:$( GO_VERSION) \
2024-03-12 18:12:45 +04:00
bash -c " export GOTOOLCHAIN=local; \
2023-10-11 14:51:30 +04:00
export GO111MODULE = on; export GOPROXY = https://proxy.golang.org; \
2022-08-25 20:29:58 +04:00
go install mvdan.cc/gofumpt@$( GOFUMPT_VERSION) && \
gofumpt -w ."
2023-01-30 20:44:11 +04:00
lint-govulncheck : ## Runs govulncheck linter.
@$( MAKE) target-$@
2021-08-13 16:12:38 +03:00
.PHONY : base
base : ## Prepare base toolchain
@$( MAKE) target-$@
.PHONY : unit -tests
unit-tests : ## Performs unit tests
@$( MAKE) local-$@ DEST = $( ARTIFACTS)
.PHONY : unit -tests -race
unit-tests-race : ## Performs unit tests with race detection enabled.
@$( MAKE) target-$@
2021-09-22 23:08:22 +03:00
.PHONY : $( ARTIFACTS ) /discovery -service -linux -amd 64
$(ARTIFACTS)/discovery-service-linux-amd64 :
@$( MAKE) local-discovery-service-linux-amd64 DEST = $( ARTIFACTS)
2021-08-13 16:12:38 +03:00
2021-09-22 23:08:22 +03:00
.PHONY : discovery -service -linux -amd 64
discovery-service-linux-amd64 : $( ARTIFACTS ) /discovery -service -linux -amd 64 ## Builds executable for discovery-service-linux-amd64.
2021-08-13 16:12:38 +03:00
2024-01-21 12:30:28 +02:00
.PHONY : $( ARTIFACTS ) /discovery -service -linux -arm 64
$(ARTIFACTS)/discovery-service-linux-arm64 :
@$( MAKE) local-discovery-service-linux-arm64 DEST = $( ARTIFACTS)
.PHONY : discovery -service -linux -arm 64
discovery-service-linux-arm64 : $( ARTIFACTS ) /discovery -service -linux -arm 64 ## Builds executable for discovery-service-linux-arm64.
2021-09-22 23:08:22 +03:00
.PHONY : discovery -service
2024-01-21 12:30:28 +02:00
discovery-service : discovery -service -linux -amd 64 discovery -service -linux -arm 64 ## Builds executables for discovery-service.
2021-08-13 16:12:38 +03:00
.PHONY : lint -markdown
lint-markdown : ## Runs markdownlint.
@$( MAKE) target-$@
.PHONY : lint
2024-05-10 12:08:16 +02:00
lint : lint -golangci -lint lint -gofumpt lint -govulncheck lint -markdown ## Run all linters for the project.
2021-08-13 16:12:38 +03:00
2021-09-22 23:08:22 +03:00
.PHONY : image -discovery -service
image-discovery-service : ## Builds image for discovery-service.
2025-02-26 15:34:11 +04:00
@$( MAKE) registry-$@ IMAGE_NAME = "discovery-service"
2024-05-10 12:08:16 +02:00
.PHONY : $( ARTIFACTS ) /snapshot -decoder -linux -amd 64
$(ARTIFACTS)/snapshot-decoder-linux-amd64 :
@$( MAKE) local-snapshot-decoder-linux-amd64 DEST = $( ARTIFACTS)
.PHONY : snapshot -decoder -linux -amd 64
snapshot-decoder-linux-amd64 : $( ARTIFACTS ) /snapshot -decoder -linux -amd 64 ## Builds executable for snapshot-decoder-linux-amd64.
.PHONY : $( ARTIFACTS ) /snapshot -decoder -linux -arm 64
$(ARTIFACTS)/snapshot-decoder-linux-arm64 :
@$( MAKE) local-snapshot-decoder-linux-arm64 DEST = $( ARTIFACTS)
.PHONY : snapshot -decoder -linux -arm 64
snapshot-decoder-linux-arm64 : $( ARTIFACTS ) /snapshot -decoder -linux -arm 64 ## Builds executable for snapshot-decoder-linux-arm64.
.PHONY : snapshot -decoder
snapshot-decoder : snapshot -decoder -linux -amd 64 snapshot -decoder -linux -arm 64 ## Builds executables for snapshot-decoder.
2021-08-13 16:12:38 +03:00
.PHONY : rekres
rekres :
@docker pull $( KRES_IMAGE)
2024-01-12 18:10:16 +04:00
@docker run --rm --net= host --user $( shell id -u) :$( shell id -g) -v $( PWD) :/src -w /src -e GITHUB_TOKEN $( KRES_IMAGE)
2021-08-13 16:12:38 +03:00
.PHONY : help
help : ## This help menu.
@echo " $$ HELP_MENU_HEADER "
@grep -E '^[a-zA-Z%_-]+:.*?## .*$$' $( MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY : release -notes
2024-05-10 12:08:16 +02:00
release-notes : $( ARTIFACTS )
2021-08-13 16:12:38 +03:00
@ARTIFACTS= $( ARTIFACTS) ./hack/release.sh $@ $( ARTIFACTS) /RELEASE_NOTES.md $( TAG)
2022-08-25 20:29:58 +04:00
.PHONY : conformance
conformance :
@docker pull $( CONFORMANCE_IMAGE)
@docker run --rm -it -v $( PWD) :/src -w /src $( CONFORMANCE_IMAGE) enforce