Skip to content

Commit

Permalink
feat: add cas server dockerfile (#757)
Browse files Browse the repository at this point in the history
* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* feat: add cas server dockerfile

* fix: absolute path in hub image
  • Loading branch information
hanxiao committed Jun 19, 2022
1 parent 7c2faae commit 03541dd
Show file tree
Hide file tree
Showing 29 changed files with 367 additions and 136 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/cd.yml
Expand Up @@ -134,6 +134,13 @@ jobs:
token: ${{ secrets.JINA_DEV_BOT }}
env:
release_token: ${{ secrets.CAS_RELEASE_TOKEN }}
- uses: benc-uk/workflow-dispatch@v1
with:
workflow: Manual CAS Docker Build
inputs: '{ "release_token": "${{ env.release_token }}", "triggered_by": "CD"}'
token: ${{ secrets.JINA_DEV_BOT }}
env:
release_token: ${{ secrets.CAS_RELEASE_TOKEN }}
- name: Pre-release hub (.devN)
uses: benc-uk/workflow-dispatch@v1
with:
Expand Down
146 changes: 146 additions & 0 deletions .github/workflows/force-docker-build-cas.yml
@@ -0,0 +1,146 @@
name: Manual CAS Docker Build

on:
workflow_dispatch:
inputs:
release_token:
description: 'Your release token'
required: true
triggered_by:
description: 'CD | TAG | MANUAL'
required: false
default: MANUAL

jobs:
token-check:
runs-on: ubuntu-latest
steps:
- run: echo "success!"
if: "${{ github.event.inputs.release_token }} == ${{ env.release_token }}"
env:
release_token: ${{ secrets.CAS_RELEASE_TOKEN }}

regular-release:
needs: token-check
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pip_tag: [ "", "onnx", "tensorrt"] # default: "" = core
steps:
- uses: actions/checkout@v2
- name: Set envs and versions
run: |
VCS_REF=${{ github.ref }}
echo "VCS_REF=$VCS_REF" >> $GITHUB_ENV
echo "Will build $VCS_REF"
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
if [[ "${{ matrix.pip_tag }}" == "perf" ]]; then
echo "JINA_PIP_INSTALL_PERF=1" >> $GITHUB_ENV
fi
if [[ "${{ matrix.pip_tag }}" == "" ]]; then
echo "JINA_PIP_INSTALL_CORE=1" >> $GITHUB_ENV
fi
JINA_VERSION=$(sed -n '/^__version__/p' ./server/clip_server/__init__.py | cut -d \' -f2)
V_JINA_VERSION=v${JINA_VERSION}
JINA_MINOR_VERSION=${JINA_VERSION%.*}
JINA_MAJOR_VERSION=${JINA_MINOR_VERSION%.*}
PY_TAG=${{matrix.py_version}}
if [ -n "${PY_TAG}" ]; then
PY_TAG=-py${PY_TAG//./}
fi
PIP_TAG=${{ matrix.pip_tag }}
if [ -n "${PIP_TAG}" ]; then
PIP_TAG=-${PIP_TAG}
fi
if [[ "${{ github.event.inputs.triggered_by }}" == "CD" ]]; then
if [[ "${{ matrix.py_version }}" == "$DEFAULT_PY_VERSION" ]]; then
echo "TAG_ALIAS=\
jinaai/clip-as-service:master${PY_TAG}${PIP_TAG}, \
jinaai/clip-as-service:master${PIP_TAG}" \
>> $GITHUB_ENV
else
# on every CD
echo "TAG_ALIAS=\
jinaai/clip-as-service:master${PY_TAG}${PIP_TAG}" \
>> $GITHUB_ENV
fi
elif [[ "${{ github.event.inputs.triggered_by }}" == "TAG" ]]; then
# on every tag release
if [[ "${{ matrix.py_version }}" == "$DEFAULT_PY_VERSION" ]]; then
echo "TAG_ALIAS=\
jinaai/clip-as-service:latest${PY_TAG}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_VERSION}${PY_TAG}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_MINOR_VERSION}${PY_TAG}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_MAJOR_VERSION}${PY_TAG}${PIP_TAG}, \
jinaai/clip-as-service:latest${PIP_TAG}, \
jinaai/clip-as-service:${JINA_VERSION}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_MINOR_VERSION}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_MAJOR_VERSION}${PIP_TAG} \
" >> $GITHUB_ENV
else
echo "TAG_ALIAS=\
jinaai/clip-as-service:latest${PY_TAG}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_VERSION}${PY_TAG}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_MINOR_VERSION}${PY_TAG}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_MAJOR_VERSION}${PY_TAG}${PIP_TAG} \
" >> $GITHUB_ENV
fi
elif [[ "${{ github.event.inputs.triggered_by }}" == "MANUAL" ]]; then
# on every manual release
if [[ "${{ matrix.py_version }}" == "$DEFAULT_PY_VERSION" ]]; then
echo "TAG_ALIAS=\
jinaai/clip-as-service:${JINA_VERSION}${PIP_TAG}, \
jinaai/clip-as-service:${JINA_VERSION}${PY_TAG}${PIP_TAG} \
" >> $GITHUB_ENV
else
echo "TAG_ALIAS=\
jinaai/clip-as-service:${JINA_VERSION}${PY_TAG}${PIP_TAG} \
" >> $GITHUB_ENV
fi
else
echo "Bad triggered_by: ${{ github.event.inputs.triggered_by }}!"
exit 1
fi
echo "JINA_VERSION=${JINA_VERSION}" >> $GITHUB_ENV
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
install: true
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_DEVBOT_USER }}
password: ${{ secrets.DOCKERHUB_DEVBOT_TOKEN }}
- run: |
# https://github.com/docker/buildx/issues/464#issuecomment-741507760
# https://github.com/kubernetes-sigs/azuredisk-csi-driver/pull/808/files
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-aarch64
docker run --rm --privileged tonistiigi/binfmt --install all
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfiles/server.Dockerfile
platforms: linux/amd64
push: true
tags: ${{env.TAG_ALIAS}}
build-args: |
BUILD_DATE=${{env.BUILD_DATE}}
JINA_VERSION=${{env.JINA_VERSION}}
VCS_REF=${{env.VCS_REF}}
PIP_INSTALL_CORE=${{env.JINA_PIP_INSTALL_CORE}}
PIP_INSTALL_PERF=${{env.JINA_PIP_INSTALL_PERF}}
PIP_TAG=${{matrix.pip_tag}}
7 changes: 7 additions & 0 deletions .github/workflows/force-release.yml
Expand Up @@ -52,6 +52,13 @@ jobs:
needs: token-check
runs-on: ubuntu-latest
steps:
- uses: benc-uk/workflow-dispatch@v1
with:
workflow: Manual CAS Docker Build
inputs: '{ "release_token": "${{ env.release_token }}", "triggered_by": "CD"}'
token: ${{ secrets.JINA_DEV_BOT }}
env:
release_token: ${{ secrets.CAS_RELEASE_TOKEN }}
- name: Build and push docker
uses: benc-uk/workflow-dispatch@v1
with:
Expand Down
20 changes: 10 additions & 10 deletions Dockerfiles/base.Dockerfile
Expand Up @@ -8,7 +8,7 @@ ARG BACKEND_TAG=torch
# constant, wont invalidate cache
LABEL org.opencontainers.image.vendor="Jina AI Limited" \
org.opencontainers.image.licenses="Apache 2.0" \
org.opencontainers.image.title="Clip-As-Service" \
org.opencontainers.image.title="CLIP-as-Service" \
org.opencontainers.image.description="Embed images and sentences into fixed-length vectors with CLIP" \
org.opencontainers.image.authors="hello@jina.ai" \
org.opencontainers.image.url="clip-as-service" \
Expand All @@ -17,20 +17,20 @@ LABEL org.opencontainers.image.vendor="Jina AI Limited" \
RUN pip3 install --no-cache-dir torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu

# copy will almost always invalid the cache
COPY . /clip_server/
COPY . /cas/

RUN echo "\
WORKDIR /cas

RUN if [ "${BACKEND_TAG}" != "torch" ]; then python3 -m pip install --no-cache-dir "./[${BACKEND_TAG}]" ; fi \
&& python3 -m pip install --no-cache-dir .

RUN CLIP_PATH=$(python -c "import clip_server;print(clip_server.__path__[0])") \
&& echo "\
jtype: CLIPEncoder\n\
metas:\n\
py_modules:\n\
- clip_server/executors/clip_$BACKEND_TAG.py\n\
- $CLIP_PATH/executors/clip_$BACKEND_TAG.py\n\
" > /tmp/config.yml

RUN cd /clip_server && \
if [ "$BACKEND_TAG" != "torch" ]; then pip3 install --no-cache-dir "./[$BACKEND_TAG]" ; fi && \
pip3 install --no-cache-dir .

WORKDIR /clip_server


ENTRYPOINT ["jina", "executor", "--uses", "/tmp/config.yml"]
24 changes: 15 additions & 9 deletions Dockerfiles/cuda.Dockerfile
Expand Up @@ -6,18 +6,29 @@ ENV DEBIAN_FRONTEND=noninteractive
ARG JINA_VERSION=3.6.0
ARG BACKEND_TAG=torch

# constant, wont invalidate cache
LABEL org.opencontainers.image.vendor="Jina AI Limited" \
org.opencontainers.image.licenses="Apache 2.0" \
org.opencontainers.image.title="CLIP-as-Service" \
org.opencontainers.image.description="Embed images and sentences into fixed-length vectors with CLIP" \
org.opencontainers.image.authors="hello@jina.ai" \
org.opencontainers.image.url="clip-as-service" \
org.opencontainers.image.documentation="https://clip-as-service.jina.ai/"

RUN apt-get update && apt-get install -y --no-install-recommends \
python3-setuptools python3-wheel python3-pip \
&& apt-get clean && rm -rf /var/lib/apt/lists/*;

RUN python3 -m pip install --default-timeout=1000 --no-cache-dir torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
RUN python3 -m pip install --default-timeout=1000 --no-cache-dir torch torchvision torchaudio nvidia-pyindex --extra-index-url https://download.pytorch.org/whl/cu113
RUN python3 -m pip install --default-timeout=1000 --no-cache-dir "jina[standard]==${JINA_VERSION}"

RUN python3 -m pip install nvidia-pyindex

# copy will almost always invalid the cache
COPY . /clip_server/
COPY . /cas/

WORKDIR /cas

RUN if [ "${BACKEND_TAG}" != "torch" ]; then python3 -m pip install --no-cache-dir "./[${BACKEND_TAG}]" ; fi \
&& python3 -m pip install --no-cache-dir .

RUN echo "\
jtype: CLIPEncoder\n\
Expand All @@ -28,11 +39,6 @@ metas:\n\
- clip_server/executors/clip_$BACKEND_TAG.py\n\
" > /tmp/config.yml

RUN cd /clip_server && \
if [ "${BACKEND_TAG}" != "torch" ]; then python3 -m pip install --no-cache-dir "./[${BACKEND_TAG}]" ; fi && \
python3 -m pip install --no-cache-dir .

WORKDIR /clip_server

ENTRYPOINT ["jina", "executor", "--uses", "/tmp/config.yml"]

Expand Down
50 changes: 50 additions & 0 deletions Dockerfiles/server.Dockerfile
@@ -0,0 +1,50 @@
ARG CUDA_VERSION=11.6.0

FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu20.04

ARG CAS_NAME=cas
WORKDIR /${CAS_NAME}

ENV PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1

# constant, wont invalidate cache
LABEL org.opencontainers.image.vendor="Jina AI Limited" \
org.opencontainers.image.licenses="Apache 2.0" \
org.opencontainers.image.title="CLIP-as-Service" \
org.opencontainers.image.description="Embed images and sentences into fixed-length vectors with CLIP" \
org.opencontainers.image.authors="hello@jina.ai" \
org.opencontainers.image.url="clip-as-service" \
org.opencontainers.image.documentation="https://clip-as-service.jina.ai/"


RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 python3-pip wget \
&& ln -sf python3 /usr/bin/python \
&& ln -sf pip3 /usr/bin/pip \
&& pip install --upgrade pip \
&& pip install wheel setuptools nvidia-pyindex \
&& pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113

COPY server ./server
# given by builder
ARG PIP_TAG
RUN pip install --default-timeout=1000 --compile ./server/ \
&& if [ -n "${PIP_TAG}" ]; then pip install --default-timeout=1000 --compile "./server[${PIP_TAG}]" ; fi

ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64

ARG USER_ID=1000
ARG GROUP_ID=1000
ARG USER_NAME=${CAS_NAME}
ARG GROUP_NAME=${CAS_NAME}

RUN groupadd -g ${GROUP_ID} ${USER_NAME} &&\
useradd -l -u ${USER_ID} -g ${USER_NAME} ${GROUP_NAME} &&\
mkdir /home/${USER_NAME} &&\
chown ${USER_NAME}:${GROUP_NAME} /home/${USER_NAME} &&\
chown -R ${USER_NAME}:${GROUP_NAME} /${CAS_NAME}/

USER ${USER_NAME}

ENTRYPOINT ["python", "-m", "clip_server"]
21 changes: 16 additions & 5 deletions Dockerfiles/tensorrt.Dockerfile
Expand Up @@ -7,22 +7,33 @@ FROM nvcr.io/nvidia/tensorrt:${TENSORRT_VERSION}-py3
ARG JINA_VERSION=3.6.0
ARG BACKEND_TAG=tensorrt

# constant, wont invalidate cache
LABEL org.opencontainers.image.vendor="Jina AI Limited" \
org.opencontainers.image.licenses="Apache 2.0" \
org.opencontainers.image.title="CLIP-as-Service" \
org.opencontainers.image.description="Embed images and sentences into fixed-length vectors with CLIP" \
org.opencontainers.image.authors="hello@jina.ai" \
org.opencontainers.image.url="clip-as-service" \
org.opencontainers.image.documentation="https://clip-as-service.jina.ai/"

RUN pip3 install --default-timeout=1000 --no-cache-dir torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
RUN pip3 -m pip install --default-timeout=1000 --no-cache-dir "jina[standard]==${JINA_VERSION}"

# copy will almost always invalid the cache
COPY . /clip_server/
COPY . /cas/
WORKDIR /cas

RUN python3 -m pip install --no-cache-dir "./[$BACKEND_TAG]"

RUN echo '\
RUN CLIP_PATH=$(python -c "import clip_server;print(clip_server.__path__[0])") \
&& echo '\
jtype: CLIPEncoder\n\
metas:\n\
py_modules:\n\
- clip_server/executors/clip_$BACKEND_TAG.py\n\
- $CLIP_PATH/executors/clip_$BACKEND_TAG.py\n\
' > /tmp/config.yml

RUN cd /clip_server/ && python3 -m pip install --no-cache-dir "./[$BACKEND_TAG]"

WORKDIR /clip_server

ENTRYPOINT ["jina", "executor", "--uses", "/tmp/config.yml"]

4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -13,7 +13,7 @@
<a href="https://pypi.org/project/clip_server/"><img alt="PyPI" src="https://img.shields.io/pypi/v/clip_server?label=PyPI&logo=pypi&logoColor=white&style=flat-square"></a>
<a href="https://slack.jina.ai"><img src="https://img.shields.io/badge/Slack-3.1k-blueviolet?logo=slack&amp;logoColor=white&style=flat-square"></a>
<a href="https://codecov.io/gh/jina-ai/clip-as-service"><img alt="Codecov branch" src="https://img.shields.io/codecov/c/github/jina-ai/clip-as-service/main?logo=Codecov&logoColor=white&style=flat-square"></a>
<a href="https://colab.research.google.com/github/jina-ai/clip-as-service/blob/main/docs/playground/cas-on-colab.ipynb"><img src="https://img.shields.io/badge/Host-on%20Google%20Colab%20(GPU/TPU)-yellow?style=flat-square&logo=googlecolab&&logoColor=white" alt="Host on Google Colab with GPU/TPU support"></a>
<a href="https://colab.research.google.com/github/jina-ai/clip-as-service/blob/main/docs/hosting/cas-on-colab.ipynb"><img src="https://img.shields.io/badge/Host-on%20Google%20Colab%20(GPU/TPU)-yellow?style=flat-square&logo=googlecolab&&logoColor=white" alt="Host on Google Colab with GPU/TPU support"></a>
</p>

<!-- start elevator-pitch -->
Expand Down Expand Up @@ -240,7 +240,7 @@ pip install "clip-server[tensorrt]"
</tr>
</table>

You can also [host the server on Google Colab](https://clip-as-service.jina.ai/playground/colab/), leveraging its free GPU/TPU.
You can also [host the server on Google Colab](https://clip-as-service.jina.ai/hosting/colab/), leveraging its free GPU/TPU.

### Install client

Expand Down
4 changes: 2 additions & 2 deletions client/clip_client/__init__.py
Expand Up @@ -2,9 +2,9 @@

import os

from .client import Client
from clip_client.client import Client

if 'NO_VERSION_CHECK' not in os.environ:
from .helper import is_latest_version
from clip_server.helper import is_latest_version

is_latest_version(github_repo='clip-as-service')
File renamed without changes.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion docs/playground/colab.md → docs/hosting/colab.md
Expand Up @@ -19,7 +19,7 @@ Specifically, the architecture is illustrated below:
:width: 70%
```

```{button-link} https://colab.research.google.com/github/jina-ai/clip-as-service/blob/main/docs/playground/cas-on-colab.ipynb
```{button-link} https://colab.research.google.com/github/jina-ai/clip-as-service/blob/main/docs/hosting/cas-on-colab.ipynb
:color: primary
:align: center

Expand Down
File renamed without changes

0 comments on commit 03541dd

Please sign in to comment.