From 06bd7a1792e68c9aa103c4ab3ba52a0e6619f918 Mon Sep 17 00:00:00 2001
From: David Thorpe <djt@mutablelogic.com>
Date: Sat, 10 Aug 2024 12:18:17 +0200
Subject: [PATCH] Updated

---
 .github/workflows/on_publish_cuda.yaml        | 93 +++++++++++++++++++
 ...yaml => on_publish_llamacpp.yaml_disabled} |  2 +-
 Makefile                                      |  4 +-
 3 files changed, 96 insertions(+), 3 deletions(-)
 create mode 100755 .github/workflows/on_publish_cuda.yaml
 rename .github/workflows/{on_publish.yaml => on_publish_llamacpp.yaml_disabled} (98%)
 mode change 100755 => 100644

diff --git a/.github/workflows/on_publish_cuda.yaml b/.github/workflows/on_publish_cuda.yaml
new file mode 100755
index 0000000..98d402b
--- /dev/null
+++ b/.github/workflows/on_publish_cuda.yaml
@@ -0,0 +1,93 @@
+name: Build cuda docker container on publish
+on:
+  release:
+    types: [ created, edited ]
+  workflow_dispatch:
+    inputs:
+      tag:
+        description: 'tag'
+        required: true
+        default: 'latest'
+        type: string
+jobs:
+  var:
+    name: Set variables
+    runs-on: ubuntu-latest
+    outputs:
+      image-cuda-dev: "ghcr.io/mutablelogic/cuda-dev"
+      image-cuda-runtime: "ghcr.io/mutablelogic/cuda-rt"
+      tag: ${{ steps.var.outputs.tag }}
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+      - name: Set variables
+        id: var
+        run: |
+          if [ "${{ github.event_name }}" != "release" ] && [ "${{ inputs.tag }}" != "latest" ]; then
+            TAG="${{ inputs.tag }}" && echo "tag=${TAG#v}" >> $GITHUB_OUTPUT
+          else
+            TAG="$(git describe --tags)" && echo "tag=${TAG#v}" >> $GITHUB_OUTPUT
+          fi
+  build:
+    name: Build
+    needs: var
+    strategy:
+      matrix:
+        arch: [ amd64, arm64 ]
+    runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || matrix.arch == 'arm64' && 'nx1' }}
+    env:
+      ARCH: ${{ matrix.arch }}
+      OS: linux
+      DOCKER_REGISTRY: ghcr.io/mutablelogic
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+      - name: Login
+        uses: docker/login-action@v3
+        with:
+          registry: ghcr.io
+          username: ${{ github.repository_owner }}
+          password: ${{ secrets.GITHUB_TOKEN }}
+      - name: Build and Push
+        id: build      
+        run: |
+          git checkout v${{ needs.var.outputs.tag }}
+          make docker-cuda-push
+  manifest:
+    name: Create manifest
+    needs: 
+      - build
+      - var
+    strategy:
+      matrix:
+        image:
+          - ${{ needs.var.outputs.image-cuda-dev }}
+          - ${{ needs.var.outputs.image-cuda-runtime }}
+    runs-on: ubuntu-latest
+    steps:
+      - name: Login
+        uses: docker/login-action@v3
+        with:
+          registry: ghcr.io
+          username: ${{ github.repository_owner }}
+          password: ${{ secrets.GITHUB_TOKEN }}
+      - name: Create
+        run: |
+          docker manifest create ${{ matrix.image }}:${{ needs.var.outputs.tag }} \
+            --amend ${{ matrix.image }}-linux-amd64:${{ needs.var.outputs.tag }} \
+            --amend ${{ matrix.image }}-linux-arm64:${{ needs.var.outputs.tag }}
+      - name: Annotate
+        run: |
+          docker manifest annotate --arch arm64 --os linux \
+            ${{ matrix.image }}:${{ needs.var.outputs.tag }} \
+            ${{ matrix.image }}-linux-arm64:${{ needs.var.outputs.tag }}
+          docker manifest annotate --arch amd64 --os linux \
+            ${{ matrix.image }}:${{ needs.var.outputs.tag }} \
+            ${{ matrix.image }}-linux-amd64:${{ needs.var.outputs.tag }}
+      - name: Push
+        run: |
+          docker manifest push ${{ matrix.image }}:${{ needs.var.outputs.tag }}
diff --git a/.github/workflows/on_publish.yaml b/.github/workflows/on_publish_llamacpp.yaml_disabled
old mode 100755
new mode 100644
similarity index 98%
rename from .github/workflows/on_publish.yaml
rename to .github/workflows/on_publish_llamacpp.yaml_disabled
index 2215e24..46c07ca
--- a/.github/workflows/on_publish.yaml
+++ b/.github/workflows/on_publish_llamacpp.yaml_disabled
@@ -1,4 +1,4 @@
-name: Build docker container on publish
+name: Build cuda docker container on publish
 on:
   release:
     types: [ created, edited ]
diff --git a/Makefile b/Makefile
index 8b053ce..f565793 100755
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,7 @@ test: generate llamacpp
 	@PKG_CONFIG_PATH=${ROOT_PATH}/${BUILD_DIR} ${GO} test -v ./sys/llamacpp/...
 
 # Base images for building and running CUDA containers
-docker-base: docker-dep
+docker-cuda: docker-dep
 	@echo "Building ${DOCKER_TAG_BASE_BUILD}"
 	@${DOCKER} build \
 	  --tag ${DOCKER_TAG_BASE_BUILD} \
@@ -53,7 +53,7 @@ docker-base: docker-dep
 	  -f Dockerfile.cuda .
 
 # Build docker container - assume we need to build the base images?
-docker: docker-dep docker-base
+docker-cuda-push: docker-cuda
 	@echo "Building ${DOCKER_TAG_LLAMACPP}"
 	@${DOCKER} build \
 		--tag ${DOCKER_TAG_LLAMACPP} \