Skip to content

Commit

Permalink
Add AGIPACK_VERSION and other AGIPACK_* env vars for traceability
Browse files Browse the repository at this point in the history
  • Loading branch information
spillai committed Oct 9, 2023
1 parent c1c44b2 commit cd37294
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions agipack/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from agipack.config import AGIPackConfig, ImageConfig
from agipack.constants import AGIPACK_DOCKERFILE_TEMPLATE, AGIPACK_TEMPLATE_DIR
from agipack.version import __version__

logging_level = os.environ.get("AGIPACK_LOGGING_LEVEL", "WARNING")
logging.basicConfig(level=logging.getLevelName(logging_level))
Expand Down Expand Up @@ -78,6 +79,7 @@ def _render_one(self, target: str, image_config: ImageConfig) -> str:
image_dict["target"] = target
image_dict["is_prod"] = self.config.is_prod()
image_dict["is_base_image"] = self.config.is_root(target)
image_dict["agipack_version"] = __version__
content = template.render(image_dict)

# Write the Dockerfile to the specified output filename
Expand Down
24 changes: 14 additions & 10 deletions agipack/templates/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ FROM {{ base }} AS {{ target }}
{%- if is_base_image %}

# Setup environment variables
ENV PROJECT {{ name }}
ENV PYENV {{ name }}-{{ python_alias }}
ENV AGIPACK_PROJECT {{ name }}
ENV AGIPACK_PYENV {{ name }}-{{ python_alias }}
ENV AGIPACK_VERSION {{ agipack_version }}
ENV AGIPACK_PATH /opt/agi-pack

ENV PYTHON_VERSION {{ python }}
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONWARNINGS ignore

# Setup conda paths
ENV CONDA_PATH=/opt/conda/envs/${PYENV}
ENV CONDA_PATH=/opt/conda/envs/${AGIPACK_PYENV}
ENV CONDA_PREFIX=${CONDA_PATH}
ENV CONDA_EXE=${CONDA_PATH}/bin/conda
ENV PATH=${CONDA_PATH}/bin:/opt/conda/bin:$PATH
ENV CONDA_DEFAULT_ENV ${PYENV}
ENV CONDA_DEFAULT_ENV ${AGIPACK_PYENV}

{%- endif %}


Expand Down Expand Up @@ -60,7 +64,7 @@ RUN curl -sLo ~/mambaforge.sh "https://github.com/conda-forge/miniforge/releases
&& ~/mambaforge.sh -b -p /opt/conda \
&& /opt/conda/bin/mamba init bash \
&& /opt/conda/bin/mamba config --set pip_interop_enabled True \
&& /opt/conda/bin/mamba create -n ${PYENV} python=${PYTHON_VERSION} -y \
&& /opt/conda/bin/mamba create -n ${AGIPACK_PYENV} python=${PYTHON_VERSION} -y \
&& rm ~/mambaforge.sh

{%- endif %}
Expand Down Expand Up @@ -117,16 +121,16 @@ RUN --mount=type=cache,target=~/.cache/pip \
{%- if is_base_image %}

# Export conda environment on login
RUN echo "export CONDA_PATH=/opt/conda/envs/${PYENV}" >> ~/.bashrc
RUN echo "export PATH=/opt/conda/envs/${PYENV}/bin:$PATH" >> ~/.bashrc
RUN echo "export CONDA_DEFAULT_ENV=${PYENV}" >> ~/.bashrc
RUN echo "mamba activate ${PYENV}" > ~/.bashrc
RUN echo "export CONDA_PATH=/opt/conda/envs/${AGIPACK_PYENV}" >> ~/.bashrc
RUN echo "export PATH=/opt/conda/envs/${AGIPACK_PYENV}/bin:$PATH" >> ~/.bashrc
RUN echo "export CONDA_DEFAULT_ENV=${AGIPACK_PYENV}" >> ~/.bashrc
RUN echo "mamba activate ${AGIPACK_PYENV}" > ~/.bashrc
ENTRYPOINT ["/bin/bash", "-c"]

{%- endif %}

# Setup working directory
WORKDIR /app/$PYENV
WORKDIR /app/$AGIPACK_PYENV

{%- if run|length > 0 %}

Expand Down
1 change: 1 addition & 0 deletions agipack/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.4"
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build-backend = "setuptools.build_meta"

[project]
name = "agi-pack"
version = "0.1.3"
description = "Dockerfile generator for AGI -- nothing more, nothing less."
license = {file = "LICENSE"}
readme = "README.md"
Expand All @@ -26,6 +25,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",

]
dynamic = ["version"]
dependencies = [
"jinja2",
"pydantic",
Expand All @@ -45,6 +45,9 @@ dev = [
"Source Code" = "https://github.com/spillai/agi-pack"
"Homepage" = "https://spillai.github.io/agi-pack/"

[tool.setuptools.dynamic]
version = {attr = "agipack.version.__version__"}

[project.scripts]
agi-pack = "agipack.cli:app"

Expand Down

0 comments on commit cd37294

Please sign in to comment.