From 9c3c3aa1150217f90140bbb61e8d27d163d322c9 Mon Sep 17 00:00:00 2001 From: Jackie Huang Date: Wed, 16 Jun 2021 15:06:05 +0800 Subject: [PATCH] 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 Change-Id: I4be391997ef01c191eb5a906786d0ec0ff8b0097 --- .../classes/stx-chartmuseum.bbclass | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 meta-stx-distro/classes/stx-chartmuseum.bbclass diff --git a/meta-stx-distro/classes/stx-chartmuseum.bbclass b/meta-stx-distro/classes/stx-chartmuseum.bbclass new file mode 100644 index 0000000..50d0c58 --- /dev/null +++ b/meta-stx-distro/classes/stx-chartmuseum.bbclass @@ -0,0 +1,28 @@ +# 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"