Skip to content

Commit

Permalink
Docker Finalization (#985)
Browse files Browse the repository at this point in the history
* Update deepsparse docker infra which includes:
- Updated names for docker images
- Updated triggers and tags
- Support for nightlies

* Update echo message in GHA
  • Loading branch information
rahul-tuli authored and bfineran committed May 8, 2023
1 parent a007ccc commit bf2fd7a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 103 deletions.
65 changes: 7 additions & 58 deletions .github/workflows/build-and-publish-tagged-images.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Build and Publish
name: Build and Publish Docker Images

on:
create
release:
types: [published]

jobs:
build-and-push-docker-image:
Expand All @@ -12,9 +13,6 @@ jobs:
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
if: ${{ contains(github.ref, 'refs/heads/release/') }}
id: buildx
Expand Down Expand Up @@ -45,7 +43,7 @@ jobs:
run: |
echo ${{ steps.extract_tag.outputs.tag }}
- name: Build and push deepsparse-all
- name: Build and push deepsparse with all dependencies
if: ${{ contains(github.ref, 'refs/heads/release/') }}
uses: docker/build-push-action@v2
with:
Expand All @@ -55,69 +53,20 @@ jobs:
VERSION=${{ steps.extract_tag.outputs.tag }}
push: true
tags: |
ghcr.io/neuralmagic/deepsparse-all:${{ steps.extract_tag.outputs.tag }}
- name: Build and push deepsparse-server
if: ${{ contains(github.ref, 'refs/heads/release/') }}
uses: docker/build-push-action@v2
with:
context: ./docker
build-args: |
DEPS=server
VERSION=${{ steps.extract_tag.outputs.tag }}
push: true
tags: |
ghcr.io/neuralmagic/deepsparse-server:${{ steps.extract_tag.outputs.tag }}
- name: Build and push deepsparse-transformers
if: ${{ contains(github.ref, 'refs/heads/release/') }}
uses: docker/build-push-action@v2
with:
context: ./docker
build-args: |
DEPS=transformers
VERSION=${{ steps.extract_tag.outputs.tag }}
tags: |
ghcr.io/neuralmagic/deepsparse-transformers:${{ steps.extract_tag.outputs.tag }}
- name: Build and push deepsparse-torchvision
if: ${{ contains(github.ref, 'refs/heads/release/') }}
uses: docker/build-push-action@v2
with:
context: ./docker
push: true
build-args: |
DEPS=torchvision
VERSION=${{ steps.extract_tag.outputs.tag }}
tags: |
ghcr.io/neuralmagic/deepsparse-torchvision:${{ steps.extract_tag.outputs.tag }}
- name: Build and push deepsparse-ultralytics
if: ${{ contains(github.ref, 'refs/heads/release/') }}
uses: docker/build-push-action@v2
with:
context: ./docker
push: true
build-args: |
DEPS=ultralytics
VERSION=${{ steps.extract_tag.outputs.tag }}
tags: |
ghcr.io/neuralmagic/deepsparse-ultralytics:${{ steps.extract_tag.outputs.tag }}
ghcr.io/neuralmagic/deepsparse:${{ steps.extract_tag.outputs.tag }}
- name: Build and push deepsparse-base
if: ${{ contains(github.ref, 'refs/heads/release/') }}
uses: docker/build-push-action@v2
with:
context: ./docker
push: true
build-args: |
DEPS=base
VERSION=${{ steps.extract_tag.outputs.tag }}
push: true
tags: |
ghcr.io/neuralmagic/deepsparse-base:${{ steps.extract_tag.outputs.tag }}
- name: Image digest
if: ${{ contains(github.ref, 'refs/heads/release/') }}
Expand Down
120 changes: 75 additions & 45 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ ARG BRANCH
FROM python:3.8.16-slim-bullseye@sha256:322e38e3056cf87280ad80be615a6282aae768090f30d43d99abe413e1dd081a AS base
ARG VENV

# metainformation
LABEL org.opencontainers.image.version = "1.4"
LABEL org.opencontainers.image.authors = "Neuralmagic, Inc."
LABEL org.opencontainers.image.source = "https://github.com/neuralmagic/sparseml"
LABEL org.opencontainers.image.licenses = "Apache License 2.0"

RUN set -Eeuxo \
&& apt-get update \
&& apt-get install ffmpeg libsm6 libxext6 -y \
Expand All @@ -22,70 +16,106 @@ RUN set -Eeuxo \
&& $VENV/bin/pip install --no-cache-dir --upgrade pip setuptools wheel

RUN \
if [ -z "${VERSION}" ] ; then \
echo VERSION not provided && \
if [ -z "${BRANCH}" ]; then \
git clone https://github.com/neuralmagic/deepsparse.git --depth 1 -b main; \
else clone https://github.com/neuralmagic/deepsparse.git --depth 1 -b $BRANCH; \
fi; \
else echo VERSION is $VERSION && \
git clone https://github.com/neuralmagic/deepsparse.git --depth 1 -b release/${VERSION}; \
fi;



FROM base AS container_branch_all
ARG VENV
ENV PATH="${VENV}/bin:$PATH"
ENV PIP_DEFAULT_TIMEOUT=200
ARG DEEPSPARSE_INSTALLABLE=./deepsparse[server,yolo,onnxruntime,yolov8]
RUN $VENV/bin/pip install --no-cache-dir "${DEEPSPARSE_INSTALLABLE}"
if [ -z "${BRANCH}"] ; then \
echo Will install from pypi based on mode and version ; \
else \
echo cloning from "${BRANCH}" && \
git clone https://github.com/neuralmagic/deepsparse.git --depth 1 -b "${BRANCH}" ; \
fi;

RUN deepsparse.transformers.run_inference --help \
&& deepsparse.image_classification.annotate --help


FROM base AS container_branch_server
FROM base AS container_branch_base
ARG VENV
ENV PATH="${VENV}/bin:$PATH"
ENV PIP_DEFAULT_TIMEOUT=200
ARG DEEPSPARSE_INSTALLABLE=./deepsparse[server]
RUN $VENV/bin/pip install --no-cache-dir "${DEEPSPARSE_INSTALLABLE}"

FROM container_branch_server AS container_branch_transformers
RUN deepsparse.transformers.run_inference --help
ARG VERSION
ARG MODE=""
RUN \
if [ -n "$BRANCH" ] ; then \
echo Installing from BRANCH && \
$VENV/bin/pip install --no-cache-dir "./deepsparse[server]"; \
elif [ "$MODE" = "nightly" ] ; then \
echo Installing nightlies ... && \
if [ -z "$VERSION" ] ; then \
echo Installing latest nightlies ... && \
$VENV/bin/pip install --no-cache-dir "deepsparse-nightly[server]"; \
else \
echo Installing nightlies ... with $VERSION && \
$VENV/bin/pip install --no-cache-dir "deepsparse-nightly[server]==$VERSION"; \
fi; \
elif [ -z "$VERSION" ] ; then \
echo Installing latest deepsparse ... from pypi && \
$VENV/bin/pip install --no-cache-dir "deepsparse[server]"; \
else \
echo Installing latest deepsparse version="$VERSION" from pypi && \
$VENV/bin/pip install --no-cache-dir "deepsparse[server]==$VERSION"; \
fi;


FROM container_branch_server AS container_branch_torchvision
RUN deepsparse.image_classification.annotate --help


FROM base AS container_branch_ultralytics
FROM base AS container_branch_all
ARG VENV
ENV PATH="${VENV}/bin:$PATH"
ENV PIP_DEFAULT_TIMEOUT=200
ARG DEEPSPARSE_INSTALLABLE=./deepsparse[server,yolo,yolov8]
RUN $VENV/bin/pip install --no-cache-dir "${DEEPSPARSE_INSTALLABLE}"
ARG VERSION
ARG MODE=""
RUN \
if [ -n "$BRANCH" ] ; then \
echo Installing from BRANCH && \
$VENV/bin/pip install --no-cache-dir "./deepsparse[server,yolo,onnxruntime,yolov8]"; \
elif [ "$MODE" = "nightly" ] ; then \
echo Installing nightlies ... && \
if [ -z "$VERSION" ] ; then \
echo Installing latest nightlies ... && \
$VENV/bin/pip install --no-cache-dir "deepsparse-nightly[server,yolo,onnxruntime,yolov8]"; \
else \
echo Installing nightlies ... with $VERSION && \
$VENV/bin/pip install --no-cache-dir "deepsparse-nightly[server,yolo,onnxruntime,yolov8]==$VERSION"; \
fi; \
elif [ -z "$VERSION" ] ; then \
echo Installing latest deepsparse ... from pypi && \
$VENV/bin/pip install --no-cache-dir "deepsparse[server,yolo,onnxruntime,yolov8]"; \
else \
echo Installing latest deepsparse version="$VERSION" from pypi && \
$VENV/bin/pip install --no-cache-dir "deepsparse[server,yolo,onnxruntime,yolov8]==$VERSION"; \
fi;

RUN deepsparse.transformers.run_inference --help \
&& deepsparse.image_classification.annotate --help

FROM base AS container_branch_base
ARG VENV
ENV PATH="${VENV}/bin:$PATH"
ENV PIP_DEFAULT_TIMEOUT=200
ARG DEEPSPARSE_INSTALLABLE=./deepsparse
RUN $VENV/bin/pip install --no-cache-dir "${DEEPSPARSE_INSTALLABLE}"

FROM base AS container_branch_dev
ARG VENV
ENV PATH="${VENV}/bin:$PATH"
ENV PIP_DEFAULT_TIMEOUT=200
ARG DEEPSPARSE_INSTALLABLE=./deepsparse[dev]
RUN $VENV/bin/pip install -e "${DEEPSPARSE_INSTALLABLE}"
ARG VERSION
ARG MODE
RUN \
if [ -n "$BRANCH" ] ; then \
echo Installing from BRANCH with editable mode && \
$VENV/bin/pip install -e "./deepsparse[dev]"; \
else \
echo Installing from main with editable mode && \
git clone https://github.com/neuralmagic/sparseml.git --depth 1 -b main && \
$VENV/bin/pip install -e "./deepsparse[dev]"; \
fi;


FROM container_branch_${DEPS} AS build
RUN echo Build complete, going onto prod


FROM base as dev
ARG VENV
COPY --from=build $VENV $VENV
COPY --from=build deepsparse deepsparse
ENV PATH="${VENV}/bin:$PATH"
HEALTHCHECK CMD python -c 'import deepsparse'
ENTRYPOINT bash


FROM base as prod
ARG VENV
COPY --from=build $VENV $VENV
Expand Down

0 comments on commit bf2fd7a

Please sign in to comment.