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

Added multi-stage exmaple yaml file and generated Dockerfile #13

Merged
merged 1 commit into from
Oct 24, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ $ agi-pack generate -c agibuild.yaml

As you can see, `agi-pack` will generate a **single** Dockerfile for each of the targets defined in the YAML file. You can then build the individual images from the same Dockerfile using docker targets: `docker build -f Dockerfile --target <target> .` where `<target>` is the name of the image target you want to build.

Here's the corresponding [`Dockerfile`](./examples/generated/Dockerfile-multistage-example) that was generated.
Here's the corresponding [`Dockerfile`](./examples/generated/Dockerfile-multistage) that was generated.


## Why the name? 🤷‍♂️
Expand Down
4 changes: 3 additions & 1 deletion agipack/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def build(self, filename: str, target: str, tags: List[str] = None, push: bool =
process.wait()

if process.returncode != 0:
raise Exception(f"Failed to build image [target={target}]")
err_msg = f"Failed to build image [target={target}, e={process.stderr}]"
logger.error(err_msg)
raise Exception(err_msg)

# Push the Docker image
if push:
Expand Down
1 change: 1 addition & 0 deletions agipack/templates/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Auto-generated by agi-pack (version={{ agipack_version }}).
{%- else %}
# >>>>>>>>>>>>>>>>>>>>>>>>>>>
# Auto-generated by agi-pack (version={{ agipack_version }}).
{%- endif %}
FROM {{ base }} AS {{ target }}

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.18"
__version__ = "0.1.19"
16 changes: 16 additions & 0 deletions examples/agibuild.multistage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
images:
base-cpu:
name: agi
base: debian:buster-slim
system:
- wget
python: "3.8.10"
pip:
- scikit-learn
run:
- echo "Hello, world!"

dev-cpu:
base: base-cpu
system:
- build-essential
103 changes: 103 additions & 0 deletions examples/generated/Dockerfile-multistage
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# >>>>>>>>>>>>>>>>>>>>>>>>>>>
# Auto-generated by agi-pack (version=0.1.18).
FROM debian:buster-slim AS base-cpu

# Setup environment variables
ENV AGIPACK_PROJECT agi
ENV AGIPACK_PYENV agi-py38
ENV AGIPACK_PATH /opt/agi-pack

ENV DEBIAN_FRONTEND="noninteractive"
ENV PYTHON_VERSION 3.8.10
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONWARNINGS ignore
ENV PIP_CACHE_DIR /var/cache/pip
ENV CONDA_PKGS_DIRS /var/cache/conda/pkgs

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

# Install base system packages
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install \
curl bzip2 git ca-certificates

# Install additional system packages
RUN --mount=type=cache,target=/var/cache/apt \
apt-get -y update \
&& apt-get -y --no-install-recommends install \
wget \
&& echo "system install complete"

# Install mambaforge, with cache mounting ${CONDA_PKGS_DIRS} for faster builds
RUN --mount=type=cache,target=${CONDA_PKGS_DIRS} \
curl -sLo ~/mambaforge.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh" \
&& chmod +x ~/mambaforge.sh \
&& ~/mambaforge.sh -b -p ${AGIPACK_PATH}/conda \
&& ${AGIPACK_PATH}/conda/bin/mamba init bash \
&& ${AGIPACK_PATH}/conda/bin/mamba config --add channels conda-forge \
&& ${AGIPACK_PATH}/conda/bin/mamba create -n ${AGIPACK_PYENV} python=${PYTHON_VERSION} -y \
&& rm ~/mambaforge.sh

# Upgrade pip
RUN pip install --upgrade pip

# Install pip packages, with cache mounting ${PIP_CACHE_DIR} for faster builds
# Note: Cache mounts allow us to re-use the cache for pip packages
# instead of having to re-download them every time we build.
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
pip install --cache-dir ${PIP_CACHE_DIR} \
"scikit-learn" \
&& echo "pip install complete"

# Export conda environment on login
RUN echo "export CONDA_PATH=${AGIPACK_PATH}/conda/envs/${AGIPACK_PYENV}" >> ~/.bashrc \
&& echo "export PATH=${AGIPACK_PATH}/conda/envs/${AGIPACK_PYENV}/bin:$PATH" >> ~/.bashrc \
&& echo "export CONDA_DEFAULT_ENV=${AGIPACK_PYENV}" >> ~/.bashrc \
&& echo "mamba activate ${AGIPACK_PYENV}" > ~/.bashrc

# Setup working directory
WORKDIR /app/$AGIPACK_PYENV

# Run commands
RUN echo "running commands"
RUN --mount=type=cache,target=${CONDA_PKGS_DIRS} \
--mount=type=cache,target=${PIP_CACHE_DIR} \
echo "Hello, world!"
RUN echo "run commands complete"
# Cleanup apt, mamba/conda and pip packages
RUN apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/* \
&& ${AGIPACK_PATH}/conda/bin/mamba clean -ya \
&& rm -rf ${PIP_CACHE_DIR} \
&& rm -rf ${CONDA_PKGS_DIRS} \
&& rm -rf /tmp/reqs \
&& echo "pip cleanup complete"
# >>>>>>>>>>>>>>>>>>>>>>>>>>>
# Auto-generated by agi-pack (version=0.1.18).
FROM base-cpu AS dev-cpu

# Install additional system packages
RUN --mount=type=cache,target=/var/cache/apt \
apt-get -y update \
&& apt-get -y --no-install-recommends install \
build-essential \
&& echo "system install complete"

# Setup working directory
WORKDIR /app/$AGIPACK_PYENV
# Cleanup apt, mamba/conda and pip packages
RUN apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/* \
&& ${AGIPACK_PATH}/conda/bin/mamba clean -ya \
&& rm -rf ${PIP_CACHE_DIR} \
&& rm -rf ${CONDA_PKGS_DIRS} \
&& rm -rf /tmp/reqs \
&& echo "pip cleanup complete"
74 changes: 0 additions & 74 deletions examples/generated/Dockerfile-multistage-example

This file was deleted.

Loading