From c21fc79c4d01e3bcc8d558713f2fe2160c50c8c5 Mon Sep 17 00:00:00 2001 From: Joe MacDonald Date: Mon, 12 Jun 2023 15:50:13 -0400 Subject: [PATCH] makefile: support building without dapper Signed-off-by: Joe MacDonald --- Makefile | 56 +++++++++++++++++++++++++++++++++++- debian/control | 2 +- debian/k3s.lintian-overrides | 10 +++++++ debian/rules | 16 +++++++++-- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 620f89989425..3729cbb051f8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,21 @@ TARGETS := $(shell ls scripts | grep -v \\.sh) GO_FILES ?= $$(find . -name '*.go' | grep -v generated) +GO_VERSION ?= 1.20.4 +USE_DAPPER ?= 1 +UNAME := $(shell uname -m) +SHELL = /bin/bash +WD := $(shell pwd) +export TOOLPATH := $(WD) +export GOROOT := $(TOOLPATH)/bin/go +export PATH := $(TOOLPATH)/bin:$(GOROOT)/bin:$(PATH) +ifeq ($(UNAME),x86_64) + ARCH = amd64 +else + ifeq ($(UNAME),arm64) + ARCH = arm64 + endif +endif .dapper: @echo Downloading dapper @@ -9,8 +24,47 @@ GO_FILES ?= $$(find . -name '*.go' | grep -v generated) @./.dapper.tmp -v @mv .dapper.tmp .dapper +.nodapper: + $(info Checking essential build tools.) + @if [ ! -d $(WD)/bin ] ; then \ + mkdir $(WD)/bin ; \ + fi + $(info Checking go version for compatibility.) + @if [ ! -d $(GOROOT) ] ; then \ + echo "No go found, fetching compatible version." ; curl -sL https://go.dev/dl/go$(GO_VERSION).linux-$(ARCH).tar.gz | tar -C $$PWD/bin -zxf - ; \ + else \ + case "$$(go version)" in \ + *$(GO_VERSION)* ) echo "Compatible go version found." ;; \ + * ) echo "Go appears to be " $$(go version) ; echo "Incompatible or non-functional go found, fetching compatible version." ; curl -sL https://go.dev/dl/go$(GO_VERSION).linux-$(ARCH).tar.gz | tar -C $$PWD/bin -zxf - ;; \ + esac \ + fi + @if ! type yq 2>/dev/null ; then \ + echo "yq not found, fetching."; \ + curl -sL --output $$PWD/bin/yq https://github.com/mikefarah/yq/releases/download/v4.34.1/yq_linux_$(ARCH) ; \ + chmod +x $$PWD/bin/yq ; \ + fi + +ifeq ($(strip $(USE_DAPPER)),1) $(TARGETS): .dapper ./.dapper $@ +else + +# We call clean ourselves in a separate target and we are reproducing the ci +# call here in our 'build' case. +$(filter-out clean ci, $(TARGETS)): .nodapper + env ; \ + case $@ in \ + build ) ./scripts/download ; ./scripts/validate ; ./scripts/build ;; \ + * ) ./scripts/$@ ;; \ + esac + +ci: build + $(info No additional ci steps required.) + +clean: + ./scripts/clean + +endif .PHONY: deps deps: @@ -42,4 +96,4 @@ format: local: DOCKER_BUILDKIT=1 docker build \ --build-arg="REPO TAG GITHUB_TOKEN GOLANG GOCOVER DEBUG" \ - -t k3s-local -f Dockerfile.local --output=. . \ No newline at end of file + -t k3s-local -f Dockerfile.local --output=. . diff --git a/debian/control b/debian/control index 686d114df6e5..dc924ed7bac1 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: k3s Section: admin Priority: optional Maintainer: Mentor Embedded -Build-Depends: debhelper (>= 11), chrpath, cpio, curl, diffstat, docker.io | docker-ce, gawk, lz4, wget, zstd +Build-Depends: debhelper (>= 11), chrpath, cpio, curl, diffstat, docker.io | docker-ce, gawk, libseccomp-dev, lz4, pkg-config, wget, zstd Standards-Version: 4.5.1 Homepage: https://k3s.io/ Rules-Requires-Root: no diff --git a/debian/k3s.lintian-overrides b/debian/k3s.lintian-overrides index 109c6f03bb87..9618cc6fdfd0 100644 --- a/debian/k3s.lintian-overrides +++ b/debian/k3s.lintian-overrides @@ -2,7 +2,17 @@ # linking is intentional, since no dynamic link version is possible. k3s: statically-linked-binary usr/sbin/k3s # k3s intentionally does not provide manpages for these. +k3s: no-manual-page usr/sbin/containerd k3s: no-manual-page usr/sbin/crictl k3s: no-manual-page usr/sbin/ctr k3s: no-manual-page usr/sbin/k3s +k3s: no-manual-page usr/sbin/k3s-agent +k3s: no-manual-page usr/sbin/k3s-certificate +k3s: no-manual-page usr/sbin/k3s-completion +k3s: no-manual-page usr/sbin/k3s-etcd-snapshot +k3s: no-manual-page usr/sbin/k3s-secrets-encrypt +k3s: no-manual-page usr/sbin/k3s-server +k3s: no-manual-page usr/sbin/k3s-token k3s: no-manual-page usr/sbin/kubectl +# We want to build without PIE, this is intentional +k3s: hardening-no-pie usr/sbin/k3s diff --git a/debian/rules b/debian/rules index 18b9f492ae0d..462143ed59fa 100755 --- a/debian/rules +++ b/debian/rules @@ -4,14 +4,18 @@ # export DH_VERBOSE = 1 # make debhelper commands more verbose # export DH_OPTIONS = -v +export USE_DAPPER ?= 0 %: dh $@ +ifeq ($(strip $(USE_DAPPER)),1) +# Dapper builds require this, regular builds don't override_dh_auto_configure: mkdir -p build/data make download make generate +endif override_dh_auto_test: @echo Skipping tests @@ -20,8 +24,16 @@ override_dh_auto_install: mkdir -p debian/k3s/usr/sbin/ mkdir -p debian/k3s/etc/rancher/k3s/ mkdir -p debian/k3s/lib/systemd/system/ - install -m 0755 dist/artifacts/k3s debian/k3s/usr/sbin/ - ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/kubectl + install -m 0755 bin/k3s debian/k3s/usr/sbin/ + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/containerd ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/crictl ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/ctr + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/k3s-agent + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/k3s-certificate + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/k3s-completion + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/k3s-etcd-snapshot + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/k3s-secrets-encrypt + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/k3s-server + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/k3s-token + ln -sf debian/k3s/usr/sbin/k3s debian/k3s/usr/sbin/kubectl install -m 0644 k3s.service debian/k3s/lib/systemd/system/