feat: split building process by several scripts

Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
Aisuko 2023-06-18 12:46:51 +00:00 committed by GitHub
parent d3d3187e51
commit 4117509927
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 179 additions and 28 deletions

View file

@ -1,34 +1,35 @@
ARG GO_VERSION=1.20-bullseye ARG GO_VERSION=1.20-bullseye
FROM golang:$GO_VERSION as requirements 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 BUILD_TYPE
ARG CUDA_MAJOR_VERSION=11 ARG KEYRING_VERSION="1.0-1"
ARG CUDA_MINOR_VERSION=7 ARG CUDA_MAJOR_VERSION="11"
ARG CUDA_MINOR_VERSION="7"
ENV BUILD_TYPE=${BUILD_TYPE} # ENV BUILD_TYPE=${BUILD_TYPE}
COPY scripts/cu-blas.sh /tmp/library-scripts/
RUN apt-get update && \ RUN bash /tmp/library-scripts/cu-blas.sh "${BUILD_TYPE}" "${KEYRING_VERSION}" "${CUDA_MAJOR_VERSION} ${CUDA_MINOR_VERSION}" \
apt-get install -y ca-certificates cmake curl patch && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
# 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 PATH /usr/local/cuda/bin:${PATH} ENV PATH /usr/local/cuda/bin:${PATH}
# OpenBLAS requirements # Install OpenBLAS
RUN apt-get install -y libopenblas-dev 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 FROM requirements as builder
@ -44,6 +45,7 @@ WORKDIR /build
COPY . . COPY . .
RUN make build RUN make build
FROM requirements FROM requirements
ARG FFMPEG ARG FFMPEG
@ -51,10 +53,10 @@ ARG FFMPEG
ENV REBUILD=true ENV REBUILD=true
ENV HEALTHCHECK_ENDPOINT=http://localhost:8080/readyz ENV HEALTHCHECK_ENDPOINT=http://localhost:8080/readyz
# Add FFmpeg # Install FFmpeg
RUN if [ "${FFMPEG}" = "true" ]; then \ COPY scripts/ffmpeg.sh /tmp/library-scripts/
apt-get install -y ffmpeg \ RUN bash /tmp/library-scripts/ffmpeg.sh "${FFMPEG}" \
; fi && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
WORKDIR /build WORKDIR /build
@ -67,4 +69,4 @@ HEALTHCHECK --interval=1m --timeout=10m --retries=10 \
CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1 CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT [ "/build/entrypoint.sh" ] ENTRYPOINT [ "/build/entrypoint.sh" ]

50
scripts/cu-blas.sh Normal file
View file

@ -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 <<EOF
set -e
# Wrapper function to only use sudo if not already root
sudoIf()
{
if [ "\$(id -u)" -ne 0 ]; then
sudo "\$@"
else
"\$@"
fi
}
sudoIf apt-add-repository contrib
echo "Downloading Cuda-Keyring ${KEYRING_VERSION}..."
curl -sSL -o /tmp/cuda-keyring_${KEYRING_VERSION}_all.deb "https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_${KEYRING_VERSION}_all.deb"
dpkg -i cuda-keyring_${KEYRING_VERSION}_all.deb
sudoIf apt-get update
sudoIf apt-get -y install --no-install-recommends cuda-nvcc-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcublas-dev-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION}
EOF
)"
if [ "${BUILD_TYPE}" = "cublas" ] > /dev/null 2>&1; then
"${SCHEME_INSTALL_SCRIPT}"
else
echo "Cuda keyring already installed. Skipping."
fi
echo "Done!"

46
scripts/debian.sh Normal file
View file

@ -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!"

20
scripts/ffmpeg.sh Normal file
View file

@ -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!"

18
scripts/open-blas.sh Normal file
View file

@ -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!"

View file

@ -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!"