Skip to content

Commit 846e097

Browse files
authored
fix: Dockerfile support for both published and dev version (#685)
1 parent d5e99cc commit 846e097

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

src/codegen/cli/commands/start/Dockerfile-runner renamed to src/codegen/cli/commands/start/Dockerfile

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ RUN apt-get update && apt-get install -y \
2121
# Cleanup apt cache to reduce image size
2222
&& rm -rf /var/lib/apt/lists/*
2323

24-
# Set git config
25-
RUN git config --global user.email "[email protected]" \
26-
&& git config --global user.name "codegen-bot"
27-
2824
# Install nvm and Node.js
2925
SHELL ["/bin/bash", "-c"]
3026
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
@@ -46,14 +42,23 @@ RUN node --version \
4642
&& pnpm --version \
4743
&& python --version
4844

49-
# Build codegen
50-
WORKDIR /codegen-sdk
51-
COPY . .
45+
# Add build argument for codegen version and build type
46+
ARG CODEGEN_VERSION
47+
ARG BUILD_TYPE="release" # Can be "release" or "dev"
48+
49+
# Install codegen based on BUILD_TYPE
5250
RUN --mount=type=cache,target=/root/.cache/uv \
53-
uv venv && source .venv/bin/activate \
54-
&& uv sync --frozen --no-dev --all-extras \
55-
&& uv pip install --system -e . --no-deps \
56-
&& uv pip install --system .
51+
--mount=type=bind,source=.,target=/codegen-sdk,rw \
52+
if [ "$BUILD_TYPE" = "release" ]; then \
53+
uv pip install --system codegen==${CODEGEN_VERSION}; \
54+
else \
55+
cd /codegen-sdk \
56+
&& uv venv && source .venv/bin/activate \
57+
&& uv sync --frozen --no-dev --all-extras \
58+
&& uv pip install --system -e . --no-deps \
59+
&& uv pip install --system .; \
60+
fi
61+
5762
RUN codegen --version
5863

5964
# Create a non-root user for local development + debugging

src/codegen/cli/commands/start/main.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ def start_command(port: int | None, detached: bool = False, skip_build: bool = F
3434
else:
3535
return _handle_existing_container(repo_config, container, force)
3636

37-
codegen_version = version("codegen")
38-
rich.print(f"[bold green]Codegen version:[/bold green] {codegen_version}")
39-
codegen_root = Path(__file__).parent.parent.parent.parent.parent.parent
4037
if port is None:
4138
port = get_free_port()
4239

4340
try:
4441
if not skip_build:
45-
_build_docker_image(codegen_root)
42+
codegen_root = Path(__file__).parent.parent.parent.parent.parent.parent
43+
codegen_version = version("codegen")
44+
_build_docker_image(codegen_root=codegen_root, codegen_version=codegen_version)
4645
_run_docker_container(repo_config, port, detached)
4746
rich.print(Panel(f"[green]Server started successfully![/green]\nAccess the server at: [bold]http://{_default_host}:{port}[/bold]", box=ROUNDED, title="Codegen Server"))
4847
# TODO: memory snapshot here
@@ -51,7 +50,7 @@ def start_command(port: int | None, detached: bool = False, skip_build: bool = F
5150
raise click.Abort()
5251

5352

54-
def _handle_existing_container(repo_config: RepoConfig, container: DockerContainer, force: bool) -> None:
53+
def _handle_existing_container(repo_config: RepoConfig, container: DockerContainer) -> None:
5554
if container.is_running():
5655
rich.print(
5756
Panel(
@@ -70,34 +69,48 @@ def _handle_existing_container(repo_config: RepoConfig, container: DockerContain
7069
click.Abort()
7170

7271

73-
def _build_docker_image(codegen_root: Path) -> None:
74-
platform = _get_platform()
75-
dockerfile_path = Path(__file__).parent / "Dockerfile-runner"
72+
def _build_docker_image(codegen_root: Path, codegen_version: str) -> None:
73+
build_type = _get_build_type(codegen_version)
7674
build_cmd = [
7775
"docker",
7876
"buildx",
7977
"build",
8078
"--platform",
81-
platform,
79+
_get_platform(),
8280
"-f",
83-
str(dockerfile_path),
81+
str(Path(__file__).parent / "Dockerfile"),
8482
"-t",
8583
"codegen-runner",
84+
"--build-arg",
85+
f"CODEGEN_VERSION={codegen_version}",
86+
"--build-arg",
87+
f"BUILD_TYPE={build_type}",
8688
"--load",
87-
str(codegen_root),
8889
]
90+
91+
# Only add the context path if we're doing a local build
92+
if build_type == "dev":
93+
build_cmd.append(str(codegen_root))
94+
else:
95+
build_cmd.append(".") # Minimal context when installing from PyPI
96+
8997
rich.print(
9098
Panel(
9199
f"{str.join(' ', build_cmd)}",
92100
box=ROUNDED,
93-
title="Running Build Command",
101+
title=f"Running Build Command ({build_type})",
94102
style="blue",
95103
padding=(1, 1),
96104
)
97105
)
98106
subprocess.run(build_cmd, check=True)
99107

100108

109+
def _get_build_type(version: str) -> str:
110+
"""Get the build type based on the version string."""
111+
return "dev" if "dev" in version or "+" in version else "release"
112+
113+
101114
def _get_platform() -> str:
102115
machine = py_platform.machine().lower()
103116
if machine in ("x86_64", "amd64"):

0 commit comments

Comments
 (0)