Skip to content

Commit

Permalink
MEN-2383: Adapt to new Makefile based installation.
Browse files Browse the repository at this point in the history
Changelog: Some core update modules can now be installed by adding
`modules` to the `PACKAGECONFIG` variable of `mender`. They are
included by default when using the meta-mender-demo layer.

Backported-by: Drew Moseley <drew.moseley@northern.tech>
Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>
(cherry picked from commit 172cc9a)
  • Loading branch information
kacf authored and Drew Moseley committed Apr 16, 2019
1 parent 0b7a264 commit 6e87c0f
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 33 deletions.
90 changes: 90 additions & 0 deletions meta-mender-core/recipes-mender/mender/mender-old-makefile.inc
@@ -0,0 +1,90 @@
# Build file for the old makefile, where the install target only installs the
# binary.

SRC_URI_append = " file://mender.service \
"

do_compile() {
GOPATH="${B}:${S}"
export GOPATH
PATH="${B}/bin:$PATH"
export PATH

DEFAULT_CERT_MD5="1fba17436027eb1f5ceff4af9a63c9c2"

if [ "$(md5sum ${WORKDIR}/server.crt | awk '{ print $1 }')" = $DEFAULT_CERT_MD5 ]; then
bbwarn "You are building with the default server certificate, which is not intended for production use"
fi

# mender is using vendored dependencies, any 3rd party libraries go to into
# /vendor directory inside mender source tree. In order for `go build` to pick
# up vendored deps from our source tree, the mender source tree itself must be
# located inside $GOPATH/src/${GO_IMPORT}
#
# recreate temporary $GOPATH/src/${GO_IMPORT} structure and link our source tree
mkdir -p ${B}/src/$(dirname ${GO_IMPORT})
test -e ${B}/src/${GO_IMPORT} || ln -s ${S} ${B}/src/${GO_IMPORT}
cd ${B}/src/${GO_IMPORT}

# run verbose build, we should see which dependencies are pulled in
oe_runmake V=1 install

echo "device_type=${MENDER_DEVICE_TYPE}" > ${B}/device_type
}

do_install() {
install -d ${D}/${bindir}

GOOS=$(eval $(${GO} env) && echo $GOOS)
GOARCH=$(eval $(${GO} env) && echo $GOARCH)
if [ "${BUILD_ARCH}" = "${HOST_ARCH}" ]; then
BUILD_BIN_FOLDER=${B}/bin
else
BUILD_BIN_FOLDER=${B}/bin/${GOOS}_${GOARCH}
fi
# mender is picked up from our fake GOPATH=${B}/bin; because go build is so
# consistent, if it's a cross compilation build, binaries will be in
# ${GOPATH}/bin/${GOOS}_${GOARCH}, howver if it's not, the binaries are in
# ${GOPATH}/bin; handle cross compiled case only
install -t ${D}/${bindir} -m 0755 \
${BUILD_BIN_FOLDER}/mender

install -d ${D}/${datadir}/mender/identity
install -t ${D}/${datadir}/mender/identity -m 0755 \
${S}/src/${GO_IMPORT}/support/mender-device-identity

# install example inventory tools
install -d ${D}/${datadir}/mender/inventory
install -t ${D}/${datadir}/mender/inventory -m 0755 \
${S}/src/${GO_IMPORT}/support/mender-inventory-*

install -d ${D}/${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/mender.service ${D}/${systemd_unitdir}/system

#install configuration
install -d ${D}/${sysconfdir}/mender
install -m 0644 ${B}/mender.conf ${D}/${sysconfdir}/mender

#install server certificate
if [ -f ${WORKDIR}/server.crt ]; then
install -m 0444 ${WORKDIR}/server.crt ${D}/${sysconfdir}/mender
fi

install -d ${D}/${localstatedir}/lib/mender

# install artifact verification key, if any.
if [ -e ${WORKDIR}/artifact-verify-key.pem ]; then
if [ -n "${MENDER_ARTIFACT_VERIFY_KEY}" ]; then
bbfatal "You can not specify both MENDER_ARTIFACT_VERIFY_KEY and have artifact-verify-key.pem in SRC_URI."
fi
install -m 0444 ${WORKDIR}/artifact-verify-key.pem ${D}${sysconfdir}/mender
elif [ -n "${MENDER_ARTIFACT_VERIFY_KEY}" ]; then
install -m 0444 "${MENDER_ARTIFACT_VERIFY_KEY}" ${D}${sysconfdir}/mender/artifact-verify-key.pem
fi

if ${@bb.utils.contains('DISTRO_FEATURES', 'mender-image', 'true', 'false', d)}; then
# symlink /var/lib/mender to /data/mender
rm -rf ${D}/${localstatedir}/lib/mender
ln -s /data/mender ${D}/${localstatedir}/lib/mender
fi
}
53 changes: 20 additions & 33 deletions meta-mender-core/recipes-mender/mender/mender.inc
Expand Up @@ -21,9 +21,6 @@ B = "${WORKDIR}/build"

inherit go

SRC_URI_append = " file://mender.service \
"

inherit systemd

SYSTEMD_SERVICE_${PN} = "mender.service"
Expand All @@ -44,6 +41,10 @@ PACKAGECONFIG_append = "${@bb.utils.contains('DISTRO_FEATURES', 'mender-grub', '
PACKAGECONFIG[mender-install] = ",,,mender-artifact-info ca-certificates"
PACKAGECONFIG[u-boot] = ",,,u-boot-fw-utils"
PACKAGECONFIG[grub] = ",,,grub-editenv grub-efi-mender-grubenv"
# The docker module depends on bash, and of course on docker. However, docker is
# a very large requirement, which we will not mandate. Bash however, we require,
# because otherwise the Yocto QA checks will complain.
PACKAGECONFIG[modules] = ",,,bash"

do_compile() {
GOPATH="${B}:${S}"
Expand All @@ -68,7 +69,7 @@ do_compile() {
cd ${B}/src/${GO_IMPORT}

# run verbose build, we should see which dependencies are pulled in
oe_runmake V=1 install
oe_runmake V=1

}

Expand Down Expand Up @@ -138,35 +139,21 @@ do_prepare_mender_conf[vardeps] = " \
"

do_install() {
install -d ${D}/${bindir}

GOOS=$(eval $(${GO} env) && echo $GOOS)
GOARCH=$(eval $(${GO} env) && echo $GOARCH)
if [ "${BUILD_ARCH}" = "${HOST_ARCH}" ]; then
BUILD_BIN_FOLDER=${B}/bin
else
BUILD_BIN_FOLDER=${B}/bin/${GOOS}_${GOARCH}
fi
# mender is picked up from our fake GOPATH=${B}/bin; because go build is so
# consistent, if it's a cross compilation build, binaries will be in
# ${GOPATH}/bin/${GOOS}_${GOARCH}, howver if it's not, the binaries are in
# ${GOPATH}/bin; handle cross compiled case only
install -t ${D}/${bindir} -m 0755 \
${BUILD_BIN_FOLDER}/mender

install -d ${D}/${datadir}/mender/identity
install -t ${D}/${datadir}/mender/identity -m 0755 \
${S}/src/${GO_IMPORT}/support/mender-device-identity

# install example inventory tools
install -d ${D}/${datadir}/mender/inventory
install -t ${D}/${datadir}/mender/inventory -m 0755 \
${S}/src/${GO_IMPORT}/support/mender-inventory-*

install -d ${D}/${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/mender.service ${D}/${systemd_unitdir}/system

#install configuration
oe_runmake \
-C ${B}/src/${GO_IMPORT} \
V=1 \
prefix=${D} \
bindir=${bindir} \
datadir=${datadir} \
sysconfdir=${sysconfdir} \
systemd_unitdir=${systemd_unitdir} \
install-bin \
install-identity-scripts \
install-inventory-scripts \
install-systemd \
${@bb.utils.contains('PACKAGECONFIG', 'modules', 'install-modules', '', d)}

#install our prepared configuration
install -d ${D}/${sysconfdir}/mender
install -m 0644 ${B}/mender.conf ${D}/${sysconfdir}/mender

Expand Down
1 change: 1 addition & 0 deletions meta-mender-core/recipes-mender/mender/mender_1.5.0.bb
@@ -1,4 +1,5 @@
require mender.inc
require mender-old-makefile.inc

################################################################################
#-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions meta-mender-core/recipes-mender/mender/mender_1.5.1.bb
@@ -1,4 +1,5 @@
require mender.inc
require mender-old-makefile.inc

################################################################################
#-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions meta-mender-core/recipes-mender/mender/mender_1.6.0.bb
@@ -1,4 +1,5 @@
require mender.inc
require mender-old-makefile.inc

################################################################################
#-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions meta-mender-core/recipes-mender/mender/mender_1.6.1.bb
@@ -1,4 +1,5 @@
require mender.inc
require mender-old-makefile.inc

################################################################################
#-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions meta-mender-core/recipes-mender/mender/mender_1.7.0.bb
@@ -1,4 +1,5 @@
require mender.inc
require mender-old-makefile.inc

################################################################################
#-------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions meta-mender-demo/recipes-mender/mender/mender_%.bbappend
Expand Up @@ -6,6 +6,8 @@ MENDER_UPDATE_POLL_INTERVAL_SECONDS = "5"
MENDER_INVENTORY_POLL_INTERVAL_SECONDS = "5"
MENDER_RETRY_POLL_INTERVAL_SECONDS = "30"

PACKAGECONFIG_append = " modules"

do_compile_prepend() {
bbwarn "You are building with the mender-demo layer, which is not intended for production use"
}
75 changes: 75 additions & 0 deletions tests/acceptance/test_build.py
Expand Up @@ -301,3 +301,78 @@ def test_multiple_device_types_compatible(self, prepared_test_build, bitbake_pat
output = subprocess.check_output("tar xOf %s header.tar.gz | tar xOz header-info" % image, shell=True)
data = json.loads(output)
assert data["device_types_compatible"] == ["machine1", "machine2"]

@pytest.mark.only_with_image('sdimg', 'uefiimg')
@pytest.mark.min_mender_version('1.0.0')
def test_boot_partition_population(self, prepared_test_build, bitbake_path):
# Notice in particular a mix of tabs, newlines and spaces. All there to
# check that whitespace it treated correctly.
add_to_local_conf(prepared_test_build, """
IMAGE_INSTALL_append = " test-boot-files"
IMAGE_BOOT_FILES_append = " deployed-test1 deployed-test-dir2/deployed-test2 \
deployed-test3;renamed-deployed-test3 \
deployed-test-dir4/deployed-test4;renamed-deployed-test4 deployed-test5;renamed-deployed-test-dir5/renamed-deployed-test5 \
deployed-test-dir6/deployed-test6;renamed-deployed-test-dir6/renamed-deployed-test6 \
deployed-test-dir7/* \
deployed-test-dir8/*;./ \
deployed-test-dir9/*;renamed-deployed-test-dir9/ \
"
""")
run_bitbake(prepared_test_build)

image = latest_build_artifact(prepared_test_build['build_dir'], "core-image*.*img")
extract_partition(image, 1)
try:
listing = run_verbose("mdir -i img1.fs -b -/", capture=True).split()
expected = [
"::/deployed-test1",
"::/deployed-test2",
"::/renamed-deployed-test3",
"::/renamed-deployed-test4",
"::/renamed-deployed-test-dir5/renamed-deployed-test5",
"::/renamed-deployed-test-dir6/renamed-deployed-test6",
"::/deployed-test7",
"::/deployed-test8",
"::/renamed-deployed-test-dir9/deployed-test9",
]
assert(all([item in listing for item in expected]))

add_to_local_conf(prepared_test_build, 'IMAGE_BOOT_FILES_append = " conflict-test1"')
try:
run_bitbake(prepared_test_build)
pytest.fail("Bitbake succeeded, but should have failed with a file conflict")
except subprocess.CalledProcessError:
pass
finally:
os.remove("img1.fs")

@pytest.mark.only_with_image('sdimg', 'uefiimg')
@pytest.mark.min_mender_version('2.0.0')
def test_module_install(self, prepared_test_build, bitbake_path, latest_rootfs):
mender_vars = get_bitbake_variables("mender")
if "modules" in mender_vars['PACKAGECONFIG'].split():
originally_on = True
else:
originally_on = False

output = subprocess.check_output(["debugfs", "-R", "ls -p /usr/share/mender", latest_rootfs])
entries = [elem.split('/')[5] for elem in output.split('\n') if elem.startswith('/')]

if originally_on:
assert "modules" in entries
add_to_local_conf(prepared_test_build, 'PACKAGECONFIG_remove = "modules"')
else:
assert "modules" not in entries
add_to_local_conf(prepared_test_build, 'PACKAGECONFIG_append = " modules"')
run_bitbake(prepared_test_build)

new_rootfs = latest_build_artifact(prepared_test_build['build_dir'], "core-image*.ext4")

output = subprocess.check_output(["debugfs", "-R", "ls -p /usr/share/mender", new_rootfs])
entries = [elem.split('/')[5] for elem in output.split('\n') if elem.startswith('/')]

if originally_on:
assert "modules" not in entries
else:
assert "modules" in entries

0 comments on commit 6e87c0f

Please sign in to comment.