commit 291f06df6ef0a267d8110a616eb07664f2d20602 Author: Johannes 'fish' Ziemke Date: Sat Mar 9 11:48:10 2019 +0100 Initial commit diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..cbc8ff7 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,25 @@ +version: 2 +jobs: + all: + docker: + - image: circleci/golang:1.11 + steps: + - checkout + - setup_remote_docker + - run: + name: build-and-release + command: | + curl -L https://github.com/tcnksm/ghr/releases/download/v0.12.0/ghr_v0.12.0_linux_amd64.tar.gz \ + | sudo tar --strip=1 -C /usr/bin -xzvf - + make build-all + +workflows: + version: 2 + all: + jobs: + - all: + filters: + tags: + only: /^[0-9]*$/ + branches: + ignore: /.*/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4c9709 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +*.opk diff --git a/ARCHS b/ARCHS new file mode 100644 index 0000000..87a96cb --- /dev/null +++ b/ARCHS @@ -0,0 +1,3 @@ +x86_64 +arm64 +armhf diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a810424 --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +VERSION ?= 0.2.0-rc5 +PVERSION ?= 1 +ARCH ?= x86_64 +suffix := $(subst -x86_64,,-$(ARCH)) + +FILES = $(shell find files/ -type f) +DIR = build/$(VERSION)/$(ARCH) +OUT = build/k3s_$(VERSION)_$(ARCH).opk + +define CONTROL +Package: k3s +Version: ${VERSION}-${PVERSION} +Architecture: $(ARCH) +Maintainer: Johannes 'fish' Ziemke +Depends: iptables kmod-ipt-extra iptables-mod-extra kmod-br-netfilter ca-certificates +Description: The Docker Engine packages for OpenWrt +endef +export CONTROL + +.PHONY: all +all: $(OUT) + +build-all: + if [ -n "$$(ls build/)" ]; then echo build/ not empty && exit 1; fi + for a in $$(cat ARCHS); do \ + for v in $$(cat VERSIONS); do \ + make ARCH=$$a VERSION=$$v; \ + done; \ + done + +.PHONY: release +release: build-all + ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} \ + -c ${CIRCLE_SHA1} -delete ${PVERSION} build/ + +$(OUT): $(DIR)/pkg/control.tar.gz $(DIR)/pkg/data.tar.gz $(DIR)/pkg/debian-binary + tar -C $(DIR)/pkg -czvf "$@" debian-binary data.tar.gz control.tar.gz + +$(DIR)/data: $(FILES) + mkdir -p "$@/usr/bin" + cp -r files/* "$@" + curl -sfLo "$@/usr/bin/k3s" \ + https://github.com/rancher/k3s/releases/download/v$(VERSION)/k3s${suffix} + chmod a+x "$@/usr/bin/k3s" + +$(DIR)/pkg/data.tar.gz: $(DIR)/data + tar -C "$<" -czvf "$@" . + +$(DIR)/pkg: + mkdir -p $@ + +$(DIR)/pkg/debian-binary: $(DIR)/pkg + echo 2.0 > $@ + +$(DIR)/pkg/control: $(DIR)/pkg + echo "$$CONTROL" > "$@" + +$(DIR)/pkg/control.tar.gz: $(DIR)/pkg/control + tar -C $(DIR)/pkg -czvf "$@" control + +.PHONY: clean +clean: + rm -rf build/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..acf9462 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# k3s on OpenWrt +Makefile to generate OpenWrt .opkg packages from official k3s binaries. + +## Usage +Run `make` to build the default version for `x86_64`. You can override ARCH and +VERSION, e.g `make ARCH=armhf`. See ARCHS and VERSIONS files for available +architectures and versions. diff --git a/VERSIONS b/VERSIONS new file mode 100644 index 0000000..7d8695d --- /dev/null +++ b/VERSIONS @@ -0,0 +1,2 @@ +0.2.0-rc5 +0.2.0-rc4 diff --git a/files/etc/config/k3s b/files/etc/config/k3s new file mode 100644 index 0000000..1c7b11a --- /dev/null +++ b/files/etc/config/k3s @@ -0,0 +1,2 @@ +config globals 'globals' + option root '/data/k3s' diff --git a/files/etc/init.d/k3s b/files/etc/init.d/k3s new file mode 100755 index 0000000..9a97a61 --- /dev/null +++ b/files/etc/init.d/k3s @@ -0,0 +1,16 @@ +#!/bin/sh /etc/rc.common + +START=60 +STOP=20 + +PIDFILE=/var/run/k3s.pid +EXEC="/usr/bin/k3s" + +start() { + start-stop-daemon -S -b -x "$EXEC" -m -p "$PIDFILE" \ + -- server --data-dir $(uci_get k3s.globals.root) +} + +stop() { + start-stop-daemon -K -p "$PIDFILE" +}