fix: 独立建库并整理离线依赖目录
This commit is contained in:
@@ -21,7 +21,7 @@ from importlib.metadata import distribution
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
target = Path('/package')
|
||||
target = Path('/package/vendor')
|
||||
for name in ('openpyxl', 'et-xmlfile', 'PyMySQL'):
|
||||
package = distribution(name)
|
||||
for item in package.files or ():
|
||||
@@ -76,6 +76,12 @@ def build(output: Path, runtime_image: str, base_image: str) -> Path:
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
if output.exists():
|
||||
output.unlink()
|
||||
with zipfile.ZipFile(output, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as archive:
|
||||
for path in sorted(staging.rglob("*")):
|
||||
if path.is_file():
|
||||
archive.write(path, path.relative_to(staging).as_posix())
|
||||
subprocess.run(
|
||||
[
|
||||
"docker",
|
||||
@@ -84,22 +90,14 @@ def build(output: Path, runtime_image: str, base_image: str) -> Path:
|
||||
"-e",
|
||||
"PYTHONDONTWRITEBYTECODE=1",
|
||||
"-v",
|
||||
f"{staging}:/workspace:ro",
|
||||
"-w",
|
||||
"/workspace",
|
||||
f"{output.parent}:/dist:ro",
|
||||
base_image,
|
||||
"python",
|
||||
"__main__.py",
|
||||
f"/dist/{output.name}",
|
||||
"--help",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
if output.exists():
|
||||
output.unlink()
|
||||
with zipfile.ZipFile(output, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as archive:
|
||||
for path in sorted(staging.rglob("*")):
|
||||
if path.is_file():
|
||||
archive.write(path, path.relative_to(staging).as_posix())
|
||||
return output
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user