Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dagster_uc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
from dataclasses import dataclass, fields
from typing import Literal

import yaml

Expand Down Expand Up @@ -51,6 +52,7 @@ class UserCodeDeploymentsConfig:
dagster_workspace_yaml_configmap_name: str = "dagster-workspace-yaml"
uc_deployment_semaphore_name: str = "dagster-uc-semaphore"
uc_release_name: str = "dagster-user-code"
build_format: Literal["OCI", "docker"] = "OCI"


def load_config(environment: str, path: str | None) -> UserCodeDeploymentsConfig:
Expand Down
11 changes: 10 additions & 1 deletion dagster_uc/manage_user_code_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def build_push_container(
branch_name=branch_name,
use_az_login=config.use_az_login,
build_envs=config.docker_env_vars if config.docker_env_vars is not None else [],
build_format=config.build_format,
)


Expand Down Expand Up @@ -383,6 +384,13 @@ def deployment_deploy(
help="If this is provided, buildah or docker will be called with sudo",
),
] = False,
ignore_check: Annotated[
bool,
typer.Option(
"--ignore-check",
help="If this is provided, ignore the check for if podman is installed. This is used for some CI/CD environments that require podman to always be in sudo mode",
),
] = False,
):
handler._ensure_dagster_version_match()

Expand All @@ -396,7 +404,7 @@ def deployment_deploy(

try:
logger.debug("Determining build tool...")
if not is_command_available(BuildTool.podman.value):
if not ignore_check and not is_command_available(BuildTool.podman.value):
raise Exception("Podman installation is required to run dagster-uc.")

logger.debug("Using 'podman' to build image.")
Expand All @@ -420,6 +428,7 @@ def deployment_deploy(
config.container_registry,
config.dagster_version,
config.use_az_login,
use_sudo=use_sudo,
)

typer.echo(f"Deploying deployment \033[1m'{deployment_name}:{new_tag}'\033[0m")
Expand Down
20 changes: 15 additions & 5 deletions dagster_uc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
from enum import Enum
from subprocess import Popen, TimeoutExpired
from typing import Literal

import typer

Expand Down Expand Up @@ -68,13 +69,14 @@ def gen_tag(
container_registry: str,
dagster_version: str,
use_az_login: bool,
use_sudo: bool = False,
) -> str:
"""Identifies the latest tag present in the container registry and increments it by one."""
if use_az_login:
login_registry(container_registry)
login_registry(container_registry, use_sudo=use_sudo)

res = run_cli_command(
f"podman search {os.path.join(container_registry, deployment_name)} --list-tags --format {{{{.Tag}}}} --limit 9999999",
f"{'sudo ' if use_sudo else ''}{BuildTool.podman.value} search {os.path.join(container_registry, deployment_name)} --list-tags --format {{{{.Tag}}}} --limit 9999999",
ignore_failures=True,
capture_output=True,
timeout=15,
Expand Down Expand Up @@ -134,7 +136,10 @@ def get_azure_access_token(image_registry: str) -> bytes:
return token


def login_registry(image_registry: str) -> None:
def login_registry(
image_registry: str,
use_sudo: bool = False,
) -> None:
"""Logs into registry with az cli"""
typer.echo(f"Logging into acr with {BuildTool.podman.value}...")
token = get_azure_access_token(image_registry)
Expand All @@ -146,6 +151,8 @@ def login_registry(image_registry: str) -> None:
"--password-stdin",
image_registry,
]
if use_sudo:
cmd = ["sudo"] + cmd
exception_on_failed_subprocess(subprocess.run(cmd, input=token, capture_output=False))


Expand Down Expand Up @@ -175,6 +182,7 @@ def build_and_push(
branch_name: str,
use_az_login: bool,
build_envs: list[str],
build_format: Literal["OCI", "docker"] = "OCI",
):
"""Build a docker image and push it to the registry"""
# We need to work from the root of the repo so docker can access all files
Expand All @@ -189,8 +197,10 @@ def build_and_push(
"-t",
os.path.join(image_registry, f"{image_name}:{tag}"),
"--build-arg=BRANCH_NAME=" + branch_name,
".",
]
if build_format == "docker":
cmd += ["--format", "docker"]
cmd += ["."] # Since this always has to be at the end
for env_var in build_envs:
cmd.extend(["--env", env_var])

Expand All @@ -200,7 +210,7 @@ def build_and_push(
exception_on_failed_subprocess(subprocess.run(cmd, capture_output=False))

if use_az_login:
login_registry(image_registry=image_registry)
login_registry(image_registry=image_registry, use_sudo=use_sudo)

typer.echo("Pushing image...")
cmd = [BuildTool.podman.value, "push", os.path.join(image_registry, f"{image_name}:{tag}")]
Expand Down
Loading