fix(photo-ai): build weights in an isolated stage and stop blocking app deploys
Prefetch moved to a separate python:3.10-slim stage that only sees weights.py/fetch-weights.py, so editing app.py or vendor/ no longer invalidates the 360 MB weights layer. Weight catalog and download helpers extracted to photo-ai/weights.py; fetch-weights.py no longer imports app (torch). Cache mount switched to sharing=shared: a canceled build could leave the exclusive lock held and hang the next build forever; downloads now use a pid-unique tmp file, so concurrent builds cannot corrupt it. Docs recommend 'docker compose up -d --build app' for app updates instead of rebuilding photo-ai/face-id.
This commit is contained in:
+12
-18
@@ -3,20 +3,14 @@ import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
import app
|
||||
import weights as wm
|
||||
|
||||
WEIGHTS = {}
|
||||
WEIGHTS = wm.all_weights()
|
||||
MODELS = {}
|
||||
for _name, _spec in app.MODEL_REGISTRY.items():
|
||||
WEIGHTS[_spec['file']] = _spec
|
||||
for _name, _spec in wm.MODEL_WEIGHTS.items():
|
||||
MODELS[_name] = _spec
|
||||
if _spec.get('dni'):
|
||||
WEIGHTS[_spec['dni']['file']] = _spec['dni']
|
||||
for _name, _spec in app.FACE_REGISTRY.items():
|
||||
WEIGHTS[_spec['file']] = _spec
|
||||
for _name, _spec in wm.FACE_WEIGHTS.items():
|
||||
MODELS[_name] = _spec
|
||||
for _name, _spec in app.FACEXLIB_WEIGHTS.items():
|
||||
WEIGHTS[_name] = _spec
|
||||
|
||||
|
||||
def wanted():
|
||||
@@ -29,7 +23,7 @@ def wanted():
|
||||
if not name:
|
||||
continue
|
||||
if name.lower() == 'face':
|
||||
for face_name, face_spec in app.FACE_REGISTRY.items():
|
||||
for face_name, face_spec in wm.FACE_WEIGHTS.items():
|
||||
picked[face_spec['file']] = face_spec
|
||||
continue
|
||||
spec = MODELS.get(name) or WEIGHTS.get(name)
|
||||
@@ -44,23 +38,23 @@ def fetch(name, spec, target, cache_dir):
|
||||
url = spec['url']
|
||||
if cache_dir:
|
||||
cached = os.path.join(cache_dir, name)
|
||||
if app.file_ok(cached, spec['min_bytes']):
|
||||
app.link_or_copy(cached, target)
|
||||
if wm.file_ok(cached, spec['min_bytes']):
|
||||
wm.link_or_copy(cached, target)
|
||||
print('веса %s взяты из кэша сборки %s' % (name, cached))
|
||||
return
|
||||
try:
|
||||
app.download_weight(url, cached, spec['min_bytes'])
|
||||
wm.download_weight(url, cached, spec['min_bytes'])
|
||||
except Exception:
|
||||
if os.path.isfile(cached):
|
||||
os.unlink(cached)
|
||||
raise
|
||||
app.link_or_copy(cached, target)
|
||||
wm.link_or_copy(cached, target)
|
||||
return
|
||||
app.download_weight(url, target, spec['min_bytes'])
|
||||
wm.download_weight(url, target, spec['min_bytes'])
|
||||
|
||||
|
||||
def main():
|
||||
target_dir = sys.argv[1] if len(sys.argv) > 1 else app.SEED_DIR
|
||||
target_dir = sys.argv[1] if len(sys.argv) > 1 else os.environ.get('PHOTO_AI_SEED_DIR', '/opt/photo-ai-seed')
|
||||
cache_dir = sys.argv[2] if len(sys.argv) > 2 else ''
|
||||
if cache_dir:
|
||||
os.makedirs(cache_dir, exist_ok=True)
|
||||
@@ -68,7 +62,7 @@ def main():
|
||||
failed = []
|
||||
for name, spec in wanted().items():
|
||||
target = os.path.join(target_dir, name)
|
||||
if app.file_ok(target, spec['min_bytes']):
|
||||
if wm.file_ok(target, spec['min_bytes']):
|
||||
continue
|
||||
try:
|
||||
fetch(name, spec, target, cache_dir)
|
||||
|
||||
Reference in New Issue
Block a user