Re: [PATCH v2] balena-engine: add recipe


Bruce Ashfield
 

On Tue, Dec 22, 2020 at 11:10 AM Bruce Ashfield via
lists.yoctoproject.org
<bruce.ashfield=gmail.com@...> wrote:

And another followup.

I still haven't forgotten about this, I'm still just tied up with
factoring the code, fighting with k3s and now the holidays. I expect
to get back to this in the next little while.
FYI: I finally got through uprevs and getting k3s to work, so this is
my next detailed integration point.

If you happen to have updates or any newer versions of this, now is a
good time to share them, before I start digging in.

Cheers,

Bruce


Bruce

On Mon, Nov 30, 2020 at 11:43 PM Bruce Ashfield via
lists.yoctoproject.org
<bruce.ashfield=gmail.com@...> wrote:

Just following up, since there were some holidays (and a weekend)
between this being sent and now.

I'll have a closer look at v2 in the next few days, and then will see
about unifying the moby build portion of the effort.

Cheers,

Bruce

On Tue, Nov 24, 2020 at 5:50 PM Maciej Pijanowski
<maciej.pijanowski@...> wrote:

As explained in [1], I have created the balena-engine recipe which could be
used in "regular" Yocto/OE builds (outside of the balenaOS). The
recipe is mostly a copy of the original recipe from meta-balena,
stripped from the balenaOS-specific parts so it can be compiled and
build outside of it. This recipe was tested at build and runtime
on the dunfell release on two targets: RPi4 and qemux86-64.

[1] https://lists.yoctoproject.org/g/meta-virtualization/message/5913

Signed-off-by: Maciej Pijanowski <maciej.pijanowski@...>
---

Changes since v1:
* drop oe-meta-go removes
* use variables instead of hardcoding in case of some paths
* add support for sysvinit
- based on docker.init and confirmed with original balena-engine init [1]
- not verified in practice
* conditionally install init files based on used init system
* use goarch bbclass
* use BUILD_TAGS as a BitBake variable
* drop mobynit compilation
* drop extra balena- symlinks
* drop native bbclass support
* reorganize file structure to be more similar to current docker recipes

[1] https://github.com/balena-os/balena-engine/blob/master/contrib/init/sysvinit-redhat/balena-engine

...dcoded-CC-on-cross-compile-docker-ce.patch | 60 ++++++++
.../balena-engine/balena-engine.init | 131 ++++++++++++++++++
.../balena-engine/balena-tmpfiles.conf | 2 +
.../balena-engine/balena-engine_git.bb | 126 +++++++++++++++++
4 files changed, 319 insertions(+)
create mode 100644 recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
create mode 100644 recipes-containers/balena-engine/balena-engine/balena-engine.init
create mode 100644 recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
create mode 100644 recipes-containers/balena-engine/balena-engine_git.bb

diff --git a/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch b/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
new file mode 100644
index 000000000000..0f257f1bd964
--- /dev/null
+++ b/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
@@ -0,0 +1,60 @@
+From 1263fdb50a540e9db742694b7cee08284ad986d0 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@...>
+Date: Wed, 17 Jul 2019 17:34:04 +0800
+Subject: [PATCH] imporve hardcoded CC on cross compile
+
+Since commit applied in moby [61a3285 Support cross-compile for arm]
+it hardcoded var-CC to support cross-compile for arm
+
+Correct it with "${parameter:-word}" format, it is helpful for user
+define toolchains
+
+(Use Default Values. If parameter is unset or null, the expansion of
+word is substituted. Otherwise, the value of parameter is substituted.)
+
+Upstream-Status: Submitted [https://github.com/moby/moby/pull/39546]
+
+Signed-off-by: Hongxu Jia <hongxu.jia@...>
+---
+ hack/make/.binary | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/src/import/hack/make/.binary b/src/import/hack/make/.binary
+index 53de6749e5..66f4ca05f3 100644
+--- a/src/import/hack/make/.binary
++++ b/src/import/hack/make/.binary
+@@ -44,27 +44,27 @@ if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARC
+ # must be cross-compiling!
+ case "$(go env GOOS)/$(go env GOARCH)" in
+ windows/amd64)
+- export CC=x86_64-w64-mingw32-gcc
++ export CC="${CC:-x86_64-w64-mingw32-gcc}"
+ export CGO_ENABLED=1
+ ;;
+ linux/arm)
+ case "${GOARM}" in
+ 5|"")
+- export CC=arm-linux-gnueabi-gcc
++ export CC="${CC:-arm-linux-gnueabi-gcc}"
+ export CGO_ENABLED=1
+ ;;
+ 7)
+- export CC=arm-linux-gnueabihf-gcc
++ export CC="${CC:-arm-linux-gnueabihf-gcc}"
+ export CGO_ENABLED=1
+ ;;
+ esac
+ ;;
+ linux/arm64)
+- export CC=aarch64-linux-gnu-gcc
++ export CC="${CC:-aarch64-linux-gnu-gcc}"
+ export CGO_ENABLED=1
+ ;;
+ linux/amd64)
+- export CC=x86_64-linux-gnu-gcc
++ export CC="${CC:-x86_64-linux-gnu-gcc}"
+ export CGO_ENABLED=1
+ ;;
+ esac
+--
+2.23.0
diff --git a/recipes-containers/balena-engine/balena-engine/balena-engine.init b/recipes-containers/balena-engine/balena-engine/balena-engine.init
new file mode 100644
index 000000000000..a8c83b2b2b37
--- /dev/null
+++ b/recipes-containers/balena-engine/balena-engine/balena-engine.init
@@ -0,0 +1,131 @@
+#!/bin/sh
+#
+# /etc/rc.d/init.d/balena-engine
+#
+# Daemon for docker.com
+#
+# chkconfig: 2345 95 95
+# description: Daemon for docker.com
+
+### BEGIN INIT INFO
+# Provides: balena-engine
+# Required-Start: $network cgconfig
+# Required-Stop:
+# Should-Start:
+# Should-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: start and stop balena-engine
+# Description: Daemon for docker.com
+### END INIT INFO
+
+# Source function library.
+. /etc/init.d/functions
+
+prog="balena-engine"
+unshare=/usr/bin/unshare
+exec="/usr/bin/balena-engine-daemon"
+pidfile="/var/run/$prog.pid"
+lockfile="/var/lock/subsys/$prog"
+logfile="/var/log/$prog"
+other_args="--pidfile $pidfile --registry-mirror=http://localhost:5000 --insecure-registry=http://localhost:5000 --raw-logs"
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+start() {
+ [ -x $exec ] || exit 5
+
+ check_for_cleanup
+
+ if ! [ -f $pidfile ]; then
+ printf "Starting $prog:\t"
+ echo -e "\n$(date)\n" >> $logfile
+ "$unshare" -m -- $exec $other_args >> $logfile 2>&1 &
+ pid=$!
+ touch $lockfile
+ # wait up to 10 seconds for the pidfile to exist. see
+ # https://github.com/docker/docker/issues/5359
+ tries=0
+ while [ ! -f $pidfile -a $tries -lt 10 ]; do
+ sleep 1
+ tries=$((tries + 1))
+ done
+ success
+ echo
+ else
+ failure
+ echo
+ printf "$pidfile still exists...\n"
+ exit 7
+ fi
+}
+
+stop() {
+ echo -n $"Stopping $prog: "
+ killproc $prog
+ retval=$?
+ echo
+ [ $retval -eq 0 ] && rm -f $lockfile
+ return $retval
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ restart
+}
+
+force_reload() {
+ restart
+}
+
+rh_status() {
+ status $prog
+}
+
+rh_status_q() {
+ rh_status >/dev/null 2>&1
+}
+
+
+check_for_cleanup() {
+ if [ -f ${pidfile} ]; then
+ /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile}
+ fi
+}
+
+case "$1" in
+ start)
+ rh_status_q && exit 0
+ $1
+ ;;
+ stop)
+ rh_status_q || exit 0
+ $1
+ ;;
+ restart)
+ $1
+ ;;
+ reload)
+ rh_status_q || exit 7
+ $1
+ ;;
+ force-reload)
+ force_reload
+ ;;
+ status)
+ rh_status
+ ;;
+ condrestart|try-restart)
+ rh_status_q || exit 0
+ restart
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+ exit 2
+esac
+
+exit $?
diff --git a/recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf b/recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
new file mode 100644
index 000000000000..548a25d3ae49
--- /dev/null
+++ b/recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
@@ -0,0 +1,2 @@
+L /run/docker.pid - - - - /run/balena-engine.pid
+L /run/balena.pid - - - - /run/balena-engine.pid
diff --git a/recipes-containers/balena-engine/balena-engine_git.bb b/recipes-containers/balena-engine/balena-engine_git.bb
new file mode 100644
index 000000000000..b1c149019c27
--- /dev/null
+++ b/recipes-containers/balena-engine/balena-engine_git.bb
@@ -0,0 +1,126 @@
+HOMEPAGE = "https://www.balena.io/"
+SUMMARY = "A Moby-based container engine for IoT"
+DESCRIPTION = "Balena is a new container engine purpose-built for embedded \
+and IoT use cases and compatible with Docker containers. Based on Docker’s \
+Moby Project, balena supports container deltas for 10-70x more efficient \
+bandwidth usage, has 3.5x smaller binaries, uses RAM and storage more \
+conservatively, and focuses on atomicity and durability of container \
+pulling."
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://src/import/LICENSE;md5=4859e97a9c7780e77972d989f0823f28"
+
+BALENA_VERSION = "19.03.13-dev"
+BALENA_BRANCH= "master"
+
+SRCREV = "074a481789174b4b6fd2d706086e8ffceb72e924"
+SRC_URI = "\
+ git://github.com/balena-os/balena-engine.git;branch=${BALENA_BRANCH};destsuffix=git/src/import \
+ file://0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch \
+ file://balena-engine.init \
+ file://balena-tmpfiles.conf \
+"
+
+GO_IMPORT = "import"
+
+S = "${WORKDIR}/git"
+
+PV = "${BALENA_VERSION}+git${SRCREV}"
+
+SECURITY_CFLAGS = "${SECURITY_NOPIE_CFLAGS}"
+SECURITY_LDFLAGS = ""
+
+inherit systemd update-rc.d
+
+SYSTEMD_PACKAGES = "${@bb.utils.contains('DISTRO_FEATURES','systemd','${PN}','',d)}"
+SYSTEMD_SERVICE_${PN} = "${@bb.utils.contains('DISTRO_FEATURES','systemd','balena-engine.service','',d)}"
+SYSTEMD_AUTO_ENABLE_${PN} = "enable"
+
+INITSCRIPT_PACKAGES += "${@bb.utils.contains('DISTRO_FEATURES','sysvinit','${PN}','',d)}"
+INITSCRIPT_NAME_${PN} = "${@bb.utils.contains('DISTRO_FEATURES','sysvinit','balena-engine.init','',d)}"
+INITSCRIPT_PARAMS_${PN} = "defaults"
+
+inherit useradd
+USERADD_PACKAGES = "${PN}"
+GROUPADD_PARAM_${PN} = "-r balena-engine"
+
+DEPENDS_append = " systemd"
+RDEPENDS_${PN} = "curl util-linux iptables tini systemd bash"
+RRECOMMENDS_${PN} += "kernel-module-nf-nat kernel-module-br-netfilter kernel-module-nf-conntrack-netlink kernel-module-xt-masquerade kernel-module-xt-addrtype"
+
+INSANE_SKIP_${PN} += "already-stripped"
+
+FILES_${PN} += " \
+ ${systemd_unitdir}/system/* \
+ ${ROOT_HOME} \
+ ${localstatedir} \
+"
+
+DOCKER_PKG="github.com/docker/docker"
+
+BUILD_TAGS ="no_buildkit no_btrfs no_cri no_devmapper no_zfs exclude_disk_quota exclude_graphdriver_btrfs exclude_graphdriver_devicemapper exclude_graphdriver_zfs"
+
+inherit go
+inherit goarch
+inherit pkgconfig
+
+do_configure[noexec] = "1"
+
+do_compile() {
+ export PATH=${STAGING_BINDIR_NATIVE}/${HOST_SYS}:$PATH
+
+ # Set GOPATH. See 'PACKAGERS.md'. Don't rely on
+ # docker to download its dependencies but rather
+ # use dependencies packaged independently.
+ cd ${S}/src/import
+ rm -rf .gopath
+ mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")"
+ ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}"
+
+ export GOPATH="${S}/src/import/.gopath:${S}/src/import/vendor:${STAGING_DIR_TARGET}/${prefix}/local/go"
+ export GOROOT="${STAGING_DIR_NATIVE}/${nonarch_libdir}/${HOST_SYS}/go"
+
+ # Pass the needed cflags/ldflags so that cgo
+ # can find the needed headers files and libraries
+ export GOARCH=${TARGET_GOARCH}
+ export CGO_ENABLED="1"
+ export CGO_CFLAGS="${CFLAGS} --sysroot=${STAGING_DIR_TARGET}"
+ export CGO_LDFLAGS="${LDFLAGS} --sysroot=${STAGING_DIR_TARGET}"
+ export DOCKER_BUILDTAGS='${BUILD_TAGS}'
+
+ export DOCKER_GITCOMMIT="${SRCREV}"
+ export DOCKER_LDFLAGS="-s"
+
+ VERSION=${BALENA_VERSION} ./hack/make.sh dynbinary-balena
+}
+
+do_install() {
+ mkdir -p ${D}/${bindir}
+ install -m 0755 ${S}/src/import/bundles/dynbinary-balena/balena-engine ${D}/${bindir}/balena-engine
+
+ ln -sf balena-engine ${D}/${bindir}/balena-engine-daemon
+ ln -sf balena-engine ${D}/${bindir}/balena-engine-containerd
+ ln -sf balena-engine ${D}/${bindir}/balena-engine-containerd-shim
+ ln -sf balena-engine ${D}/${bindir}/balena-engine-containerd-ctr
+ ln -sf balena-engine ${D}/${bindir}/balena-engine-runc
+ ln -sf balena-engine ${D}/${bindir}/balena-engine-proxy
+
+ if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
+ install -d ${D}${systemd_unitdir}/system
+ install -m 0644 ${S}/src/import/contrib/init/systemd/balena-engine.socket ${D}/${systemd_unitdir}/system
+ install -m 0644 ${S}/src/import/contrib/init/systemd/balena-engine.service ${D}/${systemd_unitdir}/system
+ else
+ install -d ${D}${sysconfdir}/init.d
+ install -m 0755 ${WORKDIR}/balena-engine.init ${D}${sysconfdir}/init.d/balena-engine.init
+ fi
+
+ install -d ${D}${ROOT_HOME}/.docker
+ ln -sf .docker ${D}${ROOT_HOME}/.balena
+ ln -sf .docker ${D}${ROOT_HOME}/.balena-engine
+
+ install -d ${D}${localstatedir}/lib/docker
+ ln -sf docker ${D}${localstatedir}/lib/balena
+ ln -sf docker ${D}${localstatedir}/lib/balena-engine
+
+ install -d ${D}${sysconfdir}/tmpfiles.d
+ install -m 0644 ${WORKDIR}/balena-tmpfiles.conf ${D}${sysconfdir}/tmpfiles.d/
+}
--
2.25.1




--
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II



--
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II



--
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II

Join meta-virtualization@lists.yoctoproject.org to automatically receive all group messages.