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
TOOLS ?= autonomy/tools:8fdb32d
GO_VERSION ?= 1.13
OPERATING_SYSTEM := $( shell uname -s | tr "[:upper:]" "[:lower:]" )
OSCTL_DEFAULT_TARGET := osctl-$( OPERATING_SYSTEM)
OSCTL_COMMAND := $( ARTIFACTS) /osctl-$( OPERATING_SYSTEM) -amd64
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)
2019-12-24 12:23:52 -08:00
COMMON_ARGS += --build-arg= IMAGES = $( ARTIFACTS) /images
2019-04-23 20:52:31 -05:00
2019-12-24 12:23:52 -08:00
all : help
# 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) .
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 (DEST).
@$( MAKE) target-$* TARGET_ARGS = " --output=type=local,dest= $( DEST) $( TARGET_ARGS) "
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 (DEST).
@mkdir -p $( DEST)
@$( MAKE) target-$* TARGET_ARGS = " --output type=docker,dest= $( DEST) / $* .tar,name= $( REGISTRY_AND_USERNAME) / $* : $( TAG) $( TARGET_ARGS) "
# 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-12-24 12:23:52 -08:00
docs : ## Generates the documentation for osctl.
@rm -rf docs/osctl/*
@$( MAKE) local-$@ DEST = ./
# Services
apid : ## Builds the apid container image. The build result will be output to the specified local destination (DEST).
@$( MAKE) docker-$@ DEST = ./$( ARTIFACTS) /images
machined : ## Builds machined. The build result will only remain in the build cache.
@$( MAKE) target-$@
networkd : ## Builds the networkd container image. The build result will be output to the specified local destination (DEST).
@$( MAKE) docker-$@ DEST = ./$( ARTIFACTS) /images
ntpd : ## Builds the ntpd container image. The build result will be output to the specified local destination (DEST).
@$( MAKE) docker-$@ DEST = ./$( ARTIFACTS) /images
osd : ## Builds the osd container image. The build result will be output to the specified local destination (DEST).
@$( MAKE) docker-$@ DEST = ./$( ARTIFACTS) /images
trustd : ## Builds the trustd container image. The build result will be output to the specified local destination (DEST).
@$( MAKE) docker-$@ DEST = ./$( ARTIFACTS) /images
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
2019-12-24 12:23:52 -08:00
initramfs : ## Builds the compressed initramfs and outputs it to the artifact directory.
@$( MAKE) local-$@ DEST = $( ARTIFACTS)
2018-12-19 22:22:05 -08:00
2019-12-24 12:23:52 -08:00
.PHONY : installer
installer : ## Builds the container image for the installer and outputs it to the artifact directory.
@$( 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
talos : ## Builds the Talos container image and outputs it to the artifact directory.
@$( 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.
image-build-% : installer
@docker run --rm -v /dev:/dev -v $( PWD) /$( ARTIFACTS) :/out --privileged autonomy/installer:$( TAG) install -n $* -r -p $* -u $( CONFIG_SOURCE) $( EXTRA_IMAGE_ARGS)
2019-02-19 11:41:41 -05:00
2019-08-09 03:45:13 +00:00
.PHONY : image -aws
2019-12-24 12:23:52 -08:00
image-aws : ## Builds a VM image suitable for use in AWS and outputs it to the artifact directory.
@$( MAKE) image-build-aws CONFIG_SOURCE = none EXTRA_IMAGE_ARGS = "-e console=tty1 -e console=ttyS0"
@tar -C $( PWD) /$( ARTIFACTS) -czf $( PWD) /$( ARTIFACTS) /aws.tar.gz aws.raw
@rm -rf $( PWD) /$( ARTIFACTS) /aws.raw
2019-04-30 10:21:51 -07:00
2019-08-09 03:45:13 +00:00
.PHONY : image -azure
2019-12-24 12:23:52 -08:00
image-azure : ## Builds a VM image suitable for use in Azure and outputs it to the artifact directory.
@$( MAKE) image-build-azure CONFIG_SOURCE = none EXTRA_IMAGE_ARGS = "-e console=ttyS0,115200n8 -e earlyprintk=ttyS0,115200 -e rootdelay=300"
@docker run --rm -v $( PWD) /$( ARTIFACTS) :/out \
2019-07-27 08:09:50 +00:00
--entrypoint qemu-img \
autonomy/installer:$( TAG) \
convert \
-f raw \
-o subformat = fixed,force_size \
2019-08-09 03:45:13 +00:00
-O vpc /out/azure.raw /out/azure.vhd
2019-12-24 12:23:52 -08:00
@tar -C $( PWD) /$( ARTIFACTS) -czf $( PWD) /$( ARTIFACTS) /azure.tar.gz azure.vhd
@rm -rf $( PWD) /$( ARTIFACTS) /azure.raw $( PWD) /$( ARTIFACTS) /azure.vhd
2019-08-09 03:45:13 +00:00
2019-10-28 15:43:59 +00:00
.PHONY : image -digital -ocean
2019-12-24 12:23:52 -08:00
image-digital-ocean : ## Builds a VM image suitable for use in Digital Ocean and outputs it to the artifact directory.
@$( MAKE) image-build-digital-ocean CONFIG_SOURCE = none EXTRA_IMAGE_ARGS = "-e console=ttyS0"
@gzip -f $( PWD) /$( ARTIFACTS) /digital-ocean.raw
2019-10-28 15:43:59 +00:00
2019-08-11 21:38:24 +00:00
.PHONY : image -gcp
2019-12-24 12:23:52 -08:00
image-gcp : ## Builds a VM image suitable for use in GCP and outputs it to the artifact directory.
@$( MAKE) image-build-gcp CONFIG_SOURCE = none EXTRA_IMAGE_ARGS = "-e console=ttyS0"
@mv $( PWD) /$( ARTIFACTS) /gcp.raw $( PWD) /$( ARTIFACTS) /disk.raw
@tar -C $( PWD) /$( ARTIFACTS) -czf $( PWD) /$( ARTIFACTS) /gcp.tar.gz disk.raw
@rm -rf $( PWD) /$( ARTIFACTS) /disk.raw
2019-08-09 03:45:13 +00:00
2019-09-13 15:10:47 -05:00
.PHONY : image -vmware
2019-12-24 12:23:52 -08:00
image-vmware : ## Builds a VM image suitable for use in VMware and outputs it to the artifact directory.
@$( MAKE) image-build-vmware CONFIG_SOURCE = guestinfo EXTRA_IMAGE_ARGS = "-e console=tty0 -e earlyprintk=ttyS0,115200"
@docker run --rm -v /dev:/dev -v $( PWD) /$( ARTIFACTS) :/out \
2019-12-24 09:28:58 -08:00
--privileged \
2019-09-13 15:10:47 -05:00
autonomy/installer:$( TAG) \
2019-12-24 12:23:52 -08:00
ova -n vmware
@rm -rf $( PWD) /$( ARTIFACTS) /talos.raw
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
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-12-24 12:23:52 -08:00
lint-% :
@$( 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.
@$( MAKE) local-$@ DEST = ./ TARGET_ARGS = " --build-arg=TESTPKGS= $( TESTPKGS) --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.
@$( MAKE) local-$@ DEST = ./ TARGET_ARGS = " --build-arg=TESTPKGS= $( TESTPKGS) "
2019-04-16 00:41:11 +03:00
2019-10-25 22:57:52 +03:00
.PHONY : integration -test
2019-12-24 12:23:52 -08:00
integration-test : ## Runs the CLI and API integration tests against a running cluster.
@$( MAKE) local-$@ DEST = ./bin
2019-10-25 22:57:52 +03:00
2019-12-24 12:23:52 -08:00
.PHONY : basic -integration
basic-integration : ## Runs the basic integration test.
@TAG= $( TAG) SHA = $( SHA) go run ./internal/test-framework/main.go basic-integration --artifacts= $( ARTIFACTS)
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.
@TAG= $( TAG) SHA = $( SHA) ./hack/test/$@ .sh
2019-08-27 21:45:59 +00:00
2019-12-24 12:23:52 -08:00
.PHONY : image -test
image-test : ## Builds a test VM image.
@$( MAKE) image-build-test CONFIG_SOURCE = none
2019-10-23 21:31:18 -05:00
2019-12-24 12:23:52 -08:00
# push-image-%: ## Pushes a VM image into the specified cloud provider. Valid options are aws, azure, and gcp (e.g. push-image-aws).
# @TAG=$(TAG) SHA=$(SHA) ./hack/test/$*-setup.sh
.PHONY : capi
capi : ## Deploys Cluster API to the basic integration cluster.
@TAG= $( TAG) ./hack/test/$@ .sh
# 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
2019-12-24 12:23:52 -08:00
push-% : login ## Pushes the installer, and talos images to the configured container registry with the specified tag (e.g. push-latest).
2019-04-11 23:40:30 -07:00
@docker push autonomy/installer:$( TAG)
@docker push autonomy/talos:$( TAG)
2019-08-17 15:21:20 -05:00
i f e q ( $( BRANCH ) , m a s t e r )
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-08-17 15:21:20 -05:00
e n d i f
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