Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
3 changes: 3 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,8 @@ 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_tool: Literal["podman", "docker", "auto"] = "podman"
build_format: Literal["OCI", "docker"] = "OCI"


def load_config(environment: str, path: str | None) -> UserCodeDeploymentsConfig:
Expand Down
10 changes: 9 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,8 @@ 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_tool=config.build_tool,
build_format=config.build_format,
)


Expand Down Expand Up @@ -397,7 +399,13 @@ def deployment_deploy(
try:
logger.debug("Determining build tool...")
if not is_command_available(BuildTool.podman.value):
raise Exception("Podman installation is required to run dagster-uc.")
if use_sudo:
if not is_command_available(f"sudo {BuildTool.podman.value}"):
raise Exception("Podman installation is required to run dagster-uc.")
else:
raise Warning("Sudo is required to run podman")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true, you can run podman fine without sudo

Copy link
Contributor Author

@mackenziedott mackenziedott Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently not in Azure Pipelines! Either that or I have to do some funkier stuff to make it work. Running podman info fails right after installation, but sudo podman info works fine.

else:
raise Exception("Podman installation is required to run dagster-uc.")

logger.debug("Using 'podman' to build image.")
if deployment_name:
Expand Down
49 changes: 34 additions & 15 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 @@ -134,12 +135,15 @@ def get_azure_access_token(image_registry: str) -> bytes:
return token


def login_registry(image_registry: str) -> None:
def login_registry(
image_registry: str,
build_tool: Literal["podman", "docker", "auto"] = "podman",
) -> None:
"""Logs into registry with az cli"""
typer.echo(f"Logging into acr with {BuildTool.podman.value}...")
token = get_azure_access_token(image_registry)
cmd = [
BuildTool.podman.value,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep BuildTool.podman.value

build_tool,
"login",
"--username",
"00000000-0000-0000-0000-000000000000",
Expand Down Expand Up @@ -175,22 +179,37 @@ def build_and_push(
branch_name: str,
use_az_login: bool,
build_envs: list[str],
build_tool: Literal["podman", "docker", "auto"] = "podman",
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
previous_dir = os.getcwd()
os.chdir(repository_root)

cmd = [
BuildTool.podman.value,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep BuildTool.podman.value

"build",
"-f",
os.path.join(os.getcwd(), dockerfile),
"-t",
os.path.join(image_registry, f"{image_name}:{tag}"),
"--build-arg=BRANCH_NAME=" + branch_name,
".",
]
if build_tool == BuildTool.podman.value and build_format == "docker":
cmd = [
Copy link
Member

@ion-elgreco ion-elgreco Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can simplify this by making just doing:

if build_tool == BuildTool.podman.value and build_format == "docker":
    cmd += ["--format", "docker"]

build_tool,
"build",
"-f",
os.path.join(os.getcwd(), dockerfile),
"-t",
os.path.join(image_registry, f"{image_name}:{tag}"),
"--format",
"docker",
"--build-arg=BRANCH_NAME=" + branch_name,
".",
]
else:
cmd = [
build_tool,
"build",
"-f",
os.path.join(os.getcwd(), dockerfile),
"-t",
os.path.join(image_registry, f"{image_name}:{tag}"),
"--build-arg=BRANCH_NAME=" + branch_name,
".",
]
for env_var in build_envs:
cmd.extend(["--env", env_var])

Expand All @@ -200,10 +219,10 @@ 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, build_tool=build_tool)

typer.echo("Pushing image...")
cmd = [BuildTool.podman.value, "push", os.path.join(image_registry, f"{image_name}:{tag}")]
cmd = [build_tool, "push", os.path.join(image_registry, f"{image_name}:{tag}")]
if use_sudo:
cmd = ["sudo"] + cmd
exception_on_failed_subprocess(subprocess.run(cmd, capture_output=False))
Expand Down
Loading