2019-12-23 10:36:14 -08:00
REGISTRY ?= docker.io
USERNAME ?= autonomy
2019-12-24 12:23:52 -08: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 10:36:14 -08:00
REGISTRY_AND_USERNAME := $( REGISTRY) /$( USERNAME)
2019-12-24 12:23:52 -08:00
ARTIFACTS := _out
2020-01-04 13:19:34 -08:00
IMAGES := $( ARTIFACTS) /images
2020-01-19 11:45:36 -08:00
TOOLS ?= autonomy/tools:v0.1.0
2019-12-24 12:23:52 -08:00
GO_VERSION ?= 1.13
OPERATING_SYSTEM := $( shell uname -s | tr "[:upper:]" "[:lower:]" )
OSCTL_DEFAULT_TARGET := osctl-$( OPERATING_SYSTEM)
2020-01-04 13:19:34 -08:00
INTEGRATION_TEST_DEFAULT_TARGET := integration-test-$( OPERATING_SYSTEM)
2019-12-24 12:23:52 -08:00
TESTPKGS ?= ./...
BUILD := docker buildx build
2019-12-23 10:36:14 -08: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)
2020-01-04 13:19:34 -08:00
COMMON_ARGS += --build-arg= IMAGES = $( IMAGES)
2019-12-27 20:49:24 +00:00
COMMON_ARGS += --build-arg= ARTIFACTS = $( ARTIFACTS)
2019-11-01 04:55:58 +00:00
COMMON_ARGS += --build-arg= TESTPKGS = $( TESTPKGS)
2019-04-23 20:52:31 -05:00
2020-01-04 13:19:34 -08:00
all : initramfs kernel installer osctl talos
2019-12-24 12:23:52 -08: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 12:23:52 -08: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 11:25:04 -05:00
2019-12-24 12:23:52 -08: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-14 22:32:00 -06:00
2019-12-24 12:23:52 -08:00
> Note : The security .insecure entitlement is only required , and used by the unit -tests target .
2019-06-05 11:44:15 -07:00
2019-12-24 12:23:52 -08:00
## Artifacts
2019-02-14 22:32:00 -06:00
2019-12-24 12:23:52 -08: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 10:36:14 -08:00
@$( BUILD) \
2019-12-24 12:23:52 -08:00
--target= $* \
$( COMMON_ARGS) \
$( TARGET_ARGS) .
2019-11-01 04:55:58 +00: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 12:23:52 -08:00
@$( MAKE) target-$* TARGET_ARGS = " --output=type=local,dest= $( DEST) $( TARGET_ARGS) "
2019-11-01 04:55:58 +00: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 12:23:52 -08:00
@mkdir -p $( DEST)
@$( MAKE) target-$* TARGET_ARGS = " --output type=docker,dest= $( DEST) / $* .tar,name= $( REGISTRY_AND_USERNAME) / $* : $( TAG) $( TARGET_ARGS) "
2019-11-01 04:55:58 +00:00
hack-test-% : ## Runs the specied script in ./hack/test with well known environment variables.
@TAG= $( TAG) SHA = $( SHA) ARTIFACTS = $( ARTIFACTS) ./hack/test/$* .sh
2019-12-24 12:23:52 -08:00
# Generators
2019-04-23 20:52:31 -05:00
2019-08-09 03:45:13 +00:00
.PHONY : generate
2019-12-24 12:23:52 -08:00
generate : ## Generates source code from protobuf definitions.
@$( MAKE) local-$@ DEST = ./
2019-08-09 03:45:13 +00:00
2019-11-09 15:22:43 +00:00
.PHONY : docs
2019-11-01 04:55:58 +00:00
docs : ## Generates the documentation for machine config, and osctl.
2019-12-24 12:23:52 -08:00
@rm -rf docs/osctl/*
@$( MAKE) local-$@ DEST = ./
2019-11-01 04:55:58 +00:00
# Apps
2019-12-24 12:23:52 -08:00
2019-11-01 04:55:58 +00:00
apid : ## Builds the apid container image. The build result will be output to the specified local destination.
2020-01-04 13:19:34 -08:00
@$( MAKE) docker-$@ DEST = ./$( IMAGES)
2019-12-24 12:23:52 -08:00
machined : ## Builds machined. The build result will only remain in the build cache.
@$( MAKE) target-$@
2019-11-01 04:55:58 +00:00
networkd : ## Builds the networkd container image. The build result will be output to the specified local destination.
2020-01-04 13:19:34 -08:00
@$( MAKE) docker-$@ DEST = ./$( IMAGES)
2019-12-24 12:23:52 -08:00
2019-11-01 04:55:58 +00:00
ntpd : ## Builds the ntpd container image. The build result will be output to the specified local destination.
2020-01-04 13:19:34 -08:00
@$( MAKE) docker-$@ DEST = ./$( IMAGES)
2019-12-24 12:23:52 -08:00
2019-11-01 04:55:58 +00:00
osd : ## Builds the osd container image. The build result will be output to the specified local destination.
2020-01-04 13:19:34 -08:00
@$( MAKE) docker-$@ DEST = ./$( IMAGES)
2019-12-24 12:23:52 -08:00
2019-11-01 04:55:58 +00:00
trustd : ## Builds the trustd container image. The build result will be output to the specified local destination.
2020-01-04 13:19:34 -08:00
@$( MAKE) docker-$@ DEST = ./$( IMAGES)
2019-12-24 12:23:52 -08:00
apps : apid machined networkd ntpd osd trustd ## Builds all apps (apid, machined, networkd, ntpd, osd, and trustd).
# Local Artifacts
2019-11-09 15:22:43 +00:00
2019-04-18 19:31:43 -07:00
.PHONY : kernel
2019-12-24 12:23:52 -08:00
kernel : ## Outputs the kernel package contents (vmlinuz, and vmlinux) to the artifact directory.
@$( MAKE) local-$@ DEST = $( ARTIFACTS)
@-rm -rf $( ARTIFACTS) /modules
2019-01-17 19:14:52 -08:00
2019-04-18 19:31:43 -07:00
.PHONY : initramfs
2020-01-04 13:19:34 -08:00
initramfs : apps ## Builds the compressed initramfs and outputs it to the artifact directory.
2019-12-24 12:23:52 -08:00
@$( MAKE) local-$@ DEST = $( ARTIFACTS)
2018-12-19 22:22:05 -08:00
2019-12-24 12:23:52 -08:00
.PHONY : installer
2020-01-04 13:19:34 -08:00
installer : apps ## Builds the container image for the installer and outputs it to the artifact directory.
2019-12-24 12:23:52 -08:00
@$( MAKE) docker-$@ DEST = $( ARTIFACTS)
@docker load < $( ARTIFACTS) /$@ .tar
2019-10-30 22:52:36 +00:00
2019-12-24 12:23:52 -08:00
.PHONY : talos
2020-01-04 13:19:34 -08:00
talos : apps ## Builds the Talos container image and outputs it to the artifact directory.
2019-12-24 12:23:52 -08:00
@$( MAKE) docker-$@ DEST = $( ARTIFACTS)
@mv $( ARTIFACTS) /$@ .tar $( ARTIFACTS) /container.tar
@docker load < $( ARTIFACTS) /container.tar
2018-12-19 22:22:05 -08:00
2019-12-24 12:23:52 -08:00
osctl-% :
@$( MAKE) local-$@ DEST = $( ARTIFACTS)
osctl : $( OSCTL_DEFAULT_TARGET ) ## Builds the osctl binary for the local machine.
2019-11-01 04:55:58 +00: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-04 21:34:58 -07:00
2019-08-09 03:45:13 +00:00
.PHONY : iso
2019-12-24 12:23:52 -08: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 03:45:13 +00:00
2020-01-09 12:25:25 -08: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 12:23:52 -08:00
# Code Quality
2019-02-19 11:41:41 -05:00
2019-12-24 12:23:52 -08: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 12:06:03 -07:00
2019-11-01 04:55:58 +00:00
lint-% : ## Runs the specified linter. Valid options are go, protobuf, and markdown (e.g. lint-go).
2019-12-24 12:23:52 -08:00
@$( MAKE) target-lint-$*
2019-08-02 11:05:34 -04:00
2019-12-24 12:23:52 -08:00
lint : ## Runs linters on go, protobuf, and markdown file types.
@$( MAKE) lint-go lint-protobuf lint-markdown
# Tests
2019-06-17 12:36:48 -04:00
2019-08-09 03:45:13 +00:00
.PHONY : unit -tests
2019-12-24 12:23:52 -08:00
unit-tests : apps ## Performs unit tests.
2019-11-01 04:55:58 +00:00
@$( MAKE) local-$@ DEST = ./ TARGET_ARGS = "--allow security.insecure"
2019-08-07 01:08:27 +03:00
2019-08-09 03:45:13 +00:00
.PHONY : unit -tests -race
2019-12-24 12:23:52 -08:00
unit-tests-race : ## Performs unit tests with race detection enabled.
2019-11-01 04:55:58 +00:00
@$( MAKE) local-$@ DEST = ./
2019-04-16 00:41:11 +03:00
2020-01-04 13:19:34 -08:00
integration-test-% :
@$( MAKE) local-$@ DEST = $( ARTIFACTS)
integration-test : $( INTEGRATION_TEST_DEFAULT_TARGET ) ## Builds the integration-test binary for the local machine.
2019-10-25 22:57:52 +03:00
2020-01-21 19:37:12 -08:00
basic-integration-% : integration -test osctl talos ## Runs the basic integration test.
@$( MAKE) hack-test-basic-integration PROVISIONER = $*
2019-09-11 21:32:07 +00:00
2019-12-24 12:23:52 -08:00
.PHONY : e 2e -integration
e2e-integration : ## Runs the E2E integration for the specified cloud provider.
2019-11-01 04:55:58 +00:00
@$( MAKE) hack-test-$@
2019-10-23 21:31:18 -05:00
2019-11-01 04:55:58 +00:00
push-image-% : ## Pushes a VM image into the specified cloud provider. Valid options are aws, azure, and gcp (e.g. push-image-aws).
@$( MAKE) hack-test-$* -setup
2019-12-24 12:23:52 -08:00
.PHONY : capi
capi : ## Deploys Cluster API to the basic integration cluster.
2019-11-01 04:55:58 +00:00
@$( MAKE) hack-test-$@
2019-12-24 12:23:52 -08:00
# Utilities
2019-01-19 01:58:26 -08:00
2019-04-11 23:40:30 -07:00
.PHONY : login
2019-12-24 12:23:52 -08:00
login : ## Logs in to the configured container registry.
@docker login --username " $( DOCKER_USERNAME) " --password " $( DOCKER_PASSWORD) " $( REGISTRY)
2019-04-11 23:40:30 -07:00
2020-01-01 10:28:44 -08:00
push : login ## Pushes the installer, and talos images to the configured container registry with the generated tag.
2019-04-11 23:40:30 -07:00
@docker push autonomy/installer:$( TAG)
@docker push autonomy/talos:$( TAG)
2020-01-01 10:28:44 -08:00
push-% : login ## Pushes the installer, and talos images to the configured container registry with the specified tag (e.g. push-latest).
2019-11-27 15:39:53 +00:00
@docker tag autonomy/installer:$( TAG) autonomy/installer:$*
@docker tag autonomy/talos:$( TAG) autonomy/talos:$*
@docker push autonomy/installer:$*
@docker push autonomy/talos:$*
2019-04-11 23:40:30 -07:00
2019-04-18 19:31:43 -07:00
.PHONY : clean
2019-12-24 12:23:52 -08:00
clean : ## Cleans up all artifacts.
@-rm -rf $( ARTIFACTS) coverage.txt