Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yocto recipe for Kanto Local Digital Twins #10

Merged
merged 9 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions recipes-connectivity/local-digital-twins/files/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cacert": "@LDT_CFG_DD@/local-digital-twins/iothub.crt",
"provisioningFile": "@LDT_CFG_DD@/local-digital-twins/provisioning.json",
"logFile": "@LDT_LOG_DD@/local-digital-twins/local-digital-twins.log"
}
14 changes: 14 additions & 0 deletions recipes-connectivity/local-digital-twins/files/service.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Eclipse Kanto - Local Digital Twins
Documentation=https://eclipse.org/kanto/docs/
After=network.target mosquitto.service
Requires=network.target
Requires=mosquitto.service

[Service]
Type=simple
ExecStart=@LDT_BIN_DD@/local-digital-twins -configFile @LDT_CFG_DD@/local-digital-twins/config.json
Restart=always

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Common configuration variables to set the binaries and resources allocation directories for Eclipse Kanto local digital twins component
# The destination directory where the required configuration files for the proper connectivity establishment of the local digital twins will be placed
LDT_CFG_DD ?= "${sysconfdir}"
# The destination directory where the generated service file will be placed
LDT_SYSUNIT_DD ?= "${systemd_unitdir}/system"
# The destination directory where the local digital twins binaries will be placed
LDT_BIN_DD ?= "${bindir}"
# The destination directory where the local digital twins logs will be placed
LDT_LOG_DD ?= "${localstatedir}/log"
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
DESCRIPTION = "Eclipse Kanto - Local Digital Twins"

LICENSE = "EPL-2.0"
LIC_FILES_CHKSUM = "file://src/${GO_IMPORT}/LICENSE;md5=c7cc8aa73fb5717f8291fcec5ce9ed6c"

SRC_URI = "git://github.com/eclipse-kanto/local-digital-twins;protocol=https;branch=main \
file://config.json \
file://service.template \
"

SRCREV = "${AUTOREV}"

PV = "0.1.0-git${SRCPV}"

GO_IMPORT = "github.com/eclipse-kanto/local-digital-twins"
GO_INSTALL = "${GO_IMPORT}/cmd/twins"

require local-digital-twins.inc

inherit go-mod
inherit systemd

SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_PACKAGES = "${@bb.utils.contains('DISTRO_FEATURES','systemd','${PN}','',d)}"
SYSTEMD_SERVICE:${PN} = "${@bb.utils.contains('DISTRO_FEATURES','systemd','local-digital-twins.service','',d)}"

# workaround for network issue
do_compile[network] = "1"

FILES:${PN} += "${LDT_SYSUNIT_DD}/local-digital-twins.service"
FILES:${PN} += "${LDT_BIN_DD}/local-digital-twins"
# ensure all additional resources are properly packed in the resulting package if provided
FILES:${PN} += "${LDT_CFG_DD}/local-digital-twins/config.json"
FILES:${PN} += "${LDT_CFG_DD}/local-digital-twins/provisioning.json"
FILES:${PN} += "${LDT_CFG_DD}/local-digital-twins/iothub.crt"


e-grigorov marked this conversation as resolved.
Show resolved Hide resolved
RDEPENDS:${PN} += "mosquitto"

PROVIDES:${PN} += "kanto/local-digital-twins"
RPROVIDES:${PN} += "kanto/local-digital-twins"

do_install() {
install -d "${D}/${LDT_BIN_DD}"

install -m 0755 "${GO_BUILD_BINDIR}/twins" "${D}${LDT_BIN_DD}/local-digital-twins"

if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
install -d ${D}${LDT_SYSUNIT_DD}

# local-digital-twins
install -d ${D}${LDT_CFG_DD}/local-digital-twins

# iothub.crt
install -m 0644 ${S}/src/${GO_IMPORT}/cmd/twins/iothub.crt ${D}${LDT_CFG_DD}/local-digital-twins

# config.json
install -m 0644 ${WORKDIR}/config.json ${D}${LDT_CFG_DD}/local-digital-twins

# service.template as service
install -m 0644 ${WORKDIR}/service.template ${D}${LDT_SYSUNIT_DD}/local-digital-twins.service

# fill in the local-digital-twins systemd service template with the custom configs provided
sed -e 's,@LDT_BIN_DD@,${LDT_BIN_DD},g' \
-e 's,@LDT_CFG_DD@,${LDT_CFG_DD},g' \
-i ${D}${LDT_SYSUNIT_DD}/local-digital-twins.service

# fill in the config.json template with the custom configs provided
sed -e 's,@LDT_CFG_DD@,${LDT_CFG_DD},g' \
-e 's,@LDT_LOG_DD@,${LDT_LOG_DD},g' \
-i ${D}${LDT_CFG_DD}/local-digital-twins/config.json
fi

# provisioning.json
if [ -f "${THISDIR}/files/provisioning.json" ]; then
install -m 0644 ${THISDIR}/files/provisioning.json ${D}/${LDT_CFG_DD}/local-digital-twins
fi
}