65 lines
3.0 KiB
Python
Executable File
65 lines
3.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Build Tradarr images; publishing requires --push. No authentication handling."""
|
|
import argparse
|
|
import pathlib
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
REGISTRY = 'gitea.anthonybouteiller.ovh/blomios'
|
|
SOURCE = 'https://gitea.anthonybouteiller.ovh/blomios/Tradarr'
|
|
LAYA_REVISION = 'e150aa92a0d4059ac621875b39b620847cf1b88a'
|
|
|
|
|
|
def main(argv=None):
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--tag', help='Image tag (default: full Git HEAD SHA)')
|
|
parser.add_argument('--push', action='store_true', help='Publish after all four builds succeed')
|
|
parser.add_argument('--dry-run', action='store_true', help='Show plan without building or pushing')
|
|
args = parser.parse_args(argv)
|
|
if args.tag is not None and not re.fullmatch(r'[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}', args.tag):
|
|
parser.error('Invalid image tag')
|
|
# Runtime read-only Git lookup; no Git mutation and no remote access.
|
|
revision = subprocess.run(['git', 'rev-parse', '--verify', 'HEAD'], cwd=ROOT,
|
|
check=True, capture_output=True, text=True).stdout.strip()
|
|
if not re.fullmatch(r'[0-9a-f]{40}', revision):
|
|
parser.error('Expected a full Git SHA-1 revision')
|
|
tag = args.tag or revision
|
|
commands = []
|
|
images = []
|
|
for name, context in [('backend', 'backend'), ('frontend', 'frontend'),
|
|
('scraper', 'scraper-service'), ('laya', None)]:
|
|
image = f'{REGISTRY}/tradarr-{name}:{tag}'
|
|
images.append(image)
|
|
upstream = name == 'laya'
|
|
labels = {'source': 'https://github.com/NandhaKishorM/laya' if upstream else SOURCE,
|
|
'revision': LAYA_REVISION if upstream else revision, 'version': tag}
|
|
command = ['docker', 'build', '--tag', image]
|
|
for key, value in labels.items():
|
|
command += ['--label', f'org.opencontainers.image.{key}={value}']
|
|
if upstream:
|
|
command += ['--build-arg', 'TORCH_INDEX=cpu']
|
|
command += [f'https://github.com/NandhaKishorM/laya.git#{LAYA_REVISION}'
|
|
if upstream else str(ROOT / context)]
|
|
commands.append(command)
|
|
if args.push:
|
|
commands += [['docker', 'push', image] for image in images]
|
|
for command in commands:
|
|
if args.dry_run:
|
|
print(' '.join(command))
|
|
else:
|
|
# Docker output is intentionally suppressed: build diagnostics can expose
|
|
# local files or registry credentials. Never print exception command/output.
|
|
subprocess.run(command, cwd=ROOT, check=True, stdout=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL)
|
|
print(f'{command[1]} completed: {command[3] if command[1] == "build" else command[2]}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except (subprocess.CalledProcessError, OSError):
|
|
print('Image operation failed; stopped without further publication.', file=sys.stderr)
|
|
sys.exit(1)
|