Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
79 changes: 79 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build and Publish Docker Image

on:
push:
branches: [main]
paths:
- 'src/**'
- 'pyproject.toml'
- 'Dockerfile'
- '.github/workflows/docker-publish.yml'
release:
types: [published]
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v6

- name: Repository name lowercase
run: echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=,enable=${{github.event_name == 'workflow_dispatch'}}

- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DOWNLOAD_WEIGHTS=false
cache-from: type=registry,ref=ghcr.io/${{ env.REPO_LC }}-cache:buildcache
cache-to: type=registry,ref=ghcr.io/${{ env.REPO_LC }}-cache:buildcache,mode=max

cleanup:
runs-on: ubuntu-latest
needs: build-and-push
permissions:
packages: write

steps:
- name: Delete old container images
uses: actions/delete-package-versions@v5
with:
package-name: ${{ github.event.repository.name }}
package-type: container
min-versions-to-keep: 5
ignore-versions: ^v\d+\.\d+\.\d+$
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
CUDA_HOME=/usr/local/cuda \
PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cu121 \
HF_HOME=/cache

HF_HOME=/cache \
NUMBA_CACHE_DIR=/tmp/numba_cache \
TRITON_CACHE_DIR=/tmp/triton_cache \
XDG_CACHE_HOME=/tmp/xdg_cache

RUN apt-get update && \
apt-get install -y --no-install-recommends \
software-properties-common \
Expand Down Expand Up @@ -40,9 +43,14 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 &

WORKDIR /app

COPY . /app
# Install dependencies (cached unless pyproject.toml changes)
COPY pyproject.toml PYPI_DESCRIPTION.md /app/
COPY src/boltzgen/__init__.py /app/src/boltzgen/__init__.py
RUN pip install --no-cache-dir \
--extra-index-url https://download.pytorch.org/whl/cu121 \
-e /app "torch>=2.4.1,<2.10"

RUN pip install --no-cache-dir -e /app
COPY . /app

ARG DOWNLOAD_WEIGHTS=false
RUN mkdir -p "${HF_HOME}" && \
Expand Down