Skip to content

Commit

Permalink
Update dockerfile for publishing image (#12)
Browse files Browse the repository at this point in the history
* Updated    dockerfile and CI

* Updated Dockerfile to fix some problems

* Fixed the copy of src/

* Update Dockerfile to see ls

* Update Dockerfile to have the src folder

* Update Dockerfile Reduce the nb of layers in the builder

* Fix the CI to forbid the manual use of the action
  • Loading branch information
gsolard authored and mfournioux committed Jun 26, 2024
1 parent 89e8fe6 commit 12284d2
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 19 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/install_test_from_requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build & Tests
on:
push:
paths:
- 'src/**'
- '!*.md'
pull_request:
types: [opened, reopened, synchronize]
branches:
- 'main'
- 'release/v*'
paths:
- 'src/**'
- '!*.md'
schedule:
- cron: '0 4 * * *'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install the project and run tests
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install .[test]
pytest
python -m mypy --ignore-missing-imports --allow-redefinition --no-strict-optional -p src
1 change: 0 additions & 1 deletion .github/workflows/publish_docker_image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ name: Publish Docker image
on:
release:
types: [published]
workflow_dispatch:

jobs:
push_to_registry:
Expand Down
67 changes: 49 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,61 @@
ARG base_image=nvidia/cuda:12.1.0-devel-ubuntu22.04
FROM nvidia/cuda:12.1.0-runtime-ubuntu22.04 AS builder

# base image
FROM ${base_image}
LABEL org.opencontainers.image.author="Agence Data Services"
LABEL org.opencontainers.image.description="REST service happy-vllm"

ENV APP_NAME="happy_vllm"
ENV API_ENTRYPOINT="/happy_vllm/rs/v1"
COPY prebuildfs /
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

LABEL maintainer="Agence Data Services"
LABEL description="Service REST happy_vllm"
# Install python common
RUN install_packages software-properties-common

RUN add-apt-repository -d -y 'ppa:deadsnakes/ppa' \
&& install_packages python3.11 python3.11-dev python3.11-venv python3-pip \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=true \
APP_NAME="happy_vllm" \
API_ENTRYPOINT="/happy_vllm/rs/v1"

RUN python -m venv /opt/venv \
&& pip install --upgrade pip
ENV VIRTUAL_ENV="/opt/venv" PATH="/opt/venv/bin:${PATH}"

WORKDIR /app

# Install package
COPY pyproject.toml pyproject.toml
COPY setup.py setup.py
COPY src/ src/
COPY requirements.txt requirements.txt
COPY version.txt version.txt
COPY pyproject.toml setup.py README.md requirements.txt version.txt /app
COPY src/happy_vllm /app/src/happy_vllm

RUN python -m pip install -r requirements.txt && python -m pip install .

FROM nvidia/cuda:12.1.0-runtime-ubuntu22.04

RUN add-apt-repository -d -y 'ppa:deadsnakes/ppa'
RUN install_packages python3.11 python3.11-dev python3.11-venv python3-pip
COPY prebuildfs /
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN ln -sfn /usr/bin/python3.11 /usr/bin/python3
# Install python common
RUN install_packages software-properties-common

RUN add-apt-repository -d -y 'ppa:deadsnakes/ppa' \
&& install_packages python3.11 \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/opt/venv/bin:${PATH}" \
PIP_NO_CACHE_DIR=true \
APP_NAME="happy_vllm" \
API_ENTRYPOINT="/happy_vllm/rs/v1"

COPY --from=builder /opt/venv /opt/venv

WORKDIR /app

RUN python3 -m pip install --upgrade pip && python3 -m pip install -r requirements.txt && python3 -m pip install .
COPY src/happy_vllm/launch.py /app

# Start API
EXPOSE 8501
CMD ["python3", "src/happy_vllm/launch.py"]
EXPOSE 8000
CMD ["python", "/app/launch.py"]
26 changes: 26 additions & 0 deletions prebuildfs/usr/sbin/install_packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
set -eu

n=0
max=2
export DEBIAN_FRONTEND=noninteractive
export MKUSER=""

until [ $n -gt $max ]; do
set +e
(
apt-get update -qq &&
apt-get install -y --no-install-recommends "$@"
)
CODE=$?
set -e
if [ $CODE -eq 0 ]; then
break
fi
if [ $n -eq $max ]; then
exit $CODE
fi
echo "apt failed, retrying"
n=$(($n + 1))
done
apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives

0 comments on commit 12284d2

Please sign in to comment.