121 lines
3.8 KiB
YAML
121 lines
3.8 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on: workflow_dispatch
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
actions: read
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- variant: "cu12"
|
|
cuda_version: "12.6.2"
|
|
containerfile: "ik_llama-cuda.Containerfile"
|
|
- variant: "cu13"
|
|
cuda_version: "13.1.1"
|
|
containerfile: "ik_llama-cuda.Containerfile"
|
|
- variant: "cpu"
|
|
cuda_version: "none"
|
|
containerfile: "ik_llama-cpu.Containerfile"
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 100 # Enough for rev-list, but saves GBs of history
|
|
|
|
- name: Free Disk Space (Ubuntu)
|
|
run: |
|
|
echo "Listing initial disk usage..."
|
|
df -h
|
|
sudo rm -rf /usr/share/dotnet
|
|
sudo rm -rf /usr/local/lib/android
|
|
sudo rm -rf /opt/ghc
|
|
sudo rm -rf "/usr/local/share/boost"
|
|
sudo rm -rf /usr/lib/jvm
|
|
sudo docker image prune -af
|
|
echo "Listing disk usage after cleanup..."
|
|
df -h
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Prepare Environment
|
|
id: prep
|
|
run: |
|
|
echo "BUILD_NUMBER=$(git rev-list --count HEAD)" >> $GITHUB_ENV
|
|
echo "LLAMA_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
|
echo "REPO_LOWER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
|
|
|
|
# 5.1 Restore the cache from GitHub's storage to a host folder
|
|
- name: Cache ccache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: .buildkit-cache
|
|
key: ccache-${{ matrix.variant }}-${{ github.run_id }}
|
|
restore-keys: |
|
|
ccache-${{ matrix.variant }}-
|
|
|
|
# 5.2. "Inject" that host folder into BuildKit's internal mount system
|
|
- name: Inject ccache into BuildKit
|
|
uses: reproducible-containers/buildkit-cache-dance@v3
|
|
with:
|
|
cache-map: |
|
|
{
|
|
".buildkit-cache": "/ccache"
|
|
}
|
|
skip-extraction: ${{ github.event_name == 'pull_request' }}
|
|
|
|
# 5.3 Build and push using the cache
|
|
- name: Build and Push
|
|
uses: docker/bake-action@v7
|
|
env:
|
|
REPO_OWNER: ${{ env.REPO_LOWER }}
|
|
VARIANT: ${{ matrix.variant }}
|
|
BUILD_NUMBER: ${{ env.BUILD_NUMBER }}
|
|
LLAMA_COMMIT: ${{ env.LLAMA_COMMIT }}
|
|
CUDA_VERSION: ${{ matrix.cuda_version }}
|
|
GGML_NATIVE: "OFF" # Force OFF for CI portability
|
|
USE_CCACHE: "true"
|
|
with:
|
|
push: true
|
|
files: ./docker-bake.hcl
|
|
set: |
|
|
*.context=.
|
|
*.dockerfile=./docker/${{ matrix.containerfile }}
|
|
*.cache-from=type=gha,scope=ccache-${{ matrix.variant }}
|
|
*.cache-to=type=gha,mode=max,scope=ccache-${{ matrix.variant }}
|
|
source: .
|
|
|
|
cleanup:
|
|
runs-on: ubuntu-latest
|
|
needs: build-and-push
|
|
if: success()
|
|
steps:
|
|
- name: Delete untagged images
|
|
uses: vlaurin/action-ghcr-prune@v0.6.0
|
|
with:
|
|
# Use a PAT if GITHUB_TOKEN continues to return "Not Found"
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
# Ensure this matches the package owner (user or org)
|
|
organization: ${{ github.repository_owner }}
|
|
container: ik-llama-cpp
|
|
# Changed from untagged-only to the valid input
|
|
untagged: true
|
|
# Optional: Keep the most recent untagged if needed,
|
|
# otherwise 0 deletes all untagged.
|
|
keep-last: 0
|