Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move envs to bottom to avoid docker re-builds, and fix python dependency versions #3

Merged
merged 1 commit into from
Oct 18, 2023
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
6 changes: 4 additions & 2 deletions agipack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ def validate_python_dependencies_for_nonbase_images(cls, images):
for target, config in images.items():
if config.is_base_image():
version = config.python
elif config.python != version:
raise ValueError(f"Non-base image [{target}] must have the same python version as the base image")
else:
if config.python != version:
logger.debug(f"Ignoring python version for non-base image [{target}]")
config.python = version
return images

@classmethod
Expand Down
28 changes: 22 additions & 6 deletions agipack/templates/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,33 @@ ENV CONDA_DEFAULT_ENV ${AGIPACK_PYENV}
{%- endif %}


{%- if env|length > 0 %}
{%- if is_base_image %}

# Setup environment variables
{% for key, value in env.items() -%}
ENV {{ key }}={{ value }} {% endfor %}
# Install base system packages
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install \
curl bzip2 git ca-certificates \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*

{%- endif %}


# Install system packages
{%- if system|length > 0 %}

# Install additional system packages
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install \
curl bzip2 git ca-certificates \
{%- for package in system %}
{{ package }} \
{%- endfor %}
&& apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*

{%- endif %}


{%- if is_base_image %}

Expand Down Expand Up @@ -162,6 +169,15 @@ RUN echo "run commands complete"
{%- endif %}


{%- if env|length > 0 %}

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

{%- endif %}


{%- if entrypoint|length > 0 %}
ENTRYPOINT [{%- for cmd in entrypoint %}"{{ cmd }}"{% if not loop.last %}, {% endif %}{%- 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.9"
__version__ = "0.1.10"
18 changes: 12 additions & 6 deletions examples/generated/Dockerfile-base-cpu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# >>>>>>>>>>>>>>>>>>>>>>>>>>>
# Auto-generated by agi-pack (version=0.1.9).
# Auto-generated by agi-pack (version=0.1.10).
FROM debian:buster-slim AS base-cpu

# Setup environment variables
Expand All @@ -19,14 +19,17 @@ ENV CONDA_EXE=${CONDA_PATH}/bin/conda
ENV PATH=${CONDA_PATH}/bin:/opt/conda/bin:$PATH
ENV CONDA_DEFAULT_ENV ${AGIPACK_PYENV}

# Setup environment variables
ENV MY_ENV_VAR=value


# Install system packages
# Install base system packages
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install \
curl bzip2 git ca-certificates \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*

# Install additional system packages
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install \
wget \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down Expand Up @@ -82,4 +85,7 @@ RUN echo "running commands"
RUN python -c 'import cv2; print(cv2.__version__)'
RUN python -c 'import torch; print(torch.__version__)'
RUN echo "run commands complete"

# Setup environment variables
ENV MY_ENV_VAR=value
CMD ["bash"]
18 changes: 12 additions & 6 deletions examples/generated/Dockerfile-base-cu118
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# >>>>>>>>>>>>>>>>>>>>>>>>>>>
# Auto-generated by agi-pack (version=0.1.9).
# Auto-generated by agi-pack (version=0.1.10).
FROM nvidia/cuda:11.8.0-base-ubuntu22.04 AS base-gpu

# Setup environment variables
Expand All @@ -19,14 +19,17 @@ ENV CONDA_EXE=${CONDA_PATH}/bin/conda
ENV PATH=${CONDA_PATH}/bin:/opt/conda/bin:$PATH
ENV CONDA_DEFAULT_ENV ${AGIPACK_PYENV}

# Setup environment variables
ENV MY_ENV_VAR=value


# Install system packages
# Install base system packages
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install \
curl bzip2 git ca-certificates \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/*

# Install additional system packages
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install \
wget \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
Expand Down Expand Up @@ -88,4 +91,7 @@ RUN echo 'cuda: ' && python -c 'import torch; print(torch.version.cuda)'
RUN echo 'cudnn: ' && python -c 'import torch; print(torch.backends.cudnn.version())'
RUN echo 'opencv:' && python -c 'import cv2; print(cv2.__version__)'
RUN echo "run commands complete"

# Setup environment variables
ENV MY_ENV_VAR=value
CMD ["bash"]
5 changes: 2 additions & 3 deletions examples/generated/Dockerfile-builder
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# >>>>>>>>>>>>>>>>>>>>>>>>>>>
# Auto-generated by agi-pack (version=0.1.9).
# Auto-generated by agi-pack (version=0.1.10).
FROM debian:buster-slim AS agipack-builder

# Setup environment variables
Expand All @@ -19,8 +19,7 @@ ENV CONDA_EXE=${CONDA_PATH}/bin/conda
ENV PATH=${CONDA_PATH}/bin:/opt/conda/bin:$PATH
ENV CONDA_DEFAULT_ENV ${AGIPACK_PYENV}


# Install system packages
# Install base system packages
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install \
curl bzip2 git ca-certificates \
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_configs(test_data_dir):
test_data_dir / "agibuild-with-deps.yaml",
test_data_dir / "agibuild-no-system.yaml",
test_data_dir / "agibuild-no-deps.yaml",
test_data_dir / "agibuild-different-py-versions.yaml",
]
for filename in configs:
logger.info(f"Testing {filename}")
Expand All @@ -26,7 +27,6 @@ def test_configs(test_data_dir):
def test_poorly_formatted_configs(test_data_dir):
poorly_formatted_configs = [
test_data_dir / "agibuild-no-base.yaml",
test_data_dir / "agibuild-different-py-versions.yaml",
]
for filename in poorly_formatted_configs:
with pytest.raises(ValueError):
Expand Down