123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- name: Create and publish Docker images with specific build args
- on:
- workflow_dispatch:
- push:
- branches:
- - main
- - dev
- tags:
- - v*
- env:
- REGISTRY: ghcr.io
- IMAGE_NAME: ${{ github.repository }}
- FULL_IMAGE_NAME: ghcr.io/${{ github.repository }}
- jobs:
- build-main-image:
- runs-on: ubuntu-latest
- permissions:
- contents: read
- packages: write
- strategy:
- fail-fast: false
- matrix:
- platform:
- - linux/amd64
- - linux/arm64
- steps:
- - name: Prepare
- run: |
- platform=${{ matrix.platform }}
- echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- - name: Checkout repository
- uses: actions/checkout@v4
- - name: Set up QEMU
- uses: docker/setup-qemu-action@v3
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v3
- - 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 for Docker images (default latest tag)
- id: meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- type=ref,event=tag
- type=sha,prefix=git-
- type=semver,pattern={{version}}
- type=semver,pattern={{major}}.{{minor}}
- flavor: |
- latest=${{ github.ref == 'refs/heads/main' }}
- - name: Extract metadata for Docker cache
- id: cache-meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- flavor: |
- prefix=cache-${{ matrix.platform }}-
- - name: Build Docker image (latest)
- uses: docker/build-push-action@v5
- id: build
- with:
- context: .
- push: true
- platforms: ${{ matrix.platform }}
- labels: ${{ steps.meta.outputs.labels }}
- outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
- cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
- cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
- build-args: |
- BUILD_HASH=${{ github.sha }}
- - name: Export digest
- run: |
- mkdir -p /tmp/digests
- digest="${{ steps.build.outputs.digest }}"
- touch "/tmp/digests/${digest#sha256:}"
- - name: Upload digest
- uses: actions/upload-artifact@v4
- with:
- name: digests-main-${{ env.PLATFORM_PAIR }}
- path: /tmp/digests/*
- if-no-files-found: error
- retention-days: 1
- build-cuda-image:
- runs-on: ubuntu-latest
- permissions:
- contents: read
- packages: write
- strategy:
- fail-fast: false
- matrix:
- platform:
- - linux/amd64
- - linux/arm64
- steps:
- - name: Prepare
- run: |
- platform=${{ matrix.platform }}
- echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- - name: Checkout repository
- uses: actions/checkout@v4
- - name: Set up QEMU
- uses: docker/setup-qemu-action@v3
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v3
- - 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 for Docker images (cuda tag)
- id: meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- type=ref,event=tag
- type=sha,prefix=git-
- type=semver,pattern={{version}}
- type=semver,pattern={{major}}.{{minor}}
- type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda
- flavor: |
- latest=${{ github.ref == 'refs/heads/main' }}
- suffix=-cuda,onlatest=true
- - name: Extract metadata for Docker cache
- id: cache-meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- flavor: |
- prefix=cache-cuda-${{ matrix.platform }}-
- - name: Build Docker image (cuda)
- uses: docker/build-push-action@v5
- id: build
- with:
- context: .
- push: true
- platforms: ${{ matrix.platform }}
- labels: ${{ steps.meta.outputs.labels }}
- outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
- cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
- cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
- build-args: |
- BUILD_HASH=${{ github.sha }}
- USE_CUDA=true
- - name: Export digest
- run: |
- mkdir -p /tmp/digests
- digest="${{ steps.build.outputs.digest }}"
- touch "/tmp/digests/${digest#sha256:}"
- - name: Upload digest
- uses: actions/upload-artifact@v4
- with:
- name: digests-cuda-${{ env.PLATFORM_PAIR }}
- path: /tmp/digests/*
- if-no-files-found: error
- retention-days: 1
- build-ollama-image:
- runs-on: ubuntu-latest
- permissions:
- contents: read
- packages: write
- strategy:
- fail-fast: false
- matrix:
- platform:
- - linux/amd64
- - linux/arm64
- steps:
- - name: Prepare
- run: |
- platform=${{ matrix.platform }}
- echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- - name: Checkout repository
- uses: actions/checkout@v4
- - name: Set up QEMU
- uses: docker/setup-qemu-action@v3
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v3
- - 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 for Docker images (ollama tag)
- id: meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- type=ref,event=tag
- type=sha,prefix=git-
- type=semver,pattern={{version}}
- type=semver,pattern={{major}}.{{minor}}
- type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama
- flavor: |
- latest=${{ github.ref == 'refs/heads/main' }}
- suffix=-ollama,onlatest=true
- - name: Extract metadata for Docker cache
- id: cache-meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- flavor: |
- prefix=cache-ollama-${{ matrix.platform }}-
- - name: Build Docker image (ollama)
- uses: docker/build-push-action@v5
- id: build
- with:
- context: .
- push: true
- platforms: ${{ matrix.platform }}
- labels: ${{ steps.meta.outputs.labels }}
- outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
- cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
- cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
- build-args: |
- BUILD_HASH=${{ github.sha }}
- USE_OLLAMA=true
- - name: Export digest
- run: |
- mkdir -p /tmp/digests
- digest="${{ steps.build.outputs.digest }}"
- touch "/tmp/digests/${digest#sha256:}"
- - name: Upload digest
- uses: actions/upload-artifact@v4
- with:
- name: digests-ollama-${{ env.PLATFORM_PAIR }}
- path: /tmp/digests/*
- if-no-files-found: error
- retention-days: 1
- merge-main-images:
- runs-on: ubuntu-latest
- needs: [ build-main-image ]
- steps:
- - name: Download digests
- uses: actions/download-artifact@v4
- with:
- pattern: digests-main-*
- path: /tmp/digests
- merge-multiple: true
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v3
- - 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 for Docker images (default latest tag)
- id: meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- type=ref,event=tag
- type=sha,prefix=git-
- type=semver,pattern={{version}}
- type=semver,pattern={{major}}.{{minor}}
- flavor: |
- latest=${{ github.ref == 'refs/heads/main' }}
- - name: Create manifest list and push
- working-directory: /tmp/digests
- run: |
- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
- $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- - name: Inspect image
- run: |
- docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
- merge-cuda-images:
- runs-on: ubuntu-latest
- needs: [ build-cuda-image ]
- steps:
- - name: Download digests
- uses: actions/download-artifact@v4
- with:
- pattern: digests-cuda-*
- path: /tmp/digests
- merge-multiple: true
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v3
- - 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 for Docker images (default latest tag)
- id: meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- type=ref,event=tag
- type=sha,prefix=git-
- type=semver,pattern={{version}}
- type=semver,pattern={{major}}.{{minor}}
- type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda
- flavor: |
- latest=${{ github.ref == 'refs/heads/main' }}
- suffix=-cuda,onlatest=true
- - name: Create manifest list and push
- working-directory: /tmp/digests
- run: |
- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
- $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- - name: Inspect image
- run: |
- docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
- merge-ollama-images:
- runs-on: ubuntu-latest
- needs: [ build-ollama-image ]
- steps:
- - name: Download digests
- uses: actions/download-artifact@v4
- with:
- pattern: digests-ollama-*
- path: /tmp/digests
- merge-multiple: true
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v3
- - 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 for Docker images (default ollama tag)
- id: meta
- uses: docker/metadata-action@v5
- with:
- images: ${{ env.FULL_IMAGE_NAME }}
- tags: |
- type=ref,event=branch
- type=ref,event=tag
- type=sha,prefix=git-
- type=semver,pattern={{version}}
- type=semver,pattern={{major}}.{{minor}}
- type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama
- flavor: |
- latest=${{ github.ref == 'refs/heads/main' }}
- suffix=-ollama,onlatest=true
- - name: Create manifest list and push
- working-directory: /tmp/digests
- run: |
- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
- $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- - name: Inspect image
- run: |
- docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
|