Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable build and push of Dockerfile. #41

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/package.yaml
daavoo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Create and publish a Docker image

on:
push:
branches:
- 'main'
tags:
- 'v*'

env:
REGISTRY: ghcr.io
daavoo marked this conversation as resolved.
Show resolved Hide resolved
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
28 changes: 28 additions & 0 deletions Dockerfile
Kostis-S-Z marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM python:3.10-slim

RUN pip3 install --no-cache-dir --upgrade \
pip \
virtualenv

RUN apt-get update && apt-get install -y \
build-essential \
software-properties-common \
git

ENV VIRTUAL_ENV=/home/venv
macaab26 marked this conversation as resolved.
Show resolved Hide resolved

COPY . /home/appuser/document-to-podcast
WORKDIR /home/appuser/document-to-podcast

RUN virtualenv ${VIRTUAL_ENV}
RUN . ${VIRTUAL_ENV}/bin/activate && pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu
Kostis-S-Z marked this conversation as resolved.
Show resolved Hide resolved
RUN . ${VIRTUAL_ENV}/bin/activate && pip install /home/appuser/document-to-podcast
RUN . ${VIRTUAL_ENV}/bin/activate && python demo/download_models.py

RUN groupadd --gid 1000 appuser \
&& useradd --uid 1000 --gid 1000 -ms /bin/bash appuser

USER appuser

EXPOSE 8501
ENTRYPOINT ["./demo/run.sh"]
13 changes: 13 additions & 0 deletions demo/download_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Used when building the Dockerfile to download the models that are used in the hosted demo
"""

from document_to_podcast.inference.model_loaders import (
load_llama_cpp_model,
load_parler_tts_model_and_tokenizer,
)

daavoo marked this conversation as resolved.
Show resolved Hide resolved
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")
28 changes: 28 additions & 0 deletions demo/run.sh
daavoo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Adapted from https://docs.streamlit.io/deploy/tutorials/kubernetes

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}
Loading