meta-starlingx/meta-stx-distro/classes/stx-chartmuseum.bbclass
Jackie Huang 9c3c3aa115 stx-chartmuseum: add new bbclass
For the packages that provide helm charts, chartmuseum is
used as the local helm chart repository for building the
chart, and the port 8879 is used.

To avoid race condition, add this bbclass to help adding a lock
for do_compile of each package that uses chartmuseum to build
helm chart, and add a prefunc to check if the port is already
in use by other program on the host.

Story: 2008952
Task: 42576

Signed-off-by: Jackie Huang <jackie.huang@windriver.com>
Change-Id: I4be391997ef01c191eb5a906786d0ec0ff8b0097
2021-07-21 17:20:13 +08:00

29 lines
920 B
Plaintext

# This class is intended to avoid race condition by adding a lock
# for do_compile of each package that uses chartmuseum to build
# helm chart, and add a prefunc to check if the port is already
# in use by other program on the host.
#
DEPENDS += "chartmuseum-native"
CHARTMUSEUM_PORT = "8879"
python check_port_in_use() {
import socket
port_num = int(d.getVar("CHARTMUSEUM_PORT"))
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
res = s.connect_ex(('localhost', port_num))
if res == 0:
bb.fatal("The port %s is already in use, please ensure the port is not used by other programs" % (port_num))
}
# Check if the port for chartmuseum is in use
do_compile[prefuncs] += "check_port_in_use"
# Ensure we don't race against other chartmuseum instances
check_port_in_use[lockfiles] = "${TMPDIR}/stx-chartmuseum.lock"
do_compile[lockfiles] = "${TMPDIR}/stx-chartmuseum.lock"