Skip to content

Commit

Permalink
Add Release and Docker workflows (#7)
Browse files Browse the repository at this point in the history
* Add Release workflow

* Add package.yaml

* Add paths to tests

* Add generic name

* Add Dockerfile and run.sh
  • Loading branch information
daavoo authored Dec 12, 2024
1 parent d684acc commit 28e91d2
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Create and publish a Docker image

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

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: mzdotai/blueprint
flavor: |
latest=auto
- 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 }}
39 changes: 39 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
release:
types: [published]
workflow_dispatch:

jobs:
release:
environment: pypi
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Upgrade pip
run: |
pip install --upgrade pip
pip --version
- name: Install
run: python -m pip install build setuptools

- name: Build package
run: python -m build

- name: Upload package
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
6 changes: 6 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ name: Tests
on:
push:
branches: [main]
paths:
- 'src/**'
- 'tests/**'
pull_request:
paths:
- 'src/**'
- 'tests/**'
workflow_dispatch:

jobs:
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.10-slim

RUN pip3 install --no-cache-dir --upgrade pip
RUN apt-get update && apt-get install -y \
build-essential \
software-properties-common \
git


COPY . /home/appuser/blueprint
WORKDIR /home/appuser/blueprint

RUN pip3 install /home/appuser/blueprint

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

USER appuser

EXPOSE 8501
ENTRYPOINT ["./demo/run.sh"]
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

# 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

streamlit run ${HOME}/document-to-podcast/demo/app.py &
APP_ID=${!}

wait ${APP_ID}

0 comments on commit 28e91d2

Please sign in to comment.