2019-02-23 20:31:49 +03:00
SHA = $( shell gitmeta git sha)
TAG = $( shell gitmeta image tag)
2018-12-20 09:22:05 +03:00
2019-02-15 07:32:00 +03:00
VPATH = $( PATH)
2019-04-14 19:59:57 +03:00
KERNEL_IMAGE ?= autonomy/kernel:8fd9a83
2019-03-28 02:33:03 +03:00
TOOLCHAIN_IMAGE ?= autonomy/toolchain:989387e
2019-02-20 07:58:06 +03:00
DOCKER_ARGS ?=
2019-02-15 07:32:00 +03:00
BUILDKIT_VERSION ?= v0.3.3
BUILDKIT_IMAGE ?= moby/buildkit:$( BUILDKIT_VERSION)
BUILDKIT_HOST ?= tcp://0.0.0.0:1234
2019-04-12 19:52:16 +03:00
BUILDKIT_CACHE ?= -v $( HOME) /.buildkit:/var/lib/buildkit
2019-02-15 07:32:00 +03:00
BUILDKIT_CONTAINER_NAME ?= talos-buildkit
2019-02-15 18:57:27 +03:00
BUILDKIT_CONTAINER_STOPPED := $( shell docker ps --filter name = $( BUILDKIT_CONTAINER_NAME) --filter status = exited --format= '{{.Names}}' 2>/dev/null)
BUILDKIT_CONTAINER_RUNNING := $( shell docker ps --filter name = $( BUILDKIT_CONTAINER_NAME) --filter status = running --format= '{{.Names}}' 2>/dev/null)
2019-02-15 07:32:00 +03:00
UNAME_S := $( shell uname -s)
i f e q ( $( UNAME_S ) , L i n u x )
BUILDCTL_ARCHIVE := https://github.com/moby/buildkit/releases/download/$( BUILDKIT_VERSION) /buildkit-$( BUILDKIT_VERSION) .linux-amd64.tar.gz
e n d i f
i f e q ( $( UNAME_S ) , D a r w i n )
BUILDCTL_ARCHIVE := https://github.com/moby/buildkit/releases/download/$( BUILDKIT_VERSION) /buildkit-$( BUILDKIT_VERSION) .darwin-amd64.tar.gz
e n d i f
BINDIR ?= /usr/local/bin
2019-04-12 19:52:16 +03:00
CONFORM_VERSION ?= 57c9dbd
2018-12-20 09:22:05 +03:00
2019-02-23 20:31:49 +03:00
COMMON_ARGS = --progress= plain
2019-01-24 02:48:02 +03:00
COMMON_ARGS += --frontend= dockerfile.v0
2019-01-19 12:58:26 +03:00
COMMON_ARGS += --local context = .
COMMON_ARGS += --local dockerfile = .
2019-01-24 02:48:02 +03:00
COMMON_ARGS += --frontend-opt build-arg:KERNEL_IMAGE= $( KERNEL_IMAGE)
COMMON_ARGS += --frontend-opt build-arg:TOOLCHAIN_IMAGE= $( TOOLCHAIN_IMAGE)
2019-01-19 12:58:26 +03:00
COMMON_ARGS += --frontend-opt build-arg:SHA= $( SHA)
COMMON_ARGS += --frontend-opt build-arg:TAG= $( TAG)
2018-12-20 09:22:05 +03:00
2019-04-14 19:27:20 +03:00
# to allow tests to run containerd
DOCKER_TEST_ARGS = --security-opt seccomp:unconfined --privileged -v /var/lib/containerd/
2019-04-12 01:24:51 +03:00
all : ci kernel initramfs rootfs osctl -linux -amd 64 osctl -darwin -amd 64 osinstall -linux -amd 64 installer talos
2019-02-15 07:32:00 +03:00
.PHONY : builddeps
builddeps : gitmeta buildctl
gitmeta :
2019-04-04 04:29:21 +03:00
GO111MODULE = off go get github.com/talos-systems/gitmeta
2019-02-15 07:32:00 +03:00
buildctl :
@wget -qO - $( BUILDCTL_ARCHIVE) | \
sudo tar -zxf - -C $( BINDIR) --strip-components 1 bin/buildctl
.PHONY : buildkitd
buildkitd :
ifeq (tcp : //0.0.0.0:1234, $( findstring tcp ://0.0.0.0:1234,$ ( BUILDKIT_HOST ) ) )
i f e q ( $( BUILDKIT_CONTAINER_STOPPED ) , $( BUILDKIT_CONTAINER_NAME ) )
@echo "Removing exited talos-buildkit container"
@docker rm $( BUILDKIT_CONTAINER_NAME)
e n d i f
i f n e q ( $( BUILDKIT_CONTAINER_RUNNING ) , $( BUILDKIT_CONTAINER_NAME ) )
@echo "Starting talos-buildkit container"
@docker run \
--name $( BUILDKIT_CONTAINER_NAME) \
-d \
--privileged \
2019-04-12 19:52:16 +03:00
-p 1234:1234 \
$( BUILDKIT_CACHE) \
2019-02-15 07:32:00 +03:00
$( BUILDKIT_IMAGE) \
--addr $( BUILDKIT_HOST)
2019-02-15 18:57:27 +03:00
@echo "Wait for buildkitd to become available"
@sleep 5
2019-02-15 07:32:00 +03:00
e n d i f
e n d i f
2019-02-19 08:35:47 +03:00
enforce :
@docker run --rm -v $( PWD) :/src -w /src autonomy/conform:$( CONFORM_VERSION)
2019-02-15 07:32:00 +03:00
.PHONY : ci
ci : builddeps buildkitd
2018-12-20 09:22:05 +03:00
2019-02-28 05:57:35 +03:00
base : buildkitd
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= docker \
--exporter-opt output = build/$@ .tar \
--exporter-opt name = docker.io/autonomy/$@ :$( TAG) \
--frontend-opt target = $@ \
$( COMMON_ARGS)
@docker load < build/$@ .tar
2019-02-28 05:57:35 +03:00
kernel : buildkitd
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= local \
--exporter-opt output = build \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-04-16 08:44:59 +03:00
@-rm -rf ./build/modules
2019-01-18 06:14:52 +03:00
2019-02-28 05:57:35 +03:00
initramfs : buildkitd
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= local \
--exporter-opt output = build \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2018-12-20 09:22:05 +03:00
2019-04-15 02:57:37 +03:00
rootfs : buildkitd hyperkube etcd coredns pause osd trustd proxyd ntpd
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= local \
--exporter-opt output = build \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2018-12-20 09:22:05 +03:00
2019-02-28 05:57:35 +03:00
installer : buildkitd
@mkdir -p build
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= docker \
--exporter-opt output = build/$@ .tar \
2019-04-05 07:34:58 +03:00
--exporter-opt name = docker.io/autonomy/$@ :$( TAG) \
2019-01-19 12:58:26 +03:00
--exporter-opt push = $( PUSH) \
--frontend-opt target = $@ \
$( COMMON_ARGS)
@docker load < build/$@ .tar
2019-02-19 19:41:41 +03:00
2019-03-28 02:33:03 +03:00
proto : buildkitd
buildctl --addr $( BUILDKIT_HOST) \
build \
--exporter= local \
--exporter-opt output = ./ \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-04-07 18:25:55 +03:00
talos-gce : installer
2019-04-06 17:24:50 +03:00
@docker run --rm -v /dev:/dev -v $( PWD) /build:/out --privileged $( DOCKER_ARGS) autonomy/installer:$( TAG) disk -l -f -p googlecloud -u none -e 'random.trust_cpu=on'
2019-04-07 18:25:55 +03:00
@tar -C $( PWD) /build -Sczf $( PWD) /build/$@ .tar.gz disk.raw
2019-04-06 17:24:50 +03:00
@rm $( PWD) /build/disk.raw
2019-04-05 07:34:58 +03:00
2019-04-07 18:25:55 +03:00
talos-raw : installer
@docker run --rm -v /dev:/dev -v $( PWD) /build:/out --privileged $( DOCKER_ARGS) autonomy/installer:$( TAG) disk -n rootfs -l
2019-04-05 07:34:58 +03:00
talos : buildkitd
@buildctl --addr $( BUILDKIT_HOST) \
build \
--exporter= docker \
--exporter-opt output = build/$@ .tar \
--exporter-opt name = docker.io/autonomy/$@ :$( TAG) \
--exporter-opt push = $( PUSH) \
--frontend-opt target = $@ \
$( COMMON_ARGS)
@docker load < build/$@ .tar
2019-02-19 19:41:41 +03:00
2019-04-16 23:56:52 +03:00
test : buildkitd rootfs
2019-04-14 19:27:20 +03:00
@mkdir -p build
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-04-14 19:27:20 +03:00
--exporter= docker \
--exporter-opt output = build/$@ .tar \
--exporter-opt name = docker.io/autonomy/$@ :$( TAG) \
--exporter-opt push = $( PUSH) \
2019-01-19 12:58:26 +03:00
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-04-14 19:27:20 +03:00
@docker load < build/$@ .tar
@docker run -i --rm $( DOCKER_TEST_ARGS) autonomy/$@ :$( TAG) /bin/test.sh --short
@trap "rm -rf ./.artifacts" EXIT; mkdir -p ./.artifacts && \
docker run -i --rm $( DOCKER_TEST_ARGS) -v $( PWD) /.artifacts:/src/artifacts autonomy/$@ :$( TAG) /bin/test.sh && \
cp ./.artifacts/coverage.txt coverage.txt
2018-12-20 09:22:05 +03:00
2019-04-16 00:41:11 +03:00
dev-test :
@docker run -i --rm $( DOCKER_TEST_ARGS) \
-v $( PWD) /internal:/src/internal:ro \
-v $( PWD) /pkg:/src/pkg:ro \
-v $( PWD) /cmd:/src/cmd:ro \
autonomy/test:$( TAG) \
go test -v ./...
2019-02-28 05:57:35 +03:00
lint : buildkitd
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-02-28 05:57:35 +03:00
osctl-linux-amd64 : buildkitd
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= local \
--exporter-opt output = build \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-02-28 05:57:35 +03:00
osctl-darwin-amd64 : buildkitd
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= local \
--exporter-opt output = build \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-02-28 05:57:35 +03:00
osinstall-linux-amd64 : buildkitd
2019-02-24 00:18:52 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
--exporter= local \
--exporter-opt output = build \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-02-28 05:57:35 +03:00
udevd : buildkitd
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-04-04 09:07:49 +03:00
images :
mkdir -p images
osd : buildkitd images
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= docker \
--exporter-opt output = images/$@ .tar \
--exporter-opt name = docker.io/autonomy/$@ :$( TAG) \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-04-04 09:07:49 +03:00
trustd : buildkitd images
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= docker \
--exporter-opt output = images/$@ .tar \
--exporter-opt name = docker.io/autonomy/$@ :$( TAG) \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-04-04 09:07:49 +03:00
proxyd : buildkitd images
2019-02-15 07:32:00 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
2019-01-19 12:58:26 +03:00
--exporter= docker \
--exporter-opt output = images/$@ .tar \
--exporter-opt name = docker.io/autonomy/$@ :$( TAG) \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-04-04 09:07:49 +03:00
ntpd : buildkitd images
2019-03-24 01:58:13 +03:00
@buildctl --addr $( BUILDKIT_HOST) \
build \
--exporter= docker \
--exporter-opt output = images/$@ .tar \
--exporter-opt name = docker.io/autonomy/$@ :$( TAG) \
--frontend-opt target = $@ \
$( COMMON_ARGS)
2019-04-04 09:07:49 +03:00
hyperkube : images
2019-04-14 17:20:34 +03:00
@docker pull k8s.gcr.io/$@ :v1.14.1
@docker save k8s.gcr.io/$@ :v1.14.1 -o ./images/$@ .tar
2019-01-16 05:46:41 +03:00
2019-04-04 09:07:49 +03:00
etcd : images
2019-03-29 03:39:26 +03:00
@docker pull k8s.gcr.io/$@ :3.3.10
@docker save k8s.gcr.io/$@ :3.3.10 -o ./images/$@ .tar
2019-01-16 05:46:41 +03:00
2019-04-04 09:07:49 +03:00
coredns : images
2019-03-29 03:39:26 +03:00
@docker pull k8s.gcr.io/$@ :1.3.1
@docker save k8s.gcr.io/$@ :1.3.1 -o ./images/$@ .tar
2019-01-16 05:46:41 +03:00
2019-04-04 09:07:49 +03:00
pause : images
2019-01-16 05:46:41 +03:00
@docker pull k8s.gcr.io/$@ :3.1
@docker save k8s.gcr.io/$@ :3.1 -o ./images/$@ .tar
2019-04-12 09:40:30 +03:00
.PHONY : login
login :
@docker login --username " $( DOCKER_USERNAME) " --password " $( DOCKER_PASSWORD) "
push :
@docker tag autonomy/installer:$( TAG) autonomy/installer:latest
@docker push autonomy/installer:$( TAG)
@docker push autonomy/installer:latest
@docker tag autonomy/talos:$( TAG) autonomy/talos:latest
@docker push autonomy/talos:$( TAG)
@docker push autonomy/talos:latest
2018-12-20 09:22:05 +03:00
clean :
2019-04-05 07:34:58 +03:00
@-rm -rf build images vendor