Skip to content

Commit

Permalink
Fixes for CLI -b, -p flags and jinja template for noninteractive …
Browse files Browse the repository at this point in the history
…mode builds
  • Loading branch information
spillai committed Oct 23, 2023
1 parent 873bfec commit cdd52ba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

- 😇 **Simplicity**: Make it easy to define and build docker images for ML.
- 📦 **Best-practices**: Bring best-practices to building docker images for ML -- good base images, multi-stage builds, minimal image sizes, etc.
- ⚡️ **Fast**: Make it lightning-fast to build and re-build docker images with out-of-the-box caching for apt, conda and pip packages.
- 🧩 **Modular, Re-usable, Composable**: Define `base`, `dev` and `prod` targets with multi-stage builds, and re-use them wherever possible.
- 👩‍💻 **Extensible**: Make the YAML / DSL easily hackable and extensible to support the ML ecosystem, as more libraries, drivers, HW vendors, come into the market.
- ☁️ **Vendor-agnostic**: `agi-pack` is not intended to be built for any specific vendor -- I need this tool for internal purposes, but I decided to build it in the open and keep it simple.
Expand Down
17 changes: 9 additions & 8 deletions agipack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def generate(
base_image: str = typer.Option(
None, "--base", "-b", help="Base image to use for the root/base target.", show_default=False
),
tag: str = typer.Option("agipack:{target}", "--tag", "-t", help="Image tag f-string.", show_default=True),
prod: bool = typer.Option(False, "--prod", "-p", help="Generate a production Dockerfile.", show_default=False),
lint: bool = typer.Option(False, "--lint", "-l", help="Lint the generated Dockerfile.", show_default=False),
build: bool = typer.Option(False, "--build", "-b", help="Build the Docker image after generating the Dockerfile."),
tag: str = typer.Option("{name}:{target}", "--tag", "-t", help="Image tag f-string.", show_default=True),
prod: bool = typer.Option(False, "--prod", help="Generate a production Dockerfile.", show_default=False),
lint: bool = typer.Option(False, "--lint", help="Lint the generated Dockerfile.", show_default=False),
build: bool = typer.Option(False, "--build", help="Build the Docker image after generating the Dockerfile."),
):
"""Generate the Dockerfile with optional overrides.
Expand Down Expand Up @@ -87,7 +87,7 @@ def generate(
image_config = config.images[target]

# Build the Dockerfile using the generated filename and target
tag_name = f"{image_config.name}:{target}" if tag is None else tag.format(target=target)
tag_name = f"{image_config.name}:{target}" if tag is None else tag.format(name=image_config.name, target=target)
cmd = f"docker build -f {filename} --target {target} -t {tag_name} ."
tree = Tree(f"📦 [bold white]{target}[/bold white]")
tree.add(
Expand Down Expand Up @@ -120,9 +120,9 @@ def build(
base_image: str = typer.Option(
None, "--base", "-b", help="Base image to use for the root/base target.", show_default=False
),
tag: str = typer.Option("agipack:{target}", "--tag", "-t", help="Image tag f-string.", show_default=True),
prod: bool = typer.Option(False, "--prod", "-p", help="Generate a production Dockerfile.", show_default=False),
lint: bool = typer.Option(False, "--lint", "-l", help="Lint the generated Dockerfile.", show_default=False),
tag: str = typer.Option("{name}:{target}", "--tag", "-t", help="Image tag f-string.", show_default=True),
prod: bool = typer.Option(False, "--prod", help="Generate a production Dockerfile.", show_default=False),
lint: bool = typer.Option(False, "--lint", help="Lint the generated Dockerfile.", show_default=False),
):
"""Generate the Dockerfile with optional overrides.
Expand All @@ -132,6 +132,7 @@ def build(
agi-pack build -c agibuild.yaml -p 3.8.10
agi-pack build -c agibuild.yaml -b python:3.8.10-slim
agi-pack build -c agibuild.yaml -t "my-image-name:{target}"
agi-pack build -c agibuild.yaml -t "my-image-name:my-target"
agi-pack build -c agibuild.yaml --prod --lint
"""
generate(config_filename, filename, python, base_image, tag, prod, lint, build=True)
Expand Down
4 changes: 3 additions & 1 deletion agipack/templates/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ENV AGIPACK_PROJECT {{ name }}
ENV AGIPACK_PYENV {{ name }}-{{ python_alias }}
ENV AGIPACK_PATH /opt/agi-pack

ENV DEBIAN_FRONTEND="noninteractive"
ENV PYTHON_VERSION {{ python }}
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
Expand Down Expand Up @@ -178,7 +179,8 @@ RUN apt-get -y autoclean \

# Setup environment variables
{% for key, value in env.items() -%}
ENV {{ key }}={{ value }} {% endfor %}
ENV {{ key }}={{ value }}
{% endfor %}

{%- endif %}

Expand Down
2 changes: 1 addition & 1 deletion agipack/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.15"
__version__ = "0.1.16"

0 comments on commit cdd52ba

Please sign in to comment.