From c4c7739f9bff8a686f82d7fe94bbb74fc790ed97 Mon Sep 17 00:00:00 2001 From: Benedikt Wagener Date: Fri, 13 Dec 2024 20:48:29 +0100 Subject: [PATCH] test multistage Dockerfile --- .github/workflows/build-container-image.yml | 7 ++- multistage.Dockerfile | 47 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 multistage.Dockerfile diff --git a/.github/workflows/build-container-image.yml b/.github/workflows/build-container-image.yml index c875775..f689891 100644 --- a/.github/workflows/build-container-image.yml +++ b/.github/workflows/build-container-image.yml @@ -6,7 +6,6 @@ on: env: IMAGE_NAME: ultrasinger IMAGE_TAGS: v1 ${{ github.sha }} - IMAGE_REGISTRY: ghcr.io/${{ github.repository }} REGISTRY_USER: ${{ github.actor }} REGISTRY_PASSWORD: ${{ github.token }} @@ -16,9 +15,9 @@ jobs: runs-on: ubuntu-22.04 steps: - - name: downcase REPO + - name: lowercase github.repository run: | - echo "REPO=${IMAGE_REGISTRY,,}" >>${GITHUB_ENV} + echo "IMAGE_REGISTRY=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} - name: Clear space run: | df -h / @@ -47,7 +46,7 @@ jobs: image: ${{ env.IMAGE_NAME }} tags: ${{ env.IMAGE_TAGS }} containerfiles: | - ./Dockerfile + ./multistage.Dockerfile oci: true layers: true # Push the image to GHCR (Image Registry) https://github.com/redhat-actions/push-to-registry diff --git a/multistage.Dockerfile b/multistage.Dockerfile new file mode 100644 index 0000000..db32366 --- /dev/null +++ b/multistage.Dockerfile @@ -0,0 +1,47 @@ +FROM nvidia/cuda:12.6.3-runtime-ubuntu22.04 AS base + +# note: the python3-pip package contains Python 3.10 on Ubuntu 22.04 +RUN apt-get update \ + && apt-get install git python3-pip python3.10-venv ffmpeg -y \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# copy only the requirements file to leverage container image build cache +COPY ./requirements.txt /app/UltraSinger/requirements.txt +WORKDIR /app/UltraSinger + +# no need to run as root +RUN chown -R 1000:1000 /app/UltraSinger +USER 1000:1000 + +# setup venv +ENV VIRTUAL_ENV=/app/UltraSinger/.venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# install dependencies +RUN pip install --no-cache-dir -r requirements.txt \ + && pip install --no-cache-dir torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121 \ + && pip install --no-cache-dir tensorflow[and-cuda]==2.16.1 + +# create runtime image with minimal dependencies +FROM nvidia/cuda:12.6.3-runtime-ubuntu22.04 AS runtime + +# note: the python3 package contains Python 3.10 on Ubuntu 22.04 +RUN apt-get update \ + && apt-get install python3 ffmpeg -y \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +USER 1000:1000 + +COPY --from=base --chown 1000:1000 /app/UltraSinger/ /app/UltraSinger/ + +# setup venv +ENV VIRTUAL_ENV=/app/UltraSinger/.venv +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# copy sources late to allow for caching of layers which contain all the dependencies +COPY . /app/UltraSinger +WORKDIR /app/UltraSinger/src +CMD ["bash" ]