Skip to content

Commit 7b9ace9

Browse files
committed
Merge branch 'develop' into feature/morph-data-frontend
2 parents 69e5e53 + a7cec4e commit 7b9ace9

9 files changed

Lines changed: 58 additions & 90 deletions

File tree

core/morph/api/cloud/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,20 @@ def verify_api_secret(self) -> MorphClientResponse:
132132

133133
@validate_project_id
134134
def initiate_deployment(
135-
self, project_id: str, image_build_log: str, image_checksum: str
135+
self,
136+
project_id: str,
137+
image_build_log: str,
138+
image_checksum: str,
139+
config: Optional[dict[str, Any]] = None,
136140
) -> MorphClientResponse:
137141
path = "deployment"
138-
body = {
142+
body: dict[str, Any] = {
139143
"projectId": project_id,
140144
"imageBuildLog": image_build_log,
141145
"imageChecksum": image_checksum,
142146
}
147+
if config:
148+
body["config"] = config
143149

144150
return self.request(method="POST", path=path, data=body)
145151

core/morph/api/service.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ async def file_upload_service(input: UploadFileService) -> Any:
284284
)
285285

286286
# Read the saved file path from the cache (always created as following path)
287-
cache_file = Path(find_project_root_dir()).joinpath(
288-
".morph/cache/file_upload.md"
289-
)
290-
with open(cache_file, "r") as f:
291-
saved_filepath = f.read()
287+
saved_filepath = ""
288+
cache_file = Path(temp_dir).joinpath("file_upload.cache")
289+
if cache_file.exists():
290+
with open(cache_file, "r") as f:
291+
saved_filepath = f.read()
292292

293293
# Remove the temporary directory
294294
if os.path.exists(temp_dir):

core/morph/config/project.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from typing import List, Optional
2+
from typing import Dict, List, Optional
33

44
import yaml
55
from pydantic import BaseModel, Field
@@ -13,6 +13,21 @@
1313
from morph.task.utils.morph import find_project_root_dir
1414

1515

16+
class BuildConfig(BaseModel):
17+
use_custom_dockerfile: bool = False
18+
runtime: Optional[str] = None
19+
framework: Optional[str] = "morph"
20+
package_manager: Optional[str] = None
21+
context: Optional[str] = None
22+
build_args: Optional[Dict[str, str]] = None
23+
24+
25+
class DeploymentConfig(BaseModel):
26+
provider: Optional[str] = "aws"
27+
aws: Optional[Dict[str, Optional[str]]] = None
28+
gcp: Optional[Dict[str, Optional[str]]] = None
29+
30+
1631
class MorphProject(BaseModel):
1732
profile: Optional[str] = "default"
1833
source_paths: List[str] = Field(default_factory=lambda: ["src"])
@@ -21,6 +36,8 @@ class MorphProject(BaseModel):
2136
package_manager: str = Field(
2237
default="pip", description="Package manager to use, e.g., pip or poetry."
2338
)
39+
build: Optional[BuildConfig] = Field(default_factory=BuildConfig)
40+
deployment: Optional[DeploymentConfig] = Field(default_factory=DeploymentConfig)
2441

2542
class Config:
2643
arbitrary_types_allowed = True

core/morph/include/Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

core/morph/include/starter_template/.dockerignore

Lines changed: 0 additions & 24 deletions
This file was deleted.

core/morph/include/starter_template/src/__init__.py

Whitespace-only changes.

core/morph/task/deploy.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ def __init__(self, args: Flags):
3333
sys.exit(1)
3434

3535
# Load morph_project.yml or equivalent
36-
project = load_project(self.project_root)
37-
if not project:
36+
self.project = load_project(self.project_root)
37+
if not self.project:
3838
click.echo(click.style("Project configuration not found.", fg="red"))
3939
sys.exit(1)
40-
elif project.project_id is None:
40+
elif self.project.project_id is None:
4141
click.echo(
4242
click.style(
4343
"Error: No project id found. Please fill project_id in morph_project.yml.",
4444
fg="red",
4545
)
4646
)
4747
sys.exit(1)
48-
self.package_manager = project.package_manager
48+
self.package_manager = self.project.package_manager
4949

5050
# Check Dockerfile existence
5151
self.dockerfile = os.path.join(self.project_root, "Dockerfile")
@@ -125,6 +125,7 @@ def run(self):
125125
project_id=self.client.project_id,
126126
image_build_log=image_build_log,
127127
image_checksum=image_checksum,
128+
config=self.project.model_dump() if self.project else None,
128129
)
129130
except Exception as e:
130131
click.echo(

core/morph/task/new.py

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
import click
1111
from morph.cli.flags import Flags
12-
from morph.config.project import default_initial_project, load_project, save_project
12+
from morph.config.project import (
13+
BuildConfig,
14+
default_initial_project,
15+
load_project,
16+
save_project,
17+
)
1318
from morph.constants import MorphConstant
1419
from morph.task.base import BaseTask
1520
from morph.task.utils.run_backend.state import MorphGlobalContext
@@ -105,42 +110,12 @@ def run(self):
105110
)
106111
project.package_manager = "poetry"
107112

108-
save_project(self.project_root, project)
109-
110-
# Generate the Dockerfile template
111-
template_dir = Path(__file__).parents[1].joinpath("include")
112-
docker_template_file = template_dir.joinpath("Dockerfile")
113-
if not docker_template_file.exists():
114-
click.echo(
115-
click.style(
116-
f"Template file not found: {docker_template_file}", fg="red"
117-
)
118-
)
119-
click.echo()
120-
sys.exit(1)
121-
122-
# Generate the Dockerfile with the selected Python version
123-
dockerfile_path = os.path.join(self.project_root, "Dockerfile")
124-
try:
125-
with docker_template_file.open("r", encoding="utf-8") as f:
126-
dockerfile_content = f.read()
113+
if project.build is None:
114+
project.build = BuildConfig()
115+
project.build.package_manager = project.package_manager
116+
project.build.runtime = f"python{self.selected_python_version}"
127117

128-
# Replace the placeholder with the selected Python version
129-
dockerfile_content = dockerfile_content.replace(
130-
"${MORPH_PYTHON_VERSION}", self.selected_python_version
131-
)
132-
133-
# Write the updated Dockerfile to the project directory
134-
with open(dockerfile_path, "w") as output_file:
135-
output_file.write(dockerfile_content)
136-
except FileNotFoundError as e:
137-
click.echo(
138-
click.style(f"Error: Template Dockerfile not found: {e}", fg="red")
139-
)
140-
sys.exit(1)
141-
except IOError as e:
142-
click.echo(click.style(f"Error: Unable to write Dockerfile: {e}", fg="red"))
143-
sys.exit(1)
118+
save_project(self.project_root, project)
144119

145120
try:
146121
morph_data_version = importlib.metadata.version("morph-data")
@@ -178,9 +153,13 @@ def run(self):
178153
pyproject_path = Path(self.project_root) / "pyproject.toml"
179154
pyproject_path.write_text(pyproject_content, encoding="utf-8")
180155

156+
# Run 'poetry install' to install the dependencies
157+
click.echo(click.style("Running 'poetry install'...", fg="blue"))
158+
subprocess.run(["poetry", "install"], cwd=self.project_root, check=True)
159+
181160
click.echo(
182161
click.style(
183-
"Added 'morph-data' to pyproject.toml with 'morph-data'.",
162+
"Poetry initialized with 'morph-data' as a dependency.",
184163
fg="green",
185164
)
186165
)
@@ -212,9 +191,13 @@ def run(self):
212191
pyproject_path = Path(self.project_root) / "pyproject.toml"
213192
pyproject_path.write_text(pyproject_content, encoding="utf-8")
214193

194+
# Run 'uv sync' to install dependencies
195+
click.echo(click.style("Running 'uv sync'...", fg="blue"))
196+
subprocess.run(["uv", "sync"], cwd=self.project_root, check=True)
197+
215198
click.echo(
216199
click.style(
217-
"Added 'morph-data' to pyproject.toml with 'morph-data'.",
200+
"uv initialized with 'morph-data' as a dependency.",
218201
fg="green",
219202
)
220203
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "morph-data"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Morph is a python-centric full-stack framework for building and deploying data apps."
55
authors = ["Morph <contact@morphdb.io>"]
66
packages = [

0 commit comments

Comments
 (0)