Initial ABSDEV deployment framework development preview
ABSDEV Framework CI / framework-validation (push) Canceled after 0s
ABSDEV Framework CI / framework-validation (push) Canceled after 0s
This commit is contained in:
Executable
+226
@@ -0,0 +1,226 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""Reproducible development-preview source packaging."""
|
||||
|
||||
import argparse
|
||||
import gzip
|
||||
import hashlib
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tarfile
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
DIRECTORIES = {
|
||||
"core", "adapters", "tests", "config",
|
||||
"bin", "scripts", "docs", ".gitea",
|
||||
}
|
||||
|
||||
TOP_LEVEL = {
|
||||
"README.md", "CHANGELOG.md",
|
||||
"VERSION", ".gitignore",
|
||||
}
|
||||
|
||||
EXTENSIONS = {
|
||||
".py", ".sh", ".json",
|
||||
".md", ".yaml", ".yml",
|
||||
}
|
||||
|
||||
DENIED = {
|
||||
"runtime", "reference", "__pycache__",
|
||||
".git", "backups", "secrets",
|
||||
".env", "credentials", "credentials.json",
|
||||
"secrets.json", "auth.json",
|
||||
"id_rsa", "id_ed25519",
|
||||
}
|
||||
|
||||
|
||||
def require(condition, message):
|
||||
if not condition:
|
||||
raise RuntimeError(message)
|
||||
|
||||
|
||||
def source_files():
|
||||
raw = subprocess.check_output([
|
||||
"git", "ls-files", "-z",
|
||||
"--cached", "--others",
|
||||
"--exclude-standard",
|
||||
], cwd=ROOT)
|
||||
|
||||
names = sorted(set(
|
||||
os.fsdecode(item)
|
||||
for item in raw.split(b"\0")
|
||||
if item
|
||||
))
|
||||
|
||||
files = []
|
||||
|
||||
for name in names:
|
||||
relative = Path(name)
|
||||
|
||||
require(
|
||||
not relative.is_absolute()
|
||||
and ".." not in relative.parts
|
||||
and not any(
|
||||
part.lower() in DENIED
|
||||
for part in relative.parts
|
||||
),
|
||||
f"Unsafe source path: {name}",
|
||||
)
|
||||
|
||||
require(
|
||||
all(
|
||||
re.fullmatch(r"[A-Za-z0-9_.-]+", part)
|
||||
for part in relative.parts
|
||||
),
|
||||
f"Invalid filename: {name}",
|
||||
)
|
||||
|
||||
require(
|
||||
name in TOP_LEVEL
|
||||
or (
|
||||
relative.parts[0] in DIRECTORIES
|
||||
and (
|
||||
relative.suffix in EXTENSIONS
|
||||
or name == "bin/absdev-deploy"
|
||||
)
|
||||
),
|
||||
f"Unapproved source: {name}",
|
||||
)
|
||||
|
||||
path = ROOT / relative
|
||||
|
||||
require(
|
||||
path.is_file()
|
||||
and not path.is_symlink()
|
||||
and path.resolve() == path
|
||||
and path.stat().st_size <= 10485760,
|
||||
f"Unsafe source file: {name}",
|
||||
)
|
||||
|
||||
files.append((name, path))
|
||||
|
||||
for required in (
|
||||
"README.md",
|
||||
"CHANGELOG.md",
|
||||
"VERSION",
|
||||
"bin/absdev-deploy",
|
||||
"config/site.example.json",
|
||||
"scripts/ci-check.sh",
|
||||
"scripts/build-release.py",
|
||||
"docs/ARCHITECTURE.md",
|
||||
"docs/PRODUCTION-READINESS.md",
|
||||
".gitea/workflows/framework-ci.yaml",
|
||||
):
|
||||
require(
|
||||
required in names,
|
||||
f"Missing source: {required}",
|
||||
)
|
||||
|
||||
return files
|
||||
|
||||
|
||||
def build(output):
|
||||
version = (ROOT / "VERSION").read_text().strip()
|
||||
|
||||
require(
|
||||
re.fullmatch(
|
||||
r"[0-9]+\.[0-9]+\.[0-9]+-dev\.[0-9]+",
|
||||
version,
|
||||
) is not None,
|
||||
"Development-preview version required",
|
||||
)
|
||||
|
||||
prefix = "absdev-deployment-" + version
|
||||
target = output / (prefix + ".tar.gz")
|
||||
|
||||
require(
|
||||
not os.path.lexists(target)
|
||||
and not os.path.lexists(output / "SHA256SUMS"),
|
||||
"Release already exists",
|
||||
)
|
||||
|
||||
files = source_files()
|
||||
payloads = []
|
||||
|
||||
for name, path in files:
|
||||
content = path.read_bytes()
|
||||
mode = 0o755 if path.stat().st_mode & 0o111 else 0o644
|
||||
payloads.append((name, content, mode))
|
||||
|
||||
manifest = "".join(
|
||||
hashlib.sha256(content).hexdigest()
|
||||
+ " " + name + "\n"
|
||||
for name, content, mode in payloads
|
||||
).encode()
|
||||
|
||||
payloads.append(
|
||||
("SOURCE.sha256", manifest, 0o644)
|
||||
)
|
||||
|
||||
with target.open("xb") as raw:
|
||||
with gzip.GzipFile(
|
||||
filename="",
|
||||
fileobj=raw,
|
||||
mode="wb",
|
||||
mtime=0,
|
||||
compresslevel=9,
|
||||
) as compressed:
|
||||
|
||||
with tarfile.open(
|
||||
fileobj=compressed,
|
||||
mode="w",
|
||||
format=tarfile.PAX_FORMAT,
|
||||
) as archive:
|
||||
|
||||
for name, content, mode in payloads:
|
||||
entry = tarfile.TarInfo(
|
||||
prefix + "/" + name
|
||||
)
|
||||
|
||||
entry.size = len(content)
|
||||
entry.mode = mode
|
||||
entry.uid = 0
|
||||
entry.gid = 0
|
||||
entry.uname = ""
|
||||
entry.gname = ""
|
||||
entry.mtime = 0
|
||||
|
||||
archive.addfile(
|
||||
entry, io.BytesIO(content)
|
||||
)
|
||||
|
||||
with target.open("rb") as handle:
|
||||
checksum = hashlib.file_digest(
|
||||
handle, "sha256"
|
||||
).hexdigest()
|
||||
|
||||
with (output / "SHA256SUMS").open("x") as handle:
|
||||
handle.write(
|
||||
checksum + " " + target.name + "\n"
|
||||
)
|
||||
|
||||
print(f"Source files: {len(files)}")
|
||||
print(f"Package: {target}")
|
||||
print(f"SHA256: {checksum}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument(
|
||||
"--output", required=True, type=Path
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
require(
|
||||
args.output.is_dir(),
|
||||
"Output directory must exist",
|
||||
)
|
||||
|
||||
build(args.output)
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
umask 077
|
||||
|
||||
ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)"
|
||||
|
||||
cd "$ROOT"
|
||||
|
||||
export PYTHONDONTWRITEBYTECODE=1
|
||||
export PYTHONUNBUFFERED=1
|
||||
export ABSDEV_INTEGRATION_TESTS=0
|
||||
|
||||
echo "=== ABSDEV FRAMEWORK CI ==="
|
||||
|
||||
python3 --version
|
||||
|
||||
echo
|
||||
echo "=== PYTHON SYNTAX VALIDATION ==="
|
||||
|
||||
python3 -B <<'PY'
|
||||
from pathlib import Path
|
||||
|
||||
files = []
|
||||
|
||||
for directory in ("core", "adapters", "tests"):
|
||||
files.extend(
|
||||
sorted(Path(directory).rglob("*.py"))
|
||||
)
|
||||
|
||||
files.extend([
|
||||
Path("bin/absdev-deploy"),
|
||||
Path("bin/absdev-deploy-validate.py"),
|
||||
])
|
||||
|
||||
for path in files:
|
||||
if path.is_symlink() or not path.is_file():
|
||||
raise SystemExit(
|
||||
f"Unsafe Python source: {path}"
|
||||
)
|
||||
|
||||
compile(
|
||||
path.read_bytes(),
|
||||
str(path),
|
||||
"exec",
|
||||
)
|
||||
|
||||
print(f"PASS: {len(files)} Python sources compiled")
|
||||
PY
|
||||
|
||||
echo
|
||||
echo "=== COMPLETE UNIT REGRESSION SUITE ==="
|
||||
|
||||
python3 -B -m unittest discover -s tests/unit
|
||||
|
||||
echo
|
||||
echo "=== VERIFY PRODUCTION CAPABILITY RESTRICTIONS ==="
|
||||
|
||||
python3 -B <<'PY'
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"bin/absdev-deploy",
|
||||
"capabilities",
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=15,
|
||||
check=True,
|
||||
)
|
||||
|
||||
report = json.loads(result.stdout)
|
||||
|
||||
for field in (
|
||||
"production_ready",
|
||||
"deployment_execution_enabled",
|
||||
"migration_execution_enabled",
|
||||
"provisioning_execution_enabled",
|
||||
"database_restore_enabled",
|
||||
"permanent_deletion_enabled",
|
||||
):
|
||||
if report.get(field) is not False:
|
||||
raise SystemExit(
|
||||
f"FAIL: Unsafe capability: {field}"
|
||||
)
|
||||
|
||||
print(f"PASS: {field}=false")
|
||||
|
||||
for command in (
|
||||
"deploy",
|
||||
"migrate",
|
||||
"rollback",
|
||||
"restore",
|
||||
"provision",
|
||||
"delete",
|
||||
):
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"bin/absdev-deploy",
|
||||
command,
|
||||
],
|
||||
capture_output=True,
|
||||
timeout=15,
|
||||
)
|
||||
|
||||
if result.returncode == 0:
|
||||
raise SystemExit(
|
||||
f"FAIL: Unexpected command: {command}"
|
||||
)
|
||||
|
||||
print(f"PASS: Unsupported command rejected: {command}")
|
||||
PY
|
||||
|
||||
echo
|
||||
echo "=== EXAMPLE CONFIGURATION ==="
|
||||
|
||||
bin/absdev-deploy validate \
|
||||
--config config/site.example.json
|
||||
|
||||
bin/absdev-deploy site-policy \
|
||||
--config config/site.example.json
|
||||
|
||||
bin/absdev-deploy provision-plan \
|
||||
--config config/site.example.json
|
||||
|
||||
echo
|
||||
echo "=== REFERENCE INTEGRITY ==="
|
||||
|
||||
if [[ -e REFERENCE.sha256 ]]; then
|
||||
sha256sum -c REFERENCE.sha256 >/dev/null
|
||||
echo "PASS: Reference implementation unchanged"
|
||||
else
|
||||
echo "SKIP: Private reference excluded from checkout"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "========================================"
|
||||
echo "PASS: FRAMEWORK CI"
|
||||
echo "UNIT TESTS AND STATIC VALIDATION ONLY"
|
||||
echo "DATABASE INTEGRATION NOT EXECUTED"
|
||||
echo "========================================"
|
||||
Reference in New Issue
Block a user