Skip to content

Commit

Permalink
Enable build and push of Dockerfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
daavoo committed Dec 5, 2024
1 parent f806c62 commit d72ba3a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/package.yaml
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
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
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
9 changes: 9 additions & 0 deletions demo/download_models.py
Original file line number Diff line number Diff line change
@@ -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")
26 changes: 26 additions & 0 deletions demo/run.sh
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit d72ba3a

Please sign in to comment.