mirror of
https://github.com/BigfootACA/arch-image-builder.git
synced 2024-09-21 13:20:53 +08:00
builder: add preset for build package
Signed-off-by: BigfootACA <bigfoot@classfun.cn>
This commit is contained in:
parent
f9fe91f5e9
commit
245a0ab00f
17
README.md
17
README.md
@ -11,7 +11,7 @@ Currently only support Arch based distros
|
|||||||
Install required packages
|
Install required packages
|
||||||
|
|
||||||
```commandline
|
```commandline
|
||||||
pacman -S rsync pyalpm python-yaml python-libarchive-c
|
pacman -S p7zip rsync pyalpm python-yaml python-libarchive-c
|
||||||
```
|
```
|
||||||
|
|
||||||
For cross build (UNTESTED)
|
For cross build (UNTESTED)
|
||||||
@ -28,13 +28,14 @@ python build.py -c target/ayn-odin2-sdcard,locale/zh-cn,desktop/gnome
|
|||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
| Option | Description |
|
| Option | Description |
|
||||||
|-------------------------------------|---------------------------|
|
|-------------------------------------|----------------------------------|
|
||||||
| -c CONFIG, --config CONFIG | Select configs to build |
|
| -p PRESET, --preset PRESET | Select preset to create package |
|
||||||
| -o WORKSPACE, --workspace WORKSPACE | Set workspace for builder |
|
| -c CONFIG, --config CONFIG | Select configs to build |
|
||||||
| -d, --debug | Enable debug logging |
|
| -o WORKSPACE, --workspace WORKSPACE | Set workspace for builder |
|
||||||
| -G, --no-gpgcheck | Disable GPG check |
|
| -d, --debug | Enable debug logging |
|
||||||
| -r, --repack | Repack rootfs only |
|
| -G, --no-gpgcheck | Disable GPG check |
|
||||||
|
| -r, --repack | Repack rootfs only |
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -105,3 +105,14 @@ def load_configs(ctx: ArchBuilderContext, configs: list[str]):
|
|||||||
if ctx.config is None:
|
if ctx.config is None:
|
||||||
raise ArchBuilderConfigError("no any config loaded")
|
raise ArchBuilderConfigError("no any config loaded")
|
||||||
log.debug(f"loaded {loaded} configs")
|
log.debug(f"loaded {loaded} configs")
|
||||||
|
|
||||||
|
|
||||||
|
def load_preset(ctx: ArchBuilderContext, preset: str):
|
||||||
|
file = preset
|
||||||
|
if not preset.startswith("/"):
|
||||||
|
file = "presets/" + preset
|
||||||
|
ctx.preset = True
|
||||||
|
load_configs(ctx, [file])
|
||||||
|
if "package" not in ctx.config:
|
||||||
|
raise ArchBuilderConfigError("bad preset config")
|
||||||
|
log.info(f"loaded preset {preset}")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
from datetime import datetime
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from builder.lib.cpu import cpu_arch_get
|
from builder.lib.cpu import cpu_arch_get
|
||||||
@ -88,6 +89,16 @@ class ArchBuilderContext:
|
|||||||
passwd: PasswdFile = PasswdFile()
|
passwd: PasswdFile = PasswdFile()
|
||||||
group: GroupFile = GroupFile()
|
group: GroupFile = GroupFile()
|
||||||
|
|
||||||
|
"""
|
||||||
|
Use a preset to build package
|
||||||
|
"""
|
||||||
|
preset: bool = False
|
||||||
|
|
||||||
|
"""
|
||||||
|
Package version
|
||||||
|
"""
|
||||||
|
version: str = datetime.now().strftime('%Y%m%d%H%M%S')
|
||||||
|
|
||||||
def get(self, key: str, default=None):
|
def get(self, key: str, default=None):
|
||||||
"""
|
"""
|
||||||
Get config value
|
Get config value
|
||||||
@ -101,7 +112,9 @@ class ArchBuilderContext:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cgroup = CGroup("arch-image-builder")
|
self.cgroup = CGroup("arch-image-builder")
|
||||||
self.cgroup.create()
|
self.config["version"] = self.version
|
||||||
|
try: self.cgroup.create()
|
||||||
|
except: log.warning("failed to create cgroup", exc_info=1)
|
||||||
|
|
||||||
def __deinit__(self):
|
def __deinit__(self):
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
|
@ -6,6 +6,7 @@ from argparse import ArgumentParser
|
|||||||
from builder.build import bootstrap
|
from builder.build import bootstrap
|
||||||
from builder.lib import config, utils
|
from builder.lib import config, utils
|
||||||
from builder.lib.context import ArchBuilderContext
|
from builder.lib.context import ArchBuilderContext
|
||||||
|
from builder.lib.config import ArchBuilderConfigError
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -14,7 +15,8 @@ def parse_arguments(ctx: ArchBuilderContext):
|
|||||||
prog="arch-image-builder",
|
prog="arch-image-builder",
|
||||||
description="Build flashable image for Arch Linux",
|
description="Build flashable image for Arch Linux",
|
||||||
)
|
)
|
||||||
parser.add_argument("-c", "--config", help="Select config to build", required=True, action='append')
|
parser.add_argument("-p", "--preset", help="Select preset to create package")
|
||||||
|
parser.add_argument("-c", "--config", help="Select config to build", action='append')
|
||||||
parser.add_argument("-o", "--workspace", help="Set workspace for builder", default=ctx.work)
|
parser.add_argument("-o", "--workspace", help="Set workspace for builder", default=ctx.work)
|
||||||
parser.add_argument("-d", "--debug", help="Enable debug logging", default=False, action='store_true')
|
parser.add_argument("-d", "--debug", help="Enable debug logging", default=False, action='store_true')
|
||||||
parser.add_argument("-G", "--no-gpgcheck", help="Disable GPG check", default=False, action='store_true')
|
parser.add_argument("-G", "--no-gpgcheck", help="Disable GPG check", default=False, action='store_true')
|
||||||
@ -31,8 +33,15 @@ def parse_arguments(ctx: ArchBuilderContext):
|
|||||||
|
|
||||||
# collect configs path
|
# collect configs path
|
||||||
configs = []
|
configs = []
|
||||||
for conf in args.config:
|
if args.config:
|
||||||
configs.extend(conf.split(","))
|
for conf in args.config:
|
||||||
|
configs.extend(conf.split(","))
|
||||||
|
|
||||||
|
# load preset config for build package
|
||||||
|
if args.preset:
|
||||||
|
config.load_preset(ctx, args.preset)
|
||||||
|
pcfgs = ctx.get("package.configs", [])
|
||||||
|
configs.extend(pcfgs)
|
||||||
|
|
||||||
# load and populate configs
|
# load and populate configs
|
||||||
config.load_configs(ctx, configs)
|
config.load_configs(ctx, configs)
|
||||||
@ -63,6 +72,20 @@ def check_system():
|
|||||||
raise FileNotFoundError("pacman not found")
|
raise FileNotFoundError("pacman not found")
|
||||||
|
|
||||||
|
|
||||||
|
def done_package(ctx: ArchBuilderContext):
|
||||||
|
file: str = ctx.get("package.file", "")
|
||||||
|
out = file
|
||||||
|
if not out.startswith("/"):
|
||||||
|
out = os.path.join(ctx.work, file)
|
||||||
|
if not out.endswith(".7z"):
|
||||||
|
raise ArchBuilderConfigError("current only supports 7z")
|
||||||
|
log.info(f"creating package {file}")
|
||||||
|
args = ["7z", "a", "-ms=on", "-mx=9", out, "."]
|
||||||
|
ret = ctx.run_external(args, cwd=ctx.get_output())
|
||||||
|
if ret != 0: raise OSError("create package failed")
|
||||||
|
log.info(f"created package at {out}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.basicConfig(stream=stdout, level=logging.INFO)
|
logging.basicConfig(stream=stdout, level=logging.INFO)
|
||||||
check_system()
|
check_system()
|
||||||
@ -71,7 +94,10 @@ def main():
|
|||||||
ctx.dir = os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
ctx.dir = os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
||||||
ctx.work = os.path.realpath(os.path.join(ctx.dir, "build"))
|
ctx.work = os.path.realpath(os.path.join(ctx.dir, "build"))
|
||||||
parse_arguments(ctx)
|
parse_arguments(ctx)
|
||||||
|
log.info(f"package version: {ctx.version}")
|
||||||
log.info(f"source tree folder: {ctx.dir}")
|
log.info(f"source tree folder: {ctx.dir}")
|
||||||
log.info(f"workspace folder: {ctx.work}")
|
log.info(f"workspace folder: {ctx.work}")
|
||||||
log.info(f"build target name: {ctx.target}")
|
log.info(f"build target name: {ctx.target}")
|
||||||
bootstrap.build_rootfs(ctx)
|
bootstrap.build_rootfs(ctx)
|
||||||
|
if ctx.preset:
|
||||||
|
done_package(ctx)
|
||||||
|
5
configs/presets/ayn-odin2-sdcard-gnome-global.yaml
Normal file
5
configs/presets/ayn-odin2-sdcard-gnome-global.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package:
|
||||||
|
file: ArchLinuxARM-AYN-Odin2-SDCard-GNOME-Global-${version}.7z
|
||||||
|
configs:
|
||||||
|
- target/ayn-odin2-sdcard
|
||||||
|
- desktop/gnome
|
6
configs/presets/ayn-odin2-sdcard-gnome-zh-cn.yaml
Normal file
6
configs/presets/ayn-odin2-sdcard-gnome-zh-cn.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package:
|
||||||
|
file: ArchLinuxARM-AYN-Odin2-SDCard-GNOME-zh_CN-${version}.7z
|
||||||
|
configs:
|
||||||
|
- target/ayn-odin2-sdcard
|
||||||
|
- locale/zh-cn
|
||||||
|
- desktop/gnome
|
5
configs/presets/ayn-odin2-ufs-gnome-global.yaml
Normal file
5
configs/presets/ayn-odin2-ufs-gnome-global.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package:
|
||||||
|
file: ArchLinuxARM-AYN-Odin2-UFS-GNOME-Global-${version}.7z
|
||||||
|
configs:
|
||||||
|
- target/ayn-odin2-ufs
|
||||||
|
- desktop/gnome
|
6
configs/presets/ayn-odin2-ufs-gnome-zh-cn.yaml
Normal file
6
configs/presets/ayn-odin2-ufs-gnome-zh-cn.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package:
|
||||||
|
file: ArchLinuxARM-AYN-Odin2-UFS-GNOME-zh_CN-${version}.7z
|
||||||
|
configs:
|
||||||
|
- target/ayn-odin2-ufs
|
||||||
|
- locale/zh-cn
|
||||||
|
- desktop/gnome
|
Loading…
Reference in New Issue
Block a user