Set cargo env vars to use configured build and repo paths
This commit is contained in:
parent
cdc2ecb195
commit
4ac729fd82
42
aocsync.py
42
aocsync.py
@ -636,28 +636,29 @@ class CargoAOCRunner:
|
|||||||
'-w', f'/repo/{work_dir_rel}', # Working directory in container
|
'-w', f'/repo/{work_dir_rel}', # Working directory in container
|
||||||
]
|
]
|
||||||
|
|
||||||
# Handle cargo registry cache
|
# Handle cargo registry cache and cargo home
|
||||||
if registry_cache_dir:
|
if registry_cache_dir:
|
||||||
# Use persistent registry cache
|
# Use persistent registry cache - mount entire CARGO_HOME directory
|
||||||
registry_cache_path = Path(registry_cache_dir).resolve()
|
registry_cache_path = Path(registry_cache_dir).resolve()
|
||||||
registry_cache_path.mkdir(parents=True, exist_ok=True)
|
registry_cache_path.mkdir(parents=True, exist_ok=True)
|
||||||
podman_cmd.extend(['-v', f'{registry_cache_path}:/root/.cargo/registry:rw'])
|
# Mount the parent directory as CARGO_HOME so both registry and bin are persisted
|
||||||
logger.info(f"Using persistent registry cache: {registry_cache_path}")
|
cargo_home_path = registry_cache_path.parent / 'cargo-home'
|
||||||
|
cargo_home_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
podman_cmd.extend(['-v', f'{cargo_home_path}:/root/.cargo:rw'])
|
||||||
|
logger.info(f"Using persistent cargo home (registry + bin): {cargo_home_path}")
|
||||||
else:
|
else:
|
||||||
# Use tmpfs for registry cache (cleared after each run)
|
# Use tmpfs for cargo home (cleared after each run)
|
||||||
podman_cmd.extend(['--tmpfs', '/root/.cargo/registry:rw,noexec,nosuid,size=100m'])
|
podman_cmd.extend(['--tmpfs', '/root/.cargo:rw,noexec,nosuid,size=200m'])
|
||||||
|
|
||||||
# Handle cargo-aoc installation location (only needed if installing on-the-fly)
|
# Note: cargo-aoc installation location is handled above via CARGO_HOME mount
|
||||||
if needs_cargo_aoc_install:
|
# If using persistent cache, cargo bin is already mounted via cargo-home
|
||||||
# Need writable /root/.cargo/bin to install cargo-aoc
|
# If using tmpfs, cargo bin is already included in /root/.cargo tmpfs
|
||||||
if registry_cache_dir:
|
|
||||||
# If using persistent registry cache, also persist cargo bin
|
# Set environment variables in the container so cargo uses the mounted directories
|
||||||
cargo_bin_path = Path(registry_cache_dir).parent / 'cargo-bin'
|
# Set build directory (target directory for compiled artifacts)
|
||||||
cargo_bin_path.mkdir(parents=True, exist_ok=True)
|
podman_cmd.extend(['-e', 'CARGO_TARGET_DIR=/build/target'])
|
||||||
podman_cmd.extend(['-v', f'{cargo_bin_path}:/root/.cargo/bin:rw'])
|
# Set cargo home to use the mounted registry cache
|
||||||
else:
|
podman_cmd.extend(['-e', 'CARGO_HOME=/root/.cargo'])
|
||||||
# Use tmpfs for cargo bin (will be cleared, but allows installation)
|
|
||||||
podman_cmd.extend(['--tmpfs', '/root/.cargo/bin:rw,noexec,nosuid,size=50m'])
|
|
||||||
|
|
||||||
# Add Podman image and command
|
# Add Podman image and command
|
||||||
if needs_cargo_aoc_install:
|
if needs_cargo_aoc_install:
|
||||||
@ -674,16 +675,11 @@ class CargoAOCRunner:
|
|||||||
'cargo', 'aoc', '--day', str(day)
|
'cargo', 'aoc', '--day', str(day)
|
||||||
])
|
])
|
||||||
|
|
||||||
# Set CARGO_TARGET_DIR to use the mounted build directory
|
|
||||||
env = os.environ.copy()
|
|
||||||
env['CARGO_TARGET_DIR'] = '/build/target'
|
|
||||||
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
podman_cmd,
|
podman_cmd,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
timeout=300, # 5 minute timeout
|
timeout=300 # 5 minute timeout
|
||||||
env=env
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user