diff --git a/Dockerfile b/Dockerfile index 854186b7..aa819b6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,35 @@ ARG GO_VERSION=1.20-bullseye - FROM golang:$GO_VERSION as requirements +# [Option] Upgrade OS packages to their latest versions +ARG UPGRADE_PACKAGES="$true" + +COPY scripts/debian.sh /tmp/library-scripts/ +RUN bash /tmp/library-scripts/debian.sh "${UPGRADE_PACKAGES}" \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts + +# Install CuBLAS ARG BUILD_TYPE -ARG CUDA_MAJOR_VERSION=11 -ARG CUDA_MINOR_VERSION=7 +ARG KEYRING_VERSION="1.0-1" +ARG CUDA_MAJOR_VERSION="11" +ARG CUDA_MINOR_VERSION="7" -ENV BUILD_TYPE=${BUILD_TYPE} - -RUN apt-get update && \ - apt-get install -y ca-certificates cmake curl patch - -# CuBLAS requirements -RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ - apt-get install -y software-properties-common && \ - apt-add-repository contrib && \ - curl -O https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_1.0-1_all.deb && \ - dpkg -i cuda-keyring_1.0-1_all.deb && \ - rm -f cuda-keyring_1.0-1_all.deb && \ - apt-get update && \ - apt-get install -y cuda-nvcc-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcublas-dev-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} \ - ; fi +# ENV BUILD_TYPE=${BUILD_TYPE} +COPY scripts/cu-blas.sh /tmp/library-scripts/ +RUN bash /tmp/library-scripts/cu-blas.sh "${BUILD_TYPE}" "${KEYRING_VERSION}" "${CUDA_MAJOR_VERSION} ${CUDA_MINOR_VERSION}" \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts ENV PATH /usr/local/cuda/bin:${PATH} -# OpenBLAS requirements -RUN apt-get install -y libopenblas-dev +# Install OpenBLAS +COPY scripts/open-blas.sh /tmp/library-scripts/ +RUN bash /tmp/library-scripts/open-blas.sh \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts + +# Install Stable Diffusion requirements +COPY scripts/stable-diffusion.sh /tmp/library-scripts/ +RUN bash /tmp/library-scripts/stable-diffusion.sh \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts -# Stable Diffusion requirements -RUN apt-get install -y libopencv-dev && \ - ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 FROM requirements as builder @@ -44,6 +45,7 @@ WORKDIR /build COPY . . RUN make build + FROM requirements ARG FFMPEG @@ -51,10 +53,10 @@ ARG FFMPEG ENV REBUILD=true ENV HEALTHCHECK_ENDPOINT=http://localhost:8080/readyz -# Add FFmpeg -RUN if [ "${FFMPEG}" = "true" ]; then \ - apt-get install -y ffmpeg \ - ; fi +# Install FFmpeg +COPY scripts/ffmpeg.sh /tmp/library-scripts/ +RUN bash /tmp/library-scripts/ffmpeg.sh "${FFMPEG}" \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts WORKDIR /build @@ -67,4 +69,4 @@ HEALTHCHECK --interval=1m --timeout=10m --retries=10 \ CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1 EXPOSE 8080 -ENTRYPOINT [ "/build/entrypoint.sh" ] \ No newline at end of file +ENTRYPOINT [ "/build/entrypoint.sh" ] diff --git a/scripts/cu-blas.sh b/scripts/cu-blas.sh new file mode 100644 index 00000000..96a9fe05 --- /dev/null +++ b/scripts/cu-blas.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Syntax: ./cu-blas.sh [KEYRING_VERSION] [CUDA_MAJOR_VERSION] [CUDA_MINOR_VERSION] + +set -e + +BUILD_TYPE=${1:-"none"} +KEYRING_VERSION=${2:-"1.0-1"} +CUDA_MAJOR_VERSION=${3:-"11"} +CUDA_MINOR_VERSION=${4:-"7"} + + +export DEBIAN_FRONTEND=noninteractive + +# Install software-properties-common +if [ "${BUILD_TYPE}" = "cublas" ] && ! dpkg -s software-properties-common > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends software-properties-common +fi + +# Install cuda-keyring +CUDA_KEYRING_SCRIPT="$(cat < /dev/null 2>&1; then + "${SCHEME_INSTALL_SCRIPT}" +else + echo "Cuda keyring already installed. Skipping." +fi + +echo "Done!" \ No newline at end of file diff --git a/scripts/debian.sh b/scripts/debian.sh new file mode 100644 index 00000000..f0b6c2be --- /dev/null +++ b/scripts/debian.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Syntax: ./debian.sh [upgrade packages flag] + +set -e + +UPGRADE_PACKAGES=${1:-"true"} + +# Ensure apt is in non-interactive to avoid prompts +export DEBIAN_FRONTEND=noninteractive + +# Function to call apt-get if needed +apt_get_update_if_needed() +{ + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update + else + echo "Skipping apt-get update." + fi +} + +# Get to latest versions of all packages +if [ "${UPGRADE_PACKAGES}" = "true" ]; then + apt_get_update_if_needed + apt-get -y upgrade --no-install-recommends + apt-get autoremove -y +fi + +# Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies +if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then + apt_get_update_if_needed + + package_list="apt-utils \ + ca-certificates \ + cmake \ + patch \ + curl" + + echo "Packages to verify are installed: ${package_list}" + apt-get -y install --no-install-recommends ${package_list} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 ) + + PACKAGES_ALREADY_INSTALLED="true" +fi + +echo "Done!" \ No newline at end of file diff --git a/scripts/ffmpeg.sh b/scripts/ffmpeg.sh new file mode 100644 index 00000000..f22c6670 --- /dev/null +++ b/scripts/ffmpeg.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Syntax: ./ffmpeg.sh [upgrade packages flag] + +set -e + +FFMPEG=${1:-"false"} + +# Ensure apt is in non-interactive to avoid prompts +export DEBIAN_FRONTEND=noninteractive + +# Install ffmpeg +if [ "${FFMPEG}" = "true" ] && ! dpkg -s ffmpeg > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends ffmpeg +fi + +echo "Done!" \ No newline at end of file diff --git a/scripts/open-blas.sh b/scripts/open-blas.sh new file mode 100644 index 00000000..beb98d7e --- /dev/null +++ b/scripts/open-blas.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Syntax: ./open-blash.sh + +set -e + +# Ensure apt is in non-interactive to avoid prompts +export DEBIAN_FRONTEND=noninteractive + +# Install software-properties-common +if ! dpkg -s libopenblas-dev > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends libopenblas-dev +fi + +echo "Done!" \ No newline at end of file diff --git a/scripts/stable-diffusion.sh b/scripts/stable-diffusion.sh new file mode 100644 index 00000000..d9125fea --- /dev/null +++ b/scripts/stable-diffusion.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Syntax: ./stable-diffusion.sh + +set -e + +if ! dpkg -s libopencv-dev > /dev/null 2>&1; then + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then + apt-get update + fi + apt-get -y install --no-install-recommends libopencv-dev + ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 +fi + +echo "Done!" \ No newline at end of file