From d72ba3a7a7b8f4df5e63c3c9a7d01e9cc85d6740 Mon Sep 17 00:00:00 2001 From: daavoo Date: Thu, 5 Dec 2024 10:54:33 +0100 Subject: [PATCH] Enable build and push of Dockerfile. --- .github/workflows/package.yaml | 55 ++++++++++++++++++++++++++++++++++ Dockerfile | 26 ++++++++++++++++ demo/download_models.py | 9 ++++++ demo/run.sh | 26 ++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 .github/workflows/package.yaml create mode 100644 Dockerfile create mode 100644 demo/download_models.py create mode 100644 demo/run.sh diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml new file mode 100644 index 0000000..36011c5 --- /dev/null +++ b/.github/workflows/package.yaml @@ -0,0 +1,55 @@ +name: Create and publish a Docker image + +on: + push: + branches: + - 'main' + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..180f8fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.10-slim + +RUN groupadd --gid 1000 appuser \ + && useradd --uid 1000 --gid 1000 -ms /bin/bash appuser + +RUN pip3 install --no-cache-dir --upgrade \ + pip \ + virtualenv + +RUN apt-get update && apt-get install -y \ + build-essential \ + software-properties-common \ + git + +USER appuser +ENV VIRTUAL_ENV=/home/appuser/venv + +COPY . /home/appuser/document-to-podcast +WORKDIR /home/appuser/document-to-podcast + +RUN virtualenv ${VIRTUAL_ENV} +RUN . ${VIRTUAL_ENV}/bin/activate && pip install -e /home/appuser/document-to-podcast +RUN . ${VIRTUAL_ENV}/bin/activate && python demo/download_models.py + +EXPOSE 8501 +ENTRYPOINT ["./demo/run.sh"] diff --git a/demo/download_models.py b/demo/download_models.py new file mode 100644 index 0000000..9c0ec51 --- /dev/null +++ b/demo/download_models.py @@ -0,0 +1,9 @@ +from document_to_podcast.inference.model_loaders import ( + load_llama_cpp_model, + load_parler_tts_model_and_tokenizer, +) + +load_llama_cpp_model( + model_id="allenai/OLMoE-1B-7B-0924-Instruct-GGUF/olmoe-1b-7b-0924-instruct-q8_0.gguf" +) +load_parler_tts_model_and_tokenizer("parler-tts/parler-tts-mini-v1") diff --git a/demo/run.sh b/demo/run.sh new file mode 100644 index 0000000..90eda18 --- /dev/null +++ b/demo/run.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +APP_PID= +stopRunningProcess() { + # Based on https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script + if test ! "${APP_PID}" = '' && ps -p ${APP_PID} > /dev/null ; then + > /proc/1/fd/1 echo "Stopping ${COMMAND_PATH} which is running with process ID ${APP_PID}" + + kill -TERM ${APP_PID} + > /proc/1/fd/1 echo "Waiting for ${COMMAND_PATH} to process SIGTERM signal" + + wait ${APP_PID} + > /proc/1/fd/1 echo "All processes have stopped running" + else + > /proc/1/fd/1 echo "${COMMAND_PATH} was not started when the signal was sent or it has already been stopped" + fi +} + +trap stopRunningProcess EXIT TERM + +source ${VIRTUAL_ENV}/bin/activate + +streamlit run ${HOME}/document-to-podcast/demo/app.py & +APP_ID=${!} + +wait ${APP_ID}