Niansuh/open-webui
2
1name: Create and publish Docker images with specific build args2 3on:4 workflow_dispatch:5 push:6 branches:7 - main8 - dev9 tags:10 - v*11 12env:13 REGISTRY: ghcr.io14 15jobs:16 build-main-image:17 runs-on: ubuntu-latest18 permissions:19 contents: read20 packages: write21 strategy:22 fail-fast: false23 matrix:24 platform:25 - linux/amd6426 - linux/arm6427 28 steps:29 # GitHub Packages requires the entire repository name to be in lowercase30 # although the repository owner has a lowercase username, this prevents some people from running actions after forking31 - name: Set repository and image name to lowercase32 run: |33 echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}34 echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}35 env:36 IMAGE_NAME: '${{ github.repository }}'37 38 - name: Prepare39 run: |40 platform=${{ matrix.platform }}41 echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV42 43 - name: Checkout repository44 uses: actions/checkout@v445 46 - name: Set up QEMU47 uses: docker/setup-qemu-action@v348 49 - name: Set up Docker Buildx50 uses: docker/setup-buildx-action@v351 52 - name: Log in to the Container registry53 uses: docker/login-action@v354 with:55 registry: ${{ env.REGISTRY }}56 username: ${{ github.actor }}57 password: ${{ secrets.GITHUB_TOKEN }}58 59 - name: Extract metadata for Docker images (default latest tag)60 id: meta61 uses: docker/metadata-action@v562 with:63 images: ${{ env.FULL_IMAGE_NAME }}64 tags: |65 type=ref,event=branch66 type=ref,event=tag67 type=sha,prefix=git-68 type=semver,pattern={{version}}69 type=semver,pattern={{major}}.{{minor}}70 flavor: |71 latest=${{ github.ref == 'refs/heads/main' }}72 73 - name: Extract metadata for Docker cache74 id: cache-meta75 uses: docker/metadata-action@v576 with:77 images: ${{ env.FULL_IMAGE_NAME }}78 tags: |79 type=ref,event=branch80 ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }}81 flavor: |82 prefix=cache-${{ matrix.platform }}-83 latest=false84 85 - name: Build Docker image (latest)86 uses: docker/build-push-action@v587 id: build88 with:89 context: .90 push: true91 platforms: ${{ matrix.platform }}92 labels: ${{ steps.meta.outputs.labels }}93 outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true94 cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}95 cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max96 build-args: |97 BUILD_HASH=${{ github.sha }}98 99 - name: Export digest100 run: |101 mkdir -p /tmp/digests102 digest="${{ steps.build.outputs.digest }}"103 touch "/tmp/digests/${digest#sha256:}"104 105 - name: Upload digest106 uses: actions/upload-artifact@v4107 with:108 name: digests-main-${{ env.PLATFORM_PAIR }}109 path: /tmp/digests/*110 if-no-files-found: error111 retention-days: 1112 113 build-cuda-image:114 runs-on: ubuntu-latest115 permissions:116 contents: read117 packages: write118 strategy:119 fail-fast: false120 matrix:121 platform:122 - linux/amd64123 - linux/arm64124 125 steps:126 # GitHub Packages requires the entire repository name to be in lowercase127 # although the repository owner has a lowercase username, this prevents some people from running actions after forking128 - name: Set repository and image name to lowercase129 run: |130 echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}131 echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}132 env:133 IMAGE_NAME: '${{ github.repository }}'134 135 - name: Prepare136 run: |137 platform=${{ matrix.platform }}138 echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV139 140 - name: Checkout repository141 uses: actions/checkout@v4142 143 - name: Set up QEMU144 uses: docker/setup-qemu-action@v3145 146 - name: Set up Docker Buildx147 uses: docker/setup-buildx-action@v3148 149 - name: Log in to the Container registry150 uses: docker/login-action@v3151 with:152 registry: ${{ env.REGISTRY }}153 username: ${{ github.actor }}154 password: ${{ secrets.GITHUB_TOKEN }}155 156 - name: Extract metadata for Docker images (cuda tag)157 id: meta158 uses: docker/metadata-action@v5159 with:160 images: ${{ env.FULL_IMAGE_NAME }}161 tags: |162 type=ref,event=branch163 type=ref,event=tag164 type=sha,prefix=git-165 type=semver,pattern={{version}}166 type=semver,pattern={{major}}.{{minor}}167 type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda168 flavor: |169 latest=${{ github.ref == 'refs/heads/main' }}170 suffix=-cuda,onlatest=true171 172 - name: Extract metadata for Docker cache173 id: cache-meta174 uses: docker/metadata-action@v5175 with:176 images: ${{ env.FULL_IMAGE_NAME }}177 tags: |178 type=ref,event=branch179 ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }}180 flavor: |181 prefix=cache-cuda-${{ matrix.platform }}-182 latest=false183 184 - name: Build Docker image (cuda)185 uses: docker/build-push-action@v5186 id: build187 with:188 context: .189 push: true190 platforms: ${{ matrix.platform }}191 labels: ${{ steps.meta.outputs.labels }}192 outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true193 cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}194 cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max195 build-args: |196 BUILD_HASH=${{ github.sha }}197 USE_CUDA=true198 199 - name: Export digest200 run: |201 mkdir -p /tmp/digests202 digest="${{ steps.build.outputs.digest }}"203 touch "/tmp/digests/${digest#sha256:}"204 205 - name: Upload digest206 uses: actions/upload-artifact@v4207 with:208 name: digests-cuda-${{ env.PLATFORM_PAIR }}209 path: /tmp/digests/*210 if-no-files-found: error211 retention-days: 1212 213 build-ollama-image:214 runs-on: ubuntu-latest215 permissions:216 contents: read217 packages: write218 strategy:219 fail-fast: false220 matrix:221 platform:222 - linux/amd64223 - linux/arm64224 225 steps:226 # GitHub Packages requires the entire repository name to be in lowercase227 # although the repository owner has a lowercase username, this prevents some people from running actions after forking228 - name: Set repository and image name to lowercase229 run: |230 echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}231 echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}232 env:233 IMAGE_NAME: '${{ github.repository }}'234 235 - name: Prepare236 run: |237 platform=${{ matrix.platform }}238 echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV239 240 - name: Checkout repository241 uses: actions/checkout@v4242 243 - name: Set up QEMU244 uses: docker/setup-qemu-action@v3245 246 - name: Set up Docker Buildx247 uses: docker/setup-buildx-action@v3248 249 - name: Log in to the Container registry250 uses: docker/login-action@v3251 with:252 registry: ${{ env.REGISTRY }}253 username: ${{ github.actor }}254 password: ${{ secrets.GITHUB_TOKEN }}255 256 - name: Extract metadata for Docker images (ollama tag)257 id: meta258 uses: docker/metadata-action@v5259 with:260 images: ${{ env.FULL_IMAGE_NAME }}261 tags: |262 type=ref,event=branch263 type=ref,event=tag264 type=sha,prefix=git-265 type=semver,pattern={{version}}266 type=semver,pattern={{major}}.{{minor}}267 type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama268 flavor: |269 latest=${{ github.ref == 'refs/heads/main' }}270 suffix=-ollama,onlatest=true271 272 - name: Extract metadata for Docker cache273 id: cache-meta274 uses: docker/metadata-action@v5275 with:276 images: ${{ env.FULL_IMAGE_NAME }}277 tags: |278 type=ref,event=branch279 ${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }}280 flavor: |281 prefix=cache-ollama-${{ matrix.platform }}-282 latest=false283 284 - name: Build Docker image (ollama)285 uses: docker/build-push-action@v5286 id: build287 with:288 context: .289 push: true290 platforms: ${{ matrix.platform }}291 labels: ${{ steps.meta.outputs.labels }}292 outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true293 cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}294 cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max295 build-args: |296 BUILD_HASH=${{ github.sha }}297 USE_OLLAMA=true298 299 - name: Export digest300 run: |301 mkdir -p /tmp/digests302 digest="${{ steps.build.outputs.digest }}"303 touch "/tmp/digests/${digest#sha256:}"304 305 - name: Upload digest306 uses: actions/upload-artifact@v4307 with:308 name: digests-ollama-${{ env.PLATFORM_PAIR }}309 path: /tmp/digests/*310 if-no-files-found: error311 retention-days: 1312 313 merge-main-images:314 runs-on: ubuntu-latest315 needs: [ build-main-image ]316 steps:317 # GitHub Packages requires the entire repository name to be in lowercase318 # although the repository owner has a lowercase username, this prevents some people from running actions after forking319 - name: Set repository and image name to lowercase320 run: |321 echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}322 echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}323 env:324 IMAGE_NAME: '${{ github.repository }}'325 326 - name: Download digests327 uses: actions/download-artifact@v4328 with:329 pattern: digests-main-*330 path: /tmp/digests331 merge-multiple: true332 333 - name: Set up Docker Buildx334 uses: docker/setup-buildx-action@v3335 336 - name: Log in to the Container registry337 uses: docker/login-action@v3338 with:339 registry: ${{ env.REGISTRY }}340 username: ${{ github.actor }}341 password: ${{ secrets.GITHUB_TOKEN }}342 343 - name: Extract metadata for Docker images (default latest tag)344 id: meta345 uses: docker/metadata-action@v5346 with:347 images: ${{ env.FULL_IMAGE_NAME }}348 tags: |349 type=ref,event=branch350 type=ref,event=tag351 type=sha,prefix=git-352 type=semver,pattern={{version}}353 type=semver,pattern={{major}}.{{minor}}354 flavor: |355 latest=${{ github.ref == 'refs/heads/main' }}356 357 - name: Create manifest list and push358 working-directory: /tmp/digests359 run: |360 docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \361 $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)362 363 - name: Inspect image364 run: |365 docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}366 367 368 merge-cuda-images:369 runs-on: ubuntu-latest370 needs: [ build-cuda-image ]371 steps:372 # GitHub Packages requires the entire repository name to be in lowercase373 # although the repository owner has a lowercase username, this prevents some people from running actions after forking374 - name: Set repository and image name to lowercase375 run: |376 echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}377 echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}378 env:379 IMAGE_NAME: '${{ github.repository }}'380 381 - name: Download digests382 uses: actions/download-artifact@v4383 with:384 pattern: digests-cuda-*385 path: /tmp/digests386 merge-multiple: true387 388 - name: Set up Docker Buildx389 uses: docker/setup-buildx-action@v3390 391 - name: Log in to the Container registry392 uses: docker/login-action@v3393 with:394 registry: ${{ env.REGISTRY }}395 username: ${{ github.actor }}396 password: ${{ secrets.GITHUB_TOKEN }}397 398 - name: Extract metadata for Docker images (default latest tag)399 id: meta400 uses: docker/metadata-action@v5401 with:402 images: ${{ env.FULL_IMAGE_NAME }}403 tags: |404 type=ref,event=branch405 type=ref,event=tag406 type=sha,prefix=git-407 type=semver,pattern={{version}}408 type=semver,pattern={{major}}.{{minor}}409 type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda410 flavor: |411 latest=${{ github.ref == 'refs/heads/main' }}412 suffix=-cuda,onlatest=true413 414 - name: Create manifest list and push415 working-directory: /tmp/digests416 run: |417 docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \418 $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)419 420 - name: Inspect image421 run: |422 docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}423 424 merge-ollama-images:425 runs-on: ubuntu-latest426 needs: [ build-ollama-image ]427 steps:428 # GitHub Packages requires the entire repository name to be in lowercase429 # although the repository owner has a lowercase username, this prevents some people from running actions after forking430 - name: Set repository and image name to lowercase431 run: |432 echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}433 echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}434 env:435 IMAGE_NAME: '${{ github.repository }}'436 437 - name: Download digests438 uses: actions/download-artifact@v4439 with:440 pattern: digests-ollama-*441 path: /tmp/digests442 merge-multiple: true443 444 - name: Set up Docker Buildx445 uses: docker/setup-buildx-action@v3446 447 - name: Log in to the Container registry448 uses: docker/login-action@v3449 with:450 registry: ${{ env.REGISTRY }}451 username: ${{ github.actor }}452 password: ${{ secrets.GITHUB_TOKEN }}453 454 - name: Extract metadata for Docker images (default ollama tag)455 id: meta456 uses: docker/metadata-action@v5457 with:458 images: ${{ env.FULL_IMAGE_NAME }}459 tags: |460 type=ref,event=branch461 type=ref,event=tag462 type=sha,prefix=git-463 type=semver,pattern={{version}}464 type=semver,pattern={{major}}.{{minor}}465 type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama466 flavor: |467 latest=${{ github.ref == 'refs/heads/main' }}468 suffix=-ollama,onlatest=true469 470 - name: Create manifest list and push471 working-directory: /tmp/digests472 run: |473 docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \474 $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)475 476 - name: Inspect image477 run: |478 docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}479 