From e088fcbc7b5568a61d950c410d0fa6d34b2bcf98 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Sun, 24 Nov 2024 22:44:41 -0800 Subject: [PATCH] Build for arm64 on arm64 runner. Parallelize arm64, x64 docker builds - 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. --- .github/workflows/dockerize.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dockerize.yml b/.github/workflows/dockerize.yml index 0dc9a27e..619cd8b8 100644 --- a/.github/workflows/dockerize.yml +++ b/.github/workflows/dockerize.yml @@ -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}}