Skip to content

Commit

Permalink
ci(docker): optimize Docker build cache to prevent cache export failing
Browse files Browse the repository at this point in the history
- Added comment to specify that no_model build runs first to ensure code builds in the `docker_publish.yml` workflow
- Added a new job to run 'en' first in sequence to build the cache
- The job run includes steps such as freeing up disk space, checking out code, setting up Docker metadata, and Docker build and push
- Updated the `docker` job to run all other languages in parallel without cache export and wait for `docker-en` to finish

Signed-off-by: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed Nov 29, 2023
1 parent f9e7dfa commit f7c7abf
Showing 1 changed file with 84 additions and 3 deletions.
87 changes: 84 additions & 3 deletions .github/workflows/docker_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Run the no_model build first ensure that the code at least builds
docker-no_model:
# The type of runner that the job will run on
runs-on: ubuntu-latest
Expand Down Expand Up @@ -76,6 +77,88 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max

# Run en first in sequence to build the cache
docker-en:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 1
matrix:
lang:
- en
model:
- tiny
- base
- small
- medium
- large-v2
- large-v3
needs: docker-no_model # wait for docker-no_model to finish

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: true

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: false

- name: Checkout
uses: actions/checkout@v3
with:
submodules: true

- name: Docker meta data:${{ matrix.model }}-${{ matrix.lang }}
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository_owner }}/whisperx
flavor: |
latest=false
prefix=
suffix=
tags: |
${{ matrix.model}}-${{ matrix.lang }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Create a Access Token with `read:packages` and `write:packages` scopes
# CR_PAT
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- name: Build and push:${{ matrix.model }}-${{ matrix.lang }}
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
WHISPER_MODEL=${{ matrix.model }}
LANG=${{ matrix.lang }}
platforms: linux/amd64, linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

# Run all other languages in parallel without cache export
docker:
# The type of runner that the job will run on
runs-on: ubuntu-latest
Expand All @@ -84,7 +167,6 @@ jobs:
max-parallel: 10
matrix:
lang:
- en
- fr
- de
- es
Expand Down Expand Up @@ -117,7 +199,7 @@ jobs:
- medium
- large-v2
- large-v3
needs: docker-no_model # wait for docker-no_model to finish
needs: docker-en # wait for docker-en to finish

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down Expand Up @@ -179,4 +261,3 @@ jobs:
LANG=${{ matrix.lang }}
platforms: linux/amd64, linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit f7c7abf

Please sign in to comment.