Skip to content

Commit

Permalink
makefile: support building without dapper
Browse files Browse the repository at this point in the history
Signed-off-by: Joe MacDonald <[email protected]>
  • Loading branch information
jjmcdn authored and chombourger committed May 6, 2024
1 parent 68bc83c commit c21fc79
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
56 changes: 55 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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=. .
-t k3s-local -f Dockerfile.local --output=. .
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: k3s
Section: admin
Priority: optional
Maintainer: Mentor Embedded <[email protected]>
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
Expand Down
10 changes: 10 additions & 0 deletions debian/k3s.lintian-overrides
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 14 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/

0 comments on commit c21fc79

Please sign in to comment.