How to conditionally include a .bbappend in Yocto

  bitbake, docker, yocto

We have a Yocto build targetting two hardware platforms. One of them needs to be built on Rocko because of chip vendor dependencies. The other is on Dunfell.

On Rocko, the docker package is just called docker but on Dunfell it is called docker-ce, and it also requires a .bbappend per this thread:

I have my code pulling in ‘docker’ for Rocko builds and ‘docker-ce’ for Dunfell builds:

DEPENDS += "${@bb.utils.contains(‘ROCKO_P’, ‘true’, ‘ docker’, ‘ docker-ce’, d)}"
RDEPENDS_${PN} += "${@bb.utils.contains(‘ROCKO_P’, ‘true’, ‘ docker’, ‘ docker-ce’, d)}"

Since I have added the required .bbappend for docker-ce to my source code repo, my Rocko builds now complain about it:

ERROR: No recipes available for:

Is there a way to tell Yocto to include this .bbappend file only if certain conditions are met?

Source: Docker Questions