9
9
from os .path import abspath , exists , isdir , isfile , join
10
10
from pathlib import Path
11
11
from subprocess import CalledProcessError , check_output
12
- from typing import Any , List , Literal , NewType
12
+ from typing import Any , List , Literal , NewType , Optional
13
13
14
14
from aleph_message .models import Chain
15
15
from aleph_message .models .execution .environment import HypervisorType
16
16
from pydantic import BaseSettings , Field , HttpUrl
17
17
from pydantic .env_settings import DotenvType , env_file_sentinel
18
- from pydantic .typing import StrPath
19
18
20
19
from aleph .vm .orchestrator .chain import STREAM_CHAINS
21
20
from aleph .vm .utils import (
@@ -111,7 +110,7 @@ def obtain_dns_ips(dns_resolver: DnsResolver, network_interface: str) -> list[st
111
110
112
111
113
112
class Settings (BaseSettings ):
114
- SUPERVISOR_HOST = "127.0.0.1"
113
+ SUPERVISOR_HOST : str = "127.0.0.1"
115
114
SUPERVISOR_PORT : int = 4020
116
115
117
116
# Public domain name
@@ -123,32 +122,32 @@ class Settings(BaseSettings):
123
122
START_ID_INDEX : int = 4
124
123
PREALLOC_VM_COUNT : int = 0
125
124
REUSE_TIMEOUT : float = 60 * 60.0
126
- WATCH_FOR_MESSAGES = True
127
- WATCH_FOR_UPDATES = True
125
+ WATCH_FOR_MESSAGES : bool = True
126
+ WATCH_FOR_UPDATES : bool = True
128
127
129
- API_SERVER = "https://official.aleph.cloud"
128
+ API_SERVER : str = "https://official.aleph.cloud"
130
129
# Connect to the Quad9 VPN provider using their IPv4 and IPv6 addresses.
131
- CONNECTIVITY_IPV4_URL = "https://9.9.9.9/"
132
- CONNECTIVITY_IPV6_URL = "https://[2620:fe::fe]/"
133
- CONNECTIVITY_DNS_HOSTNAME = "example.org"
130
+ CONNECTIVITY_IPV4_URL : str = "https://9.9.9.9/"
131
+ CONNECTIVITY_IPV6_URL : str = "https://[2620:fe::fe]/"
132
+ CONNECTIVITY_DNS_HOSTNAME : str = "example.org"
134
133
135
- USE_JAILER = True
134
+ USE_JAILER : bool = True
136
135
# Changelog: PRINT_SYSTEM_LOGS use to print the MicroVM logs with the supervisor output.
137
136
# They are now in separate journald entries, disabling the settings disable the logs output of Firecracker VM (only)
138
137
# via the serial console. This break the logs endpoint for program, as such disabling it in prod is not recommended.
139
- PRINT_SYSTEM_LOGS = True
140
- IGNORE_TRACEBACK_FROM_DIAGNOSTICS = True
141
- LOG_LEVEL = "INFO"
142
- DEBUG_ASYNCIO = False
138
+ PRINT_SYSTEM_LOGS : bool = True
139
+ IGNORE_TRACEBACK_FROM_DIAGNOSTICS : bool = True
140
+ LOG_LEVEL : str = "INFO"
141
+ DEBUG_ASYNCIO : bool = False
143
142
144
143
# Networking does not work inside Docker/Podman
145
- ALLOW_VM_NETWORKING = True
144
+ ALLOW_VM_NETWORKING : bool = True
146
145
NETWORK_INTERFACE : str | None = None
147
- IPV4_ADDRESS_POOL = Field (
146
+ IPV4_ADDRESS_POOL : str = Field (
148
147
default = "172.16.0.0/12" ,
149
148
description = "IPv4 address range used to provide networks to VMs." ,
150
149
)
151
- IPV4_NETWORK_PREFIX_LENGTH = Field (
150
+ IPV4_NETWORK_PREFIX_LENGTH : int = Field (
152
151
default = 24 ,
153
152
description = "Individual VM network prefix length in bits" ,
154
153
)
@@ -180,30 +179,30 @@ class Settings(BaseSettings):
180
179
DNS_NAMESERVERS_IPV4 : list [str ] | None
181
180
DNS_NAMESERVERS_IPV6 : list [str ] | None
182
181
183
- FIRECRACKER_PATH = Path ("/opt/firecracker/firecracker" )
184
- JAILER_PATH = Path ("/opt/firecracker/jailer" )
185
- SEV_CTL_PATH = Path ("/opt/sevctl" )
186
- LINUX_PATH = Path ("/opt/firecracker/vmlinux.bin" )
182
+ FIRECRACKER_PATH : Path = Path ("/opt/firecracker/firecracker" )
183
+ JAILER_PATH : Path = Path ("/opt/firecracker/jailer" )
184
+ SEV_CTL_PATH : Path = Path ("/opt/sevctl" )
185
+ LINUX_PATH : Path = Path ("/opt/firecracker/vmlinux.bin" )
187
186
INIT_TIMEOUT : float = 20.0
188
187
189
188
CONNECTOR_URL = Url ("http://localhost:4021" )
190
189
191
- CACHE_ROOT = Path ("/var/cache/aleph/vm" )
192
- MESSAGE_CACHE : Path = Field (
190
+ CACHE_ROOT : Path = Path ("/var/cache/aleph/vm" )
191
+ MESSAGE_CACHE : Optional [ Path ] = Field (
193
192
None ,
194
193
description = "Default to CACHE_ROOT/message" ,
195
194
)
196
- CODE_CACHE : Path = Field (None , description = "Default to CACHE_ROOT/code" )
197
- RUNTIME_CACHE : Path = Field (None , description = "Default to CACHE_ROOT/runtime" )
198
- DATA_CACHE : Path = Field (None , description = "Default to CACHE_ROOT/data" )
195
+ CODE_CACHE : Optional [ Path ] = Field (None , description = "Default to CACHE_ROOT/code" )
196
+ RUNTIME_CACHE : Optional [ Path ] = Field (None , description = "Default to CACHE_ROOT/runtime" )
197
+ DATA_CACHE : Optional [ Path ] = Field (None , description = "Default to CACHE_ROOT/data" )
199
198
200
- EXECUTION_ROOT = Path ("/var/lib/aleph/vm" )
201
- JAILER_BASE_DIRECTORY : Path = Field (None , description = "Default to EXECUTION_ROOT/jailer" )
202
- EXECUTION_DATABASE : Path = Field (
199
+ EXECUTION_ROOT : Path = Path ("/var/lib/aleph/vm" )
200
+ JAILER_BASE_DIRECTORY : Optional [ Path ] = Field (None , description = "Default to EXECUTION_ROOT/jailer" )
201
+ EXECUTION_DATABASE : Optional [ Path ] = Field (
203
202
None , description = "Location of database file. Default to EXECUTION_ROOT/executions.sqlite3"
204
203
)
205
- EXECUTION_LOG_ENABLED = False
206
- EXECUTION_LOG_DIRECTORY : Path = Field (
204
+ EXECUTION_LOG_ENABLED : bool = False
205
+ EXECUTION_LOG_DIRECTORY : Optional [ Path ] = Field (
207
206
None , description = "Location of executions log. Default to EXECUTION_ROOT/executions/"
208
207
)
209
208
@@ -212,8 +211,8 @@ class Settings(BaseSettings):
212
211
)
213
212
JAILER_BASE_DIR : Path = Field (None )
214
213
215
- MAX_PROGRAM_ARCHIVE_SIZE = 10_000_000 # 10 MB
216
- MAX_DATA_ARCHIVE_SIZE = 10_000_000 # 10 MB
214
+ MAX_PROGRAM_ARCHIVE_SIZE : int = 10_000_000 # 10 MB
215
+ MAX_DATA_ARCHIVE_SIZE : int = 10_000_000 # 10 MB
217
216
218
217
PAYMENT_MONITOR_INTERVAL : float = Field (
219
218
default = 60.0 ,
@@ -254,7 +253,7 @@ class Settings(BaseSettings):
254
253
)
255
254
256
255
# hashlib.sha256(b"secret-token").hexdigest()
257
- ALLOCATION_TOKEN_HASH = "151ba92f2eb90bce67e912af2f7a5c17d8654b3d29895b042107ea312a7eebda"
256
+ ALLOCATION_TOKEN_HASH : str = "151ba92f2eb90bce67e912af2f7a5c17d8654b3d29895b042107ea312a7eebda"
258
257
259
258
ENABLE_QEMU_SUPPORT : bool = Field (default = True )
260
259
INSTANCE_DEFAULT_HYPERVISOR : HypervisorType | None = Field (
@@ -268,12 +267,12 @@ class Settings(BaseSettings):
268
267
"with SEV and SEV-ES" ,
269
268
)
270
269
271
- CONFIDENTIAL_DIRECTORY : Path = Field (
270
+ CONFIDENTIAL_DIRECTORY : Optional [ Path ] = Field (
272
271
None ,
273
272
description = "Confidential Computing default directory. Default to EXECUTION_ROOT/confidential" ,
274
273
)
275
274
276
- CONFIDENTIAL_SESSION_DIRECTORY : Path = Field (None , description = "Default to EXECUTION_ROOT/sessions" )
275
+ CONFIDENTIAL_SESSION_DIRECTORY : Optional [ Path ] = Field (None , description = "Default to EXECUTION_ROOT/sessions" )
277
276
278
277
ENABLE_GPU_SUPPORT : bool = Field (
279
278
default = False ,
@@ -285,11 +284,13 @@ class Settings(BaseSettings):
285
284
286
285
# Tests on programs
287
286
FAKE_DATA_PROGRAM : Path | None = None
288
- BENCHMARK_FAKE_DATA_PROGRAM = Path (abspath (join (__file__ , "../../../../examples/example_fastapi" )))
287
+ BENCHMARK_FAKE_DATA_PROGRAM : Path = Path (abspath (join (__file__ , "../../../../examples/example_fastapi" )))
289
288
290
- FAKE_DATA_MESSAGE = Path (abspath (join (__file__ , "../../../../examples/program_message_from_aleph.json" )))
289
+ FAKE_DATA_MESSAGE : Path = Path (abspath (join (__file__ , "../../../../examples/program_message_from_aleph.json" )))
291
290
FAKE_DATA_DATA : Path | None = Path (abspath (join (__file__ , "../../../../examples/data/" )))
292
- FAKE_DATA_RUNTIME = Path (abspath (join (__file__ , "../../../../runtimes/aleph-debian-12-python/rootfs.squashfs" )))
291
+ FAKE_DATA_RUNTIME : Path = Path (
292
+ abspath (join (__file__ , "../../../../runtimes/aleph-debian-12-python/rootfs.squashfs" ))
293
+ )
293
294
FAKE_DATA_VOLUME : Path | None = Path (abspath (join (__file__ , "../../../../examples/volumes/volume-venv.squashfs" )))
294
295
295
296
# Tests on instances
@@ -299,9 +300,9 @@ class Settings(BaseSettings):
299
300
description = "Identifier of the instance message used when testing the launch of an instance from the network" ,
300
301
)
301
302
302
- USE_FAKE_INSTANCE_BASE = False
303
- FAKE_INSTANCE_BASE = Path (abspath (join (__file__ , "../../../../runtimes/instance-rootfs/debian-12.btrfs" )))
304
- FAKE_QEMU_INSTANCE_BASE = Path (abspath (join (__file__ , "../../../../runtimes/instance-rootfs/rootfs.img" )))
303
+ USE_FAKE_INSTANCE_BASE : bool = False
304
+ FAKE_INSTANCE_BASE : Path = Path (abspath (join (__file__ , "../../../../runtimes/instance-rootfs/debian-12.btrfs" )))
305
+ FAKE_QEMU_INSTANCE_BASE : Path = Path (abspath (join (__file__ , "../../../../runtimes/instance-rootfs/rootfs.img" )))
305
306
FAKE_INSTANCE_ID : str = Field (
306
307
default = "decadecadecadecadecadecadecadecadecadecadecadecadecadecadecadeca" ,
307
308
description = "Identifier used for the 'fake instance' message defined in "
@@ -310,8 +311,8 @@ class Settings(BaseSettings):
310
311
FAKE_INSTANCE_MESSAGE = Path (abspath (join (__file__ , "../../../../examples/instance_message_from_aleph.json" )))
311
312
FAKE_INSTANCE_QEMU_MESSAGE = Path (abspath (join (__file__ , "../../../../examples/qemu_message_from_aleph.json" )))
312
313
313
- CHECK_FASTAPI_VM_ID = "63faf8b5db1cf8d965e6a464a0cb8062af8e7df131729e48738342d956f29ace"
314
- LEGACY_CHECK_FASTAPI_VM_ID = "67705389842a0a1b95eaa408b009741027964edc805997475e95c505d642edd8"
314
+ CHECK_FASTAPI_VM_ID : str = "63faf8b5db1cf8d965e6a464a0cb8062af8e7df131729e48738342d956f29ace"
315
+ LEGACY_CHECK_FASTAPI_VM_ID : str = "67705389842a0a1b95eaa408b009741027964edc805997475e95c505d642edd8"
315
316
316
317
# Developer options
317
318
@@ -408,10 +409,14 @@ def setup(self):
408
409
STREAM_CHAINS [Chain .AVAX ].rpc = str (self .RPC_AVAX )
409
410
STREAM_CHAINS [Chain .BASE ].rpc = str (self .RPC_BASE )
410
411
411
- os .makedirs (self .MESSAGE_CACHE , exist_ok = True )
412
- os .makedirs (self .CODE_CACHE , exist_ok = True )
413
- os .makedirs (self .RUNTIME_CACHE , exist_ok = True )
414
- os .makedirs (self .DATA_CACHE , exist_ok = True )
412
+ if self .MESSAGE_CACHE :
413
+ os .makedirs (self .MESSAGE_CACHE , exist_ok = True )
414
+ if self .CODE_CACHE :
415
+ os .makedirs (self .CODE_CACHE , exist_ok = True )
416
+ if self .RUNTIME_CACHE :
417
+ os .makedirs (self .RUNTIME_CACHE , exist_ok = True )
418
+ if self .DATA_CACHE :
419
+ os .makedirs (self .DATA_CACHE , exist_ok = True )
415
420
416
421
os .makedirs (self .EXECUTION_ROOT , exist_ok = True )
417
422
@@ -427,10 +432,14 @@ def setup(self):
427
432
428
433
self .LINUX_PATH = linux_path_on_device
429
434
430
- os .makedirs (self .EXECUTION_LOG_DIRECTORY , exist_ok = True )
431
- os .makedirs (self .PERSISTENT_VOLUMES_DIR , exist_ok = True )
432
- os .makedirs (self .CONFIDENTIAL_DIRECTORY , exist_ok = True )
433
- os .makedirs (self .CONFIDENTIAL_SESSION_DIRECTORY , exist_ok = True )
435
+ if self .EXECUTION_LOG_DIRECTORY :
436
+ os .makedirs (self .EXECUTION_LOG_DIRECTORY , exist_ok = True )
437
+ if self .PERSISTENT_VOLUMES_DIR :
438
+ os .makedirs (self .PERSISTENT_VOLUMES_DIR , exist_ok = True )
439
+ if self .CONFIDENTIAL_DIRECTORY :
440
+ os .makedirs (self .CONFIDENTIAL_DIRECTORY , exist_ok = True )
441
+ if self .CONFIDENTIAL_SESSION_DIRECTORY :
442
+ os .makedirs (self .CONFIDENTIAL_SESSION_DIRECTORY , exist_ok = True )
434
443
435
444
self .API_SERVER = self .API_SERVER .rstrip ("/" )
436
445
@@ -479,7 +488,7 @@ def __init__(
479
488
_env_file : DotenvType | None = env_file_sentinel ,
480
489
_env_file_encoding : str | None = None ,
481
490
_env_nested_delimiter : str | None = None ,
482
- _secrets_dir : StrPath | None = None ,
491
+ _secrets_dir : Path | None = None ,
483
492
** values : Any ,
484
493
) -> None :
485
494
super ().__init__ (_env_file , _env_file_encoding , _env_nested_delimiter , _secrets_dir , ** values )
0 commit comments