Build for arm64 on arm64 runner. Parallelize arm64, x64 docker builds
Some checks failed
dockerize / Publish Khoj Docker Images (push) Has been cancelled
build and deploy github pages for documentation / deploy (push) Has been cancelled
pypi / Publish Python Package to PyPI (push) Has been cancelled

- Building arm64 image on an ubuntu arm64 runner reduces `yarn build'
  step time by 75% from 12mins to 3mins.
  - This is because no QEMU emulation for arm64 on x86 is required now
- Parallelizing x64 and arm64 platform builds halves build time on top
  - Revert to use standard ubuntu-latest runner as large x64 runner
    doesn't give much more speed improvements

This results an effective additional 50%-66% reduction in build time
on top of #987.

So a full dockerize workflow run now takes *10 mins* vs previous 35+mins.
This is a total of *72% improvement* in max dockerize run time.

Get additional speed improvements when docker layer cache hit.
This commit is contained in:
Debanjum 2024-11-24 22:44:41 -08:00
parent 5723a3778e
commit e088fcbc7b

View file

@ -38,13 +38,16 @@ env:
jobs:
build:
name: Publish Khoj Docker Images
runs-on: ubuntu-linux-x64-high
strategy:
fail-fast: false
matrix:
image:
- 'local'
- 'cloud'
platform:
- linux/amd64
- linux/arm64
runs-on: ${{ matrix.platform == 'linux/arm64' && 'ubuntu-linux-arm64' || 'ubuntu-latest' }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
@ -78,7 +81,7 @@ jobs:
with:
context: .
file: Dockerfile
platforms: linux/amd64, linux/arm64
platforms: ${{ matrix.platform }}
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ env.DOCKER_IMAGE_TAG }}
@ -86,8 +89,8 @@ jobs:
build-args: |
VERSION=${{ steps.hatch.outputs.version }}
PORT=42110
cache-from: type=gha,scope=${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ matrix.image }}
cache-from: type=gha,scope=${{ matrix.image }}-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=${{ matrix.image }}-${{ matrix.platform}}
- name: 📦️⛅️ Build and Push Cloud Docker Image
uses: docker/build-push-action@v4
@ -95,7 +98,7 @@ jobs:
with:
context: .
file: prod.Dockerfile
platforms: linux/amd64, linux/arm64
platforms: ${{ matrix.platform }}
push: true
tags: |
ghcr.io/${{ github.repository }}-cloud:${{ env.DOCKER_IMAGE_TAG }}
@ -103,5 +106,5 @@ jobs:
build-args: |
VERSION=${{ steps.hatch.outputs.version }}
PORT=42110
cache-from: type=gha,scope=${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ matrix.image }}
cache-from: type=gha,scope=${{ matrix.image }}-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=${{ matrix.image }}-${{ matrix.platform}}