Keep clean-clone HTTP port stable across full stack restart
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import socket
|
||||||
import tempfile
|
import tempfile
|
||||||
import uuid
|
import uuid
|
||||||
ROOT=Path(__file__).resolve().parents[1]
|
ROOT=Path(__file__).resolve().parents[1]
|
||||||
@@ -13,7 +14,12 @@ lines=['Checked source commit: '+commit,'Isolated Compose project: '+project]
|
|||||||
with tempfile.TemporaryDirectory(prefix='mtusi-lab2-clean-') as directory:
|
with tempfile.TemporaryDirectory(prefix='mtusi-lab2-clean-') as directory:
|
||||||
clone=Path(directory)/'repo'
|
clone=Path(directory)/'repo'
|
||||||
subprocess.run(['git','clone','--quiet','--local',str(ROOT),str(clone)],check=True)
|
subprocess.run(['git','clone','--quiet','--local',str(ROOT),str(clone)],check=True)
|
||||||
env=dict(os.environ,COMPOSE_PROJECT_NAME=project,APP_PORT='0',SESSION_TTL_SECONDS='3600')
|
# A dynamically published port 0 may change on container stop/start.
|
||||||
|
# Select a free numeric port so persistence keeps the same base URL.
|
||||||
|
with socket.socket() as listener:
|
||||||
|
listener.bind(('127.0.0.1',0))
|
||||||
|
host_port=listener.getsockname()[1]
|
||||||
|
env=dict(os.environ,COMPOSE_PROJECT_NAME=project,APP_PORT=str(host_port),SESSION_TTL_SECONDS='3600')
|
||||||
def run(args):
|
def run(args):
|
||||||
p=subprocess.run(args,cwd=clone,env=env,text=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
|
p=subprocess.run(args,cwd=clone,env=env,text=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
|
||||||
lines.append('$ '+' '.join(args)+'\n'+p.stdout)
|
lines.append('$ '+' '.join(args)+'\n'+p.stdout)
|
||||||
|
|||||||
Reference in New Issue
Block a user