Skip to content

Commit 0de1841

Browse files
committed
moved helper classes to helper
1 parent ffc8689 commit 0de1841

File tree

9 files changed

+671
-526
lines changed

9 files changed

+671
-526
lines changed

src/gaiaflow/cli/commands/minikube.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import typer
66

77
from gaiaflow.constants import DEFAULT_IMAGE_NAME
8+
from gaiaflow.managers.helpers import DockerHandlerMode
89

910
app = typer.Typer()
1011
fs = fsspec.filesystem("file")
@@ -110,8 +111,7 @@ def dockerize(
110111
DEFAULT_IMAGE_NAME, "--image-name", "-i", help=("Name of your image.")
111112
),
112113
dockerfile_path: Path = typer.Option(
113-
None, "--dockerfile-path", "-d", help=("Path to your custom "
114-
"Dockerfile")
114+
None, "--dockerfile-path", "-d", help=("Path to your custom Dockerfile")
115115
),
116116
):
117117
imports = load_imports()
@@ -137,6 +137,47 @@ def dockerize(
137137
)
138138

139139

140+
@app.command(help="List all the docker images in your system")
141+
def list_images():
142+
imports = load_imports()
143+
project_path = Path.cwd()
144+
gaiaflow_path, user_project_path = imports.create_gaiaflow_context_path(
145+
project_path
146+
)
147+
gaiaflow_path_exists = imports.gaiaflow_path_exists_in_state(gaiaflow_path, True)
148+
if not gaiaflow_path_exists:
149+
typer.echo("Please create a project with Gaiaflow before running this command.")
150+
return
151+
imports.MinikubeManager.run(
152+
gaiaflow_path=gaiaflow_path,
153+
user_project_path=user_project_path,
154+
action=imports.ExtendedAction.LIST_IMAGES,
155+
docker_handler_mode=DockerHandlerMode.MINIKUBE,
156+
)
157+
158+
@app.command(help="Delete a docker image from your system")
159+
def remove_image(image_name: str = typer.Option(
160+
DEFAULT_IMAGE_NAME, "--image-name", "-i", help=("Name of image "
161+
"to be deleted.")
162+
),):
163+
imports = load_imports()
164+
project_path = Path.cwd()
165+
gaiaflow_path, user_project_path = imports.create_gaiaflow_context_path(
166+
project_path
167+
)
168+
gaiaflow_path_exists = imports.gaiaflow_path_exists_in_state(gaiaflow_path, True)
169+
if not gaiaflow_path_exists:
170+
typer.echo("Please create a project with Gaiaflow before running this command.")
171+
return
172+
imports.MinikubeManager.run(
173+
gaiaflow_path=gaiaflow_path,
174+
user_project_path=user_project_path,
175+
action=imports.ExtendedAction.REMOVE_IMAGE,
176+
image_name=image_name,
177+
docker_handler_mode=DockerHandlerMode.MINIKUBE,
178+
)
179+
180+
140181
@app.command(
141182
help="Create a config file for Airflow to talk to Kubernetes "
142183
"cluster. To be used only when debugging required."

src/gaiaflow/cli/commands/mlops.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import typer
77

88
from gaiaflow.constants import DEFAULT_IMAGE_NAME, Service
9+
from gaiaflow.managers.helpers import DockerHandlerMode
910

1011
app = typer.Typer()
1112
fs = fsspec.filesystem("file")
@@ -256,8 +257,7 @@ def dockerize(
256257
DEFAULT_IMAGE_NAME, "--image-name", "-i", help=("Name of your image.")
257258
),
258259
dockerfile_path: Path = typer.Option(
259-
None, "--dockerfile-path", "-d", help=("Path to your custom "
260-
"Dockerfile")
260+
None, "--dockerfile-path", "-d", help=("Path to your custom Dockerfile")
261261
),
262262
):
263263
imports = load_imports()
@@ -288,6 +288,47 @@ def dockerize(
288288
)
289289

290290

291+
292+
@app.command(help="List all the docker images in your system")
293+
def list_images():
294+
imports = load_imports()
295+
project_path = Path.cwd()
296+
gaiaflow_path, user_project_path = imports.create_gaiaflow_context_path(
297+
project_path
298+
)
299+
gaiaflow_path_exists = imports.gaiaflow_path_exists_in_state(gaiaflow_path, True)
300+
if not gaiaflow_path_exists:
301+
typer.echo("Please create a project with Gaiaflow before running this command.")
302+
return
303+
imports.MinikubeManager.run(
304+
gaiaflow_path=gaiaflow_path,
305+
user_project_path=user_project_path,
306+
action=imports.ExtendedAction.LIST_IMAGES,
307+
docker_handler_mode=DockerHandlerMode.LOCAL,
308+
)
309+
310+
@app.command(help="Delete a docker image from your system")
311+
def remove_image(image_name: str = typer.Option(
312+
DEFAULT_IMAGE_NAME, "--image-name", "-i", help=("Name of image "
313+
"to be deleted.")
314+
),):
315+
imports = load_imports()
316+
project_path = Path.cwd()
317+
gaiaflow_path, user_project_path = imports.create_gaiaflow_context_path(
318+
project_path
319+
)
320+
gaiaflow_path_exists = imports.gaiaflow_path_exists_in_state(gaiaflow_path, True)
321+
if not gaiaflow_path_exists:
322+
typer.echo("Please create a project with Gaiaflow before running this command.")
323+
return
324+
imports.MinikubeManager.run(
325+
gaiaflow_path=gaiaflow_path,
326+
user_project_path=user_project_path,
327+
action=imports.ExtendedAction.REMOVE_IMAGE,
328+
image_name=image_name,
329+
docker_handler_mode=DockerHandlerMode.LOCAL,
330+
)
331+
291332
@app.command(
292333
help="Update the dependencies for the Airflow tasks. This command "
293334
"synchronizes the running container environments with the project's"

src/gaiaflow/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class ExtendedAction:
2020
CREATE_CONFIG = Action("create_config")
2121
CREATE_SECRET = Action("create_secret")
2222
UPDATE_DEPS = Action("update_deps")
23+
LIST_IMAGES = Action("list-images")
24+
REMOVE_IMAGE = Action("remove-image")
2325

2426

2527
GAIAFLOW_CONFIG_DIR = Path.home() / ".gaiaflow"

src/gaiaflow/core/create_task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def create_task(
3434
env_vars: dict | None = None,
3535
retries: int = 3,
3636
dag=None,
37-
**op_kwargs
37+
**op_kwargs,
3838
):
3939
"""It is a high-level abstraction on top of Apache Airflow operators.
4040
@@ -70,7 +70,7 @@ def create_task(
7070
retries=retries,
7171
params=dag_params,
7272
mode=gaiaflow_mode,
73-
**op_kwargs
73+
**op_kwargs,
7474
)
7575

7676
return operator.create_task()

src/gaiaflow/core/operators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def run_wrapper(**op_kwargs):
158158
retries=self.retries,
159159
expect_airflow=False,
160160
expect_pendulum=False,
161-
**self.op_kwargs
161+
**self.op_kwargs,
162162
)
163163

164164

@@ -307,7 +307,7 @@ def create_task(self):
307307
auto_remove="success",
308308
command=command,
309309
# docker_url="unix://var/run/docker.sock",
310-
docker_url='tcp://docker-proxy:2375',
310+
docker_url="tcp://docker-proxy:2375",
311311
# docker_url="tcp://host.docker.internal:2375",
312312
environment=combined_env,
313313
network_mode="docker-compose_ml-network",

0 commit comments

Comments
 (0)