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

build adserver dockerimage using poetry-defined environment #3783

Merged
merged 11 commits into from
Dec 8, 2021
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
37 changes: 37 additions & 0 deletions .github/workflows/alibidetect_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: AlibDetect Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
lint:
runs-on: ubuntu-18.04
container: seldonio/python-builder:0.6

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
pip install --upgrade pip setuptools
make -C components/alibi-detect-server dev_install
- name: Lint
run: |
make -C components/alibi-detect-server lint

python-tests:
runs-on: ubuntu-18.04
container: seldonio/python-builder:0.6

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
pip install --upgrade pip setuptools
apt-get -y install ffmpeg libsm6 libxext6
make -C components/alibi-detect-server dev_install
- name: Test
run: |
make -C components/alibi-detect-server test
2 changes: 2 additions & 0 deletions components/alibi-detect-server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ adserver.egg-info
.mypy_cache
.pytest_cache
.coverage
_seldon_core
version.txt
57 changes: 43 additions & 14 deletions components/alibi-detect-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,72 @@
# TODO: Add to release script
FROM docker.io/seldonio/seldon-core-s2i-python37-ubi8:1.12.0-dev
ARG VERSION
ARG BASE_IMAGE
FROM ${BASE_IMAGE}:${VERSION} as base

ARG VERSION
LABEL name="Seldon Alibi Detect Server" \
vendor="Seldon Technologies" \
version="1.12.0-dev" \
release="1" \
summary="Alibi Detect Server for Seldon Core" \
description="The Alibi Detect Server provides outlier, drift and adversarial detection services for Seldon Core"

FROM base as builder
ARG PYTHON_VERSION
ARG CONDA_VERSION

# Install Rclone Binary to be present in the image
RUN yum install -y unzip
RUN wget https://downloads.rclone.org/v1.55.1/rclone-v1.55.1-linux-amd64.zip && \
unzip rclone-v1.55.1-linux-amd64.zip && \
mv rclone-v1.55.1-linux-amd64/rclone /usr/bin/rclone && \
rm -rf rclone-v1.55.1-linux-amd64.zip rclone-v1.55.1-linux-amd64

ADD requirements_server.txt .

RUN pip install pip -U
# Install Python / Conda
RUN conda install --yes python=${PYTHON_VERSION} conda=${CONDA_VERSION}
RUN pip install pip==21.2.4 setuptools==58.1.0
RUN dnf install -y make automake gcc gcc-c++

RUN pip install -r requirements_server.txt
# Make home dir
RUN mkdir microservice
WORKDIR /microservice

# Fix cloudevents bug: https://github.com/cloudevents/sdk-python/issues/24
RUN git clone --branch 24-extensions https://github.com/ryandawsonuk/sdk-python.git && \
cd sdk-python && \
pip install -e .
# Install Poetry
ENV POETRY_HOME /microservice/.poetry
RUN curl -sSL \
https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py \
| python3

COPY adserver adserver
COPY setup.py .
ENV PATH "$POETRY_HOME/bin:$PATH"
ENV POETRY_VIRTUALENVS_CREATE false

RUN pip install -e .
# Install the server
COPY poetry.lock pyproject.toml ./
COPY _seldon_core ./_seldon_core
RUN poetry install && rm ~/.cache/pip -rf

# Add licences
RUN pip install pip-licenses
RUN mkdir /licenses
RUN mkdir ./licenses && pip-licenses --from=mixed --format=csv --output-file=./licenses/license_info.csv && \
pip-licenses --from=mixed --format=plain-vertical --with-license-file --no-license-path --output-file=./licenses/license.txt
RUN cp ./licenses/* /licenses

# Copy rest of the package
COPY adserver adserver
COPY README.md README.md
COPY version.txt version.txt

FROM base as final
WORKDIR /microservice

# this is to avoid "ImportError: libGL.so.1" from opencv
RUN yum install -y mesa-libGL
RUN mv ./licenses /licenses
RUN yum -y update-minimal --security --sec-severity=Important --sec-severity=Critical
# CVE https://github.com/SeldonIO/seldon-core/issues/2960
RUN yum remove -y nodejs httpd

COPY --from=builder /microservice /microservice
COPY --from=builder /opt/conda /opt/conda
COPY --from=builder /licenses /licenses

ENTRYPOINT ["python", "-m", "adserver"]
39 changes: 29 additions & 10 deletions components/alibi-detect-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@ VERSION := $(shell cat ../../version.txt)
REPO=seldonio
IMAGE=alibi-detect-server

.PHONY: install_dev
install_dev:
pip install -e . -r requirements-dev.txt
SELDON_CORE_DIR=../..

BASE_IMAGE ?= seldonio/conda-ubi8
PYTHON_VERSION ?= 3.7.10
CONDA_VERSION ?= 4.7.12



get_local_repo: clean
cp $(SELDON_CORE_DIR)/version.txt version.txt
cp -rT $(SELDON_CORE_DIR)/python/ _seldon_core/

clean:
rm version.txt || true
rm -rf _seldon_core || true

dev_install: get_local_repo
poetry install


.PHONY: type_check
type_check:
mypy --ignore-missing-imports adserver

.PHONY: test
test: type_check
pytest -W ignore
pytest -W ignore adserver

.PHONY: lint
lint:
Expand Down Expand Up @@ -79,17 +95,21 @@ curl-metrics-server-elasticsearch:
curl-metrics-server-metrics:
curl http://localhost:8080/v1/metrics

docker-build:
docker build -f Dockerfile -t ${REPO}/${IMAGE}:${VERSION} .

docker-build-gpu:

# image building logic

docker-build: get_local_repo
docker build -f Dockerfile --build-arg BASE_IMAGE=${BASE_IMAGE} --build-arg PYTHON_VERSION=${PYTHON_VERSION} --build-arg CONDA_VERSION=${CONDA_VERSION} --build-arg VERSION=${VERSION} -t ${REPO}/${IMAGE}:${VERSION} .

docker-build-gpu:
docker build -f Dockerfile.gpu -t ${REPO}/${IMAGE}-gpu:${VERSION} .

docker-push:
docker push ${REPO}/${IMAGE}:${VERSION}
docker push ${REPO}/${IMAGE}:${VERSION}

docker-push-gpu:
docker push ${REPO}/${IMAGE}-gpu:${VERSION}
docker push ${REPO}/${IMAGE}-gpu:${VERSION}

kind_load: docker-build
kind load docker-image ${REPO}/${IMAGE}:${VERSION}
Expand All @@ -105,4 +125,3 @@ redhat-image-scan:
echo $${rh_password_alibi_detect} | docker login -u unused scan.connect.redhat.com --password-stdin
docker tag ${REPO}/${IMAGE}:${VERSION} scan.connect.redhat.com/ospid-32ed6498-bce5-4c3b-9486-fe1c6e2582d3/${IMAGE}:${VERSION}
docker push scan.connect.redhat.com/ospid-32ed6498-bce5-4c3b-9486-fe1c6e2582d3/${IMAGE}:${VERSION}

4 changes: 2 additions & 2 deletions components/alibi-detect-server/adserver/tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from adserver.server import Protocol, CEServer, CEModel
from tornado.testing import AsyncHTTPTestCase
from adserver.base import ModelResponse
from typing import List, Dict, Optional
from typing import List, Dict, Optional, Union
import json
import requests_mock

Expand Down Expand Up @@ -33,7 +33,7 @@ def getResponse() -> ModelResponse:
def load(self):
pass

def process_event(self, inputs: List, headers: Dict) -> Optional[ModelResponse]:
def process_event(self, inputs: Union[List, Dict], headers: Dict):
assert headers[customHeaderKey] == customHeaderVal
if self.create_response:
return DummyModel.getResponse()
Expand Down
Loading