2019-12-23 21:36:14 +03:00
REGISTRY ?= docker.io
USERNAME ?= autonomy
2019-12-24 23:23:52 +03:00
SHA ?= $( shell git describe --match= none --always --abbrev= 8 --dirty)
TAG ?= $( shell git describe --tag --always --dirty)
BRANCH ?= $( shell git rev-parse --abbrev-ref HEAD)
2019-12-23 21:36:14 +03:00
REGISTRY_AND_USERNAME := $( REGISTRY) /$( USERNAME)
2020-02-13 23:07:36 +03:00
DOCKER_LOGIN_ENABLED ?= true
2019-12-23 21:36:14 +03:00
2019-12-24 23:23:52 +03:00
ARTIFACTS := _out
2020-02-14 15:26:44 +03:00
TOOLS ?= autonomy/tools:v0.1.0-1-g1c0644f
2019-12-24 23:23:52 +03:00
GO_VERSION ?= 1.13
OPERATING_SYSTEM := $( shell uname -s | tr "[:upper:]" "[:lower:]" )
OSCTL_DEFAULT_TARGET := osctl-$( OPERATING_SYSTEM)
2020-01-05 00:19:34 +03:00
INTEGRATION_TEST_DEFAULT_TARGET := integration-test-$( OPERATING_SYSTEM)
2020-01-24 07:52:02 +03:00
KUBECTL_URL ?= https://storage.googleapis.com/kubernetes-release/release/v1.17.1/bin/$( OPERATING_SYSTEM) /amd64/kubectl
SONOBUOY_VERSION ?= 0.17.1
SONOBUOY_URL ?= https://github.com/heptio/sonobuoy/releases/download/v$( SONOBUOY_VERSION) /sonobuoy_$( SONOBUOY_VERSION) _$( OPERATING_SYSTEM) _amd64.tar.gz
2019-12-24 23:23:52 +03:00
TESTPKGS ?= ./...
BUILD := docker buildx build
2019-12-23 21:36:14 +03:00
PLATFORM ?= linux/amd64
PROGRESS ?= auto
PUSH ?= false
COMMON_ARGS := --file= Dockerfile
COMMON_ARGS += --progress= $( PROGRESS)
COMMON_ARGS += --platform= $( PLATFORM)
COMMON_ARGS += --push= $( PUSH)
COMMON_ARGS += --build-arg= TOOLS = $( TOOLS)
COMMON_ARGS += --build-arg= SHA = $( SHA)
COMMON_ARGS += --build-arg= TAG = $( TAG)
COMMON_ARGS += --build-arg= GO_VERSION = $( GO_VERSION)
2019-12-27 23:49:24 +03:00
COMMON_ARGS += --build-arg= ARTIFACTS = $( ARTIFACTS)
2019-11-01 07:55:58 +03:00
COMMON_ARGS += --build-arg= TESTPKGS = $( TESTPKGS)
2020-02-14 15:26:44 +03:00
COMMON_ARGS += --build-arg= USERNAME = $( USERNAME)
2020-02-20 14:33:12 +03:00
COMMON_ARGS += --build-arg= http_proxy = $( http_proxy)
COMMON_ARGS += --build-arg= https_proxy = $( https_proxy)
2019-04-24 04:52:31 +03:00
2020-01-05 00:19:34 +03:00
all : initramfs kernel installer osctl talos
2019-12-24 23:23:52 +03:00
# Help Menu
d e f i n e H E L P _ M E N U _ H E A D E R
# 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 )
- buildx (https : //github .com /docker /buildx )
## 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 f e a t u r e s n o t c u r r e n t l y s u p p o r t e d b y t h e d e f a u l t
builder instance (docker driver). To create a compatible builder instance, run :
2019-07-23 17:17:16 +03:00
2019-12-24 23:23:52 +03:00
` ` `
d o c k e r b u i l d x c r e a t e - - d r i v e r d o c k e r - c o n t a i n e r - - n a m e l o c a l - - b u i l d k i t d - f l a g s '--allow-insecure-entitlement security.insecure' - - u s e
` ` `
2019-04-29 19:25:04 +03:00
2019-12-24 23:23:52 +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 .
2019-02-15 07:32:00 +03:00
2020-02-13 23:07:36 +03:00
> Note : The security .insecure entitlement is only required , and used by the unit -tests target and targets which build container images
f o r a p p l i c a t i o n s u s i n g ` i m g ` t o o l .
2019-06-05 21:44:15 +03:00
2019-12-24 23:23:52 +03:00
## Artifacts
2019-02-15 07:32:00 +03:00
2019-12-24 23:23:52 +03:00
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
registry "$(REGISTRY)", username "$(USERNAME)", and a dynamic tag (e.g. $(REGISTRY_AND_USERNAME)/image : $( TAG ) ).
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 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
export HELP_MENU_HEADER
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}'
# Build Abstractions
.PHONY : base
target-% : ## Builds the specified target defined in the Dockerfile. The build result will only remain in the build cache.
2019-12-23 21:36:14 +03:00
@$( BUILD) \
2019-12-24 23:23:52 +03:00
--target= $* \
$( COMMON_ARGS) \
$( TARGET_ARGS) .
2019-11-01 07:55:58 +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.
2019-12-24 23:23:52 +03:00
@$( MAKE) target-$* TARGET_ARGS = " --output=type=local,dest= $( DEST) $( TARGET_ARGS) "
2019-11-01 07:55:58 +03:00
docker-% : ## Builds the specified target defined in the Dockerfile using the docker output type. The build result will be output to the specified local destination.
2019-12-24 23:23:52 +03:00
@mkdir -p $( DEST)
@$( MAKE) target-$* TARGET_ARGS = " --output type=docker,dest= $( DEST) / $* .tar,name= $( REGISTRY_AND_USERNAME) / $* : $( TAG) $( TARGET_ARGS) "
2019-11-01 07:55:58 +03:00
hack-test-% : ## Runs the specied script in ./hack/test with well known environment variables.
2020-01-24 07:52:02 +03:00
@./hack/test/$* .sh
2019-11-01 07:55:58 +03:00
2019-12-24 23:23:52 +03:00
# Generators
2019-04-24 04:52:31 +03:00
2019-08-09 06:45:13 +03:00
.PHONY : generate
2019-12-24 23:23:52 +03:00
generate : ## Generates source code from protobuf definitions.
@$( MAKE) local-$@ DEST = ./
2019-08-09 06:45:13 +03:00
2019-11-09 18:22:43 +03:00
.PHONY : docs
2019-11-01 07:55:58 +03:00
docs : ## Generates the documentation for machine config, and osctl.
2019-12-24 23:23:52 +03:00
@rm -rf docs/osctl/*
@$( MAKE) local-$@ DEST = ./
# Local Artifacts
2019-11-09 18:22:43 +03:00
2019-04-19 05:31:43 +03:00
.PHONY : kernel
2019-12-24 23:23:52 +03:00
kernel : ## Outputs the kernel package contents (vmlinuz, and vmlinux) to the artifact directory.
@$( MAKE) local-$@ DEST = $( ARTIFACTS)
@-rm -rf $( ARTIFACTS) /modules
2019-01-18 06:14:52 +03:00
2019-04-19 05:31:43 +03:00
.PHONY : initramfs
2020-02-14 15:26:44 +03:00
initramfs : ## Builds the compressed initramfs and outputs it to the artifact directory.
@$( MAKE) local-$@ DEST = $( ARTIFACTS) TARGET_ARGS = "--allow security.insecure"
2018-12-20 09:22:05 +03:00
2019-12-24 23:23:52 +03:00
.PHONY : installer
2020-02-14 15:26:44 +03:00
installer : ## Builds the container image for the installer and outputs it to the artifact directory.
@$( MAKE) docker-$@ DEST = $( ARTIFACTS) TARGET_ARGS = "--allow security.insecure"
2019-12-24 23:23:52 +03:00
@docker load < $( ARTIFACTS) /$@ .tar
2019-10-31 01:52:36 +03:00
2019-12-24 23:23:52 +03:00
.PHONY : talos
2020-02-14 15:26:44 +03:00
talos : ## Builds the Talos container image and outputs it to the artifact directory.
@$( MAKE) docker-$@ DEST = $( ARTIFACTS) TARGET_ARGS = "--allow security.insecure"
2019-12-24 23:23:52 +03:00
@mv $( ARTIFACTS) /$@ .tar $( ARTIFACTS) /container.tar
@docker load < $( ARTIFACTS) /container.tar
2018-12-20 09:22:05 +03:00
2019-12-24 23:23:52 +03:00
osctl-% :
@$( MAKE) local-$@ DEST = $( ARTIFACTS)
osctl : $( OSCTL_DEFAULT_TARGET ) ## Builds the osctl binary for the local machine.
2019-11-01 07:55:58 +03:00
image-% : ## Builds the specified image. Valid options are aws, azure, digital-ocean, gcp, and vmware (e.g. image-aws)
@docker run --rm -v /dev:/dev -v $( PWD) /$( ARTIFACTS) :/out --privileged autonomy/installer:$( TAG) image --platform $*
images : image -aws image -azure image -digital -ocean image -gcp image -vmware ## Builds all known images (AWS, Azure, Digital Ocean, GCP, and VMware).
2019-04-05 07:34:58 +03:00
2019-08-09 06:45:13 +03:00
.PHONY : iso
2019-12-24 23:23:52 +03:00
iso : ## Builds the ISO and outputs it to the artifact directory.
@docker run --rm -i -v $( PWD) /$( ARTIFACTS) :/out autonomy/installer:$( TAG) iso
2019-08-09 06:45:13 +03:00
2020-01-09 23:25:25 +03:00
.PHONY : boot
boot : ## Creates a compressed tarball that includes vmlinuz and initramfs.xz. Note that these files must already be present in the artifacts directory.
@tar -C $( ARTIFACTS) -czf $( ARTIFACTS) /boot.tar.gz vmlinuz initramfs.xz
2019-12-24 23:23:52 +03:00
# Code Quality
2019-02-19 19:41:41 +03:00
2019-12-24 23:23:52 +03:00
.PHONY : fmt
fmt : ## Formats the source code.
@docker run --rm -it -v $( PWD) :/src -w /src golang:$( GO_VERSION) bash -c "export GO111MODULE=on; export GOPROXY=https://proxy.golang.org; cd /tmp && go mod init tmp && go get mvdan.cc/gofumpt/gofumports && cd - && gofumports -w -local github.com/talos-systems/talos ."
2019-04-28 22:06:03 +03:00
2019-11-01 07:55:58 +03:00
lint-% : ## Runs the specified linter. Valid options are go, protobuf, and markdown (e.g. lint-go).
2019-12-24 23:23:52 +03:00
@$( MAKE) target-lint-$*
2019-08-02 18:05:34 +03:00
2019-12-24 23:23:52 +03:00
lint : ## Runs linters on go, protobuf, and markdown file types.
@$( MAKE) lint-go lint-protobuf lint-markdown
# Tests
2019-06-17 19:36:48 +03:00
2019-08-09 06:45:13 +03:00
.PHONY : unit -tests
2020-02-14 15:26:44 +03:00
unit-tests : ## Performs unit tests.
2020-01-24 07:52:02 +03:00
@$( MAKE) local-$@ DEST = $( ARTIFACTS) TARGET_ARGS = "--allow security.insecure"
2019-08-07 01:08:27 +03:00
2019-08-09 06:45:13 +03:00
.PHONY : unit -tests -race
2019-12-24 23:23:52 +03:00
unit-tests-race : ## Performs unit tests with race detection enabled.
2020-01-24 07:52:02 +03:00
@$( MAKE) target-$@
2019-12-24 23:23:52 +03:00
2020-01-24 07:52:02 +03:00
$(ARTIFACTS)/$(INTEGRATION_TEST_DEFAULT_TARGET)-amd64 :
@$( MAKE) local-$( INTEGRATION_TEST_DEFAULT_TARGET) DEST = $( ARTIFACTS)
$(ARTIFACTS)/sonobuoy :
@mkdir -p $( ARTIFACTS)
@curl -L -o /tmp/sonobuoy.tar.gz ${ SONOBUOY_URL }
@tar -xf /tmp/sonobuoy.tar.gz -C $( ARTIFACTS)
$(ARTIFACTS)/kubectl :
@mkdir -p $( ARTIFACTS)
@curl -L -o $( ARTIFACTS) /kubectl " $( KUBECTL_URL) "
@chmod +x $( ARTIFACTS) /kubectl
e2e-% : $( ARTIFACTS ) /$( INTEGRATION_TEST_DEFAULT_TARGET ) -amd 64 $( ARTIFACTS ) /sonobuoy $( ARTIFACTS ) /kubectl ## Runs the E2E test for the specified platform (e.g. e2e-docker).
@$( MAKE) hack-test-$@ \
PLATFORM = $* \
TAG = $( TAG) \
SHA = $( SHA) \
IMAGE = $( REGISTRY_AND_USERNAME) /talos:$( TAG) \
ARTIFACTS = $( ARTIFACTS) \
OSCTL = $( PWD) /$( ARTIFACTS) /$( OSCTL_DEFAULT_TARGET) -amd64 \
INTEGRATION_TEST = $( PWD) /$( ARTIFACTS) /$( INTEGRATION_TEST_DEFAULT_TARGET) -amd64 \
KUBECTL = $( PWD) /$( ARTIFACTS) /kubectl \
SONOBUOY = $( PWD) /$( ARTIFACTS) /sonobuoy
2019-12-24 23:23:52 +03:00
# Utilities
2019-01-19 12:58:26 +03:00
2019-04-12 09:40:30 +03:00
.PHONY : login
2019-12-24 23:23:52 +03:00
login : ## Logs in to the configured container registry.
2020-02-13 23:07:36 +03:00
i f e q ( $( DOCKER_LOGIN_ENABLED ) , t r u e )
2019-12-24 23:23:52 +03:00
@docker login --username " $( DOCKER_USERNAME) " --password " $( DOCKER_PASSWORD) " $( REGISTRY)
2020-02-13 23:07:36 +03:00
e n d i f
2019-04-12 09:40:30 +03:00
2020-01-01 21:28:44 +03:00
push : login ## Pushes the installer, and talos images to the configured container registry with the generated tag.
2020-02-13 23:07:36 +03:00
@docker push $( REGISTRY_AND_USERNAME) /installer:$( TAG)
@docker push $( REGISTRY_AND_USERNAME) /talos:$( TAG)
2020-01-01 21:28:44 +03:00
push-% : login ## Pushes the installer, and talos images to the configured container registry with the specified tag (e.g. push-latest).
2020-02-13 23:07:36 +03:00
@docker tag $( REGISTRY_AND_USERNAME) /installer:$( TAG) $( REGISTRY_AND_USERNAME) /installer:$*
@docker tag $( REGISTRY_AND_USERNAME) /talos:$( TAG) $( REGISTRY_AND_USERNAME) /talos:$*
@docker push $( REGISTRY_AND_USERNAME) /installer:$*
@docker push $( REGISTRY_AND_USERNAME) /talos:$*
2019-04-12 09:40:30 +03:00
2019-04-19 05:31:43 +03:00
.PHONY : clean
2019-12-24 23:23:52 +03:00
clean : ## Cleans up all artifacts.
2020-01-24 07:52:02 +03:00
@-rm -rf $( ARTIFACTS)