Restrict MySQL integration to dedicated CI host and strengthen resource isolation
ABSDEV Framework CI / framework-ci (push) Successful in 48s
ABSDEV Framework CI / framework-ci (push) Successful in 48s
This commit is contained in:
@@ -27,6 +27,8 @@ IMAGE = (
|
|||||||
"f4a1ba2d463d692fada04ec7f40be00"
|
"f4a1ba2d463d692fada04ec7f40be00"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
IMAGE_REF = "mysql@" + IMAGE
|
||||||
|
|
||||||
LABEL = "absdev.framework.integration"
|
LABEL = "absdev.framework.integration"
|
||||||
|
|
||||||
SOURCE_DATABASE = "example_db"
|
SOURCE_DATABASE = "example_db"
|
||||||
@@ -103,9 +105,9 @@ class MySQLIntegrationTests(unittest.TestCase):
|
|||||||
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
if socket.gethostname().split(".")[0].lower() == "absdev":
|
if socket.gethostname().split(".")[0].lower() != "absdev-ci":
|
||||||
self.skipTest(
|
self.skipTest(
|
||||||
"Database integration tests prohibited on ABSDEV"
|
"Database integration tests permitted only on ABSDEV-CI"
|
||||||
)
|
)
|
||||||
|
|
||||||
if os.environ.get("ABSDEV_INTEGRATION_TESTS") != "1":
|
if os.environ.get("ABSDEV_INTEGRATION_TESTS") != "1":
|
||||||
@@ -137,6 +139,12 @@ class MySQLIntegrationTests(unittest.TestCase):
|
|||||||
ROOT / "runtime/integration"
|
ROOT / "runtime/integration"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
runtime.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||||
|
require(
|
||||||
|
runtime.resolve() == runtime.absolute(),
|
||||||
|
"Unsafe integration runtime path",
|
||||||
|
)
|
||||||
|
|
||||||
work = runtime / name
|
work = runtime / name
|
||||||
work.mkdir(mode=0o700)
|
work.mkdir(mode=0o700)
|
||||||
|
|
||||||
@@ -156,7 +164,7 @@ class MySQLIntegrationTests(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
require(
|
require(
|
||||||
available >= 786432,
|
available >= 2097152,
|
||||||
"Insufficient available memory",
|
"Insufficient available memory",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -170,12 +178,13 @@ class MySQLIntegrationTests(unittest.TestCase):
|
|||||||
|
|
||||||
image = json.loads(
|
image = json.loads(
|
||||||
command(
|
command(
|
||||||
"docker", "image", "inspect", IMAGE
|
"docker", "image", "inspect", IMAGE_REF
|
||||||
)
|
)
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
require(
|
require(
|
||||||
image["Id"] == IMAGE,
|
image["Id"] == IMAGE
|
||||||
|
and IMAGE_REF in image["RepoDigests"],
|
||||||
"Unexpected database image",
|
"Unexpected database image",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -207,14 +216,14 @@ class MySQLIntegrationTests(unittest.TestCase):
|
|||||||
"--label", f"absdev.integration.token={token}",
|
"--label", f"absdev.integration.token={token}",
|
||||||
"--network", "none",
|
"--network", "none",
|
||||||
"--restart", "no",
|
"--restart", "no",
|
||||||
"--memory", "512m",
|
"--memory", "1024m",
|
||||||
"--memory-swap", "768m",
|
"--memory-swap", "1024m",
|
||||||
"--cpus", "0.5",
|
"--cpus", "1.0",
|
||||||
"--pids-limit", "256",
|
"--pids-limit", "256",
|
||||||
"--security-opt",
|
"--security-opt",
|
||||||
"no-new-privileges=true",
|
"no-new-privileges=true",
|
||||||
"--env-file", str(envfile),
|
"--env-file", str(envfile),
|
||||||
IMAGE,
|
IMAGE_REF,
|
||||||
"--innodb-buffer-pool-size=64M",
|
"--innodb-buffer-pool-size=64M",
|
||||||
"--max-connections=20",
|
"--max-connections=20",
|
||||||
"--performance-schema=OFF",
|
"--performance-schema=OFF",
|
||||||
@@ -255,9 +264,14 @@ class MySQLIntegrationTests(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
require(
|
require(
|
||||||
host["Memory"] == 512 * 1024 * 1024
|
host["Memory"] == 1024 * 1024 * 1024
|
||||||
and host["MemorySwap"]
|
and host["MemorySwap"]
|
||||||
== 768 * 1024 * 1024,
|
== 1024 * 1024 * 1024
|
||||||
|
and host["NanoCpus"] == 1000000000
|
||||||
|
and host["PidsLimit"] == 256
|
||||||
|
and "no-new-privileges" in " ".join(
|
||||||
|
host.get("SecurityOpt") or []
|
||||||
|
),
|
||||||
"Resource limits changed",
|
"Resource limits changed",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -288,7 +302,7 @@ class MySQLIntegrationTests(unittest.TestCase):
|
|||||||
|
|
||||||
print("PASS: Disposable container started")
|
print("PASS: Disposable container started")
|
||||||
|
|
||||||
deadline = time.monotonic() + 180
|
deadline = time.monotonic() + 300
|
||||||
|
|
||||||
while time.monotonic() < deadline:
|
while time.monotonic() < deadline:
|
||||||
|
|
||||||
@@ -315,7 +329,7 @@ class MySQLIntegrationTests(unittest.TestCase):
|
|||||||
if b"mysqld is alive" in result:
|
if b"mysqld is alive" in result:
|
||||||
break
|
break
|
||||||
|
|
||||||
except RuntimeError:
|
except (RuntimeError, subprocess.TimeoutExpired):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|||||||
Reference in New Issue
Block a user