Skip to content

Commit df17d17

Browse files
feat: add merge migration for volume cleanup and secrets
1 parent 57d7e32 commit df17d17

4 files changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""merge volume cleanup and secrets migrations
2+
3+
Revision ID: d268739bd76b
4+
Revises: 09f10d63c924, 644b8a114187
5+
Create Date: 2025-07-07 10:22:50.061037
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = "d268739bd76b"
11+
down_revision = ("09f10d63c924", "644b8a114187")
12+
branch_labels = None
13+
depends_on = None
14+
15+
16+
def upgrade() -> None:
17+
pass
18+
19+
20+
def downgrade() -> None:
21+
pass
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from dstack._internal.core.models.fleets import FleetConfiguration, FleetSpec
2+
from dstack._internal.core.models.profiles import Profile
3+
from dstack._internal.server.services.fleets import fleet_configuration_to_yaml
4+
5+
6+
def test_fleet_configuration_to_yaml():
7+
"""Test that fleet configuration is correctly converted to YAML."""
8+
# Create a simple fleet configuration
9+
config = FleetConfiguration(
10+
name="test-fleet",
11+
nodes=2,
12+
resources={"gpu": "24GB"},
13+
)
14+
15+
spec = FleetSpec(
16+
configuration=config,
17+
profile=Profile(name="test-profile"),
18+
)
19+
20+
# Convert to YAML
21+
yaml_content = fleet_configuration_to_yaml(spec)
22+
23+
# Verify the YAML contains expected content
24+
assert "name: test-fleet" in yaml_content
25+
assert "min: 2" in yaml_content # nodes.min
26+
assert "max: 2" in yaml_content # nodes.max
27+
assert "gpu:" in yaml_content
28+
assert "type: fleet" in yaml_content
29+
30+
31+
def test_fleet_configuration_to_yaml_with_ssh():
32+
"""Test that SSH fleet configuration is correctly converted to YAML."""
33+
# Create an SSH fleet configuration
34+
config = FleetConfiguration(
35+
name="ssh-fleet",
36+
ssh_config={
37+
"user": "ubuntu",
38+
"hosts": ["192.168.1.100", "192.168.1.101"],
39+
},
40+
)
41+
42+
spec = FleetSpec(
43+
configuration=config,
44+
profile=Profile(name="test-profile"),
45+
)
46+
47+
# Convert to YAML
48+
yaml_content = fleet_configuration_to_yaml(spec)
49+
50+
# Verify the YAML contains expected content
51+
assert "name: ssh-fleet" in yaml_content
52+
assert "user: ubuntu" in yaml_content
53+
assert "192.168.1.100" in yaml_content
54+
assert "192.168.1.101" in yaml_content
55+
assert "type: fleet" in yaml_content
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from dstack._internal.core.models.configurations import (
2+
DevEnvironmentConfiguration,
3+
ServiceConfiguration,
4+
TaskConfiguration,
5+
)
6+
from dstack._internal.core.models.runs import RunSpec
7+
from dstack._internal.server.services.runs import run_configuration_to_yaml
8+
9+
10+
class TestRunConfigurationYaml:
11+
def test_task_configuration_to_yaml(self):
12+
"""Test converting task configuration to YAML"""
13+
config = TaskConfiguration(
14+
name="test-task",
15+
commands=["echo 'Hello World'"],
16+
resources={"cpu": 1, "memory": "1GB"},
17+
image="python:3.9",
18+
)
19+
20+
run_spec = RunSpec(
21+
run_name="test-run", configuration=config, ssh_key_pub="ssh-rsa test-key"
22+
)
23+
24+
yaml_content = run_configuration_to_yaml(run_spec)
25+
26+
assert "name: test-run" in yaml_content
27+
assert "type: task" in yaml_content
28+
assert "commands:" in yaml_content
29+
assert "echo 'Hello World'" in yaml_content
30+
assert "image: python:3.9" in yaml_content
31+
32+
def test_service_configuration_to_yaml(self):
33+
"""Test converting service configuration to YAML"""
34+
config = ServiceConfiguration(
35+
name="test-service",
36+
commands=["python app.py"],
37+
port=8080,
38+
resources={"cpu": 2, "memory": "2GB"},
39+
image="python:3.9",
40+
)
41+
42+
run_spec = RunSpec(
43+
run_name="test-service-run", configuration=config, ssh_key_pub="ssh-rsa test-key"
44+
)
45+
46+
yaml_content = run_configuration_to_yaml(run_spec)
47+
48+
assert "name: test-service-run" in yaml_content
49+
assert "type: service" in yaml_content
50+
assert "commands:" in yaml_content
51+
assert "python app.py" in yaml_content
52+
assert "port:" in yaml_content
53+
54+
def test_dev_environment_configuration_to_yaml(self):
55+
"""Test converting dev environment configuration to YAML"""
56+
config = DevEnvironmentConfiguration(
57+
name="test-dev",
58+
ide="vscode",
59+
resources={"cpu": 1, "memory": "1GB"},
60+
image="python:3.9",
61+
)
62+
63+
run_spec = RunSpec(
64+
run_name="test-dev-run", configuration=config, ssh_key_pub="ssh-rsa test-key"
65+
)
66+
67+
yaml_content = run_configuration_to_yaml(run_spec)
68+
69+
assert "name: test-dev-run" in yaml_content
70+
assert "type: dev-environment" in yaml_content
71+
assert "ide: vscode" in yaml_content
72+
73+
def test_configuration_without_run_name(self):
74+
"""Test converting configuration when run_name is not set"""
75+
config = TaskConfiguration(
76+
name="test-task",
77+
commands=["echo 'Hello World'"],
78+
resources={"cpu": 1, "memory": "1GB"},
79+
image="python:3.9",
80+
)
81+
82+
run_spec = RunSpec(configuration=config, ssh_key_pub="ssh-rsa test-key")
83+
84+
yaml_content = run_configuration_to_yaml(run_spec)
85+
86+
assert "name: test-task" in yaml_content
87+
assert "type: task" in yaml_content

~/.dstack/server/config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
projects:
2+
- name: main
3+
backends:
4+
- type: local
5+
name: local
6+
encryption:
7+
keys: []

0 commit comments

Comments
 (0)