Skip to content

Commit 70ab05b

Browse files
committed
[docker/train] Build binary artifacts in the image, improve layer caching, prepare for multi-arch build
1 parent efb202b commit 70ab05b

File tree

11 files changed

+161
-299
lines changed

11 files changed

+161
-299
lines changed

.github/workflows/build-and-test.yml

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,44 +1194,68 @@ jobs:
11941194
name: '' # use filename
11951195
path: "*.zip"
11961196
release-tag: ${{ needs.create-release.outputs.release-tag }}
1197-
docker-build:
1198-
name: "Build Dockerfile.build image"
1197+
docker-train-build:
1198+
name: "Build Docker training images"
11991199
runs-on: ubuntu-20.04
1200+
strategy:
1201+
matrix:
1202+
arch: ["amd64"]
12001203
steps:
12011204
- uses: actions/checkout@v2
12021205
with:
12031206
fetch-depth: 0
12041207
submodules: 'recursive'
1208+
- name: Log in to the Container registry
1209+
uses: docker/login-action@v1
1210+
with:
1211+
registry: ghcr.io
1212+
username: ${{ github.actor }}
1213+
password: ${{ secrets.GITHUB_TOKEN }}
12051214
- name: Check VERSION matches Git tag and compute Docker tag
12061215
id: compute-tag
12071216
run: |
1208-
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
1217+
set -ex
1218+
base="ghcr.io/coqui-ai/stt-train"
1219+
if [[ "${{ github.ref }}" = "refs/heads/main" ]]; then
1220+
# Push to main
1221+
tags="${base}:main_${{ matrix.arch }},${base}:${{ github.sha }}_${{ matrix.arch }}"
1222+
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
12091223
# PR build
1210-
echo "::set-output name=tag::dev"
1224+
tags="${base}:dev_${{ matrix.arch }}"
12111225
else
12121226
VERSION="v$(cat VERSION)"
12131227
if [[ "${{ github.ref }}" != "refs/tags/${VERSION}" ]]; then
12141228
echo "Pushed tag does not match VERSION file. Aborting push."
12151229
exit 1
12161230
fi
1217-
echo "::set-output name=tag::${VERSION}"
1231+
tags="${base}:${VERSION}_${{ matrix.arch }},${base}:latest_${{ matrix.arch }},${base}:${{ github.sha }}_${{ matrix.arch }}"
12181232
fi
1219-
- name: Build
1220-
run: |
1221-
DOCKER_TAG="${{ steps.compute-tag.outputs.tag }}"
1222-
docker build -f Dockerfile.build . -t ghcr.io/coqui-ai/stt-build:latest -t "ghcr.io/coqui-ai/stt-build:${DOCKER_TAG}"
1223-
docker-publish:
1224-
name: "Build and publish Docker training image to GHCR"
1233+
echo "::set-output name=tags::${tags}"
1234+
- name: Set up QEMU
1235+
uses: docker/setup-qemu-action@v1
1236+
- name: Set up Docker Buildx
1237+
id: buildx
1238+
uses: docker/setup-buildx-action@v1
1239+
- name: Generate version info for build
1240+
run: |
1241+
make -C native_client/ctcdecode workspace_status.cc
1242+
- name: Build and push
1243+
uses: docker/build-push-action@v2
1244+
with:
1245+
context: .
1246+
file: Dockerfile.train
1247+
platforms: linux/${{ matrix.arch }}
1248+
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
1249+
tags: ${{ steps.compute-tag.outputs.tags }}
1250+
docker-train-manifest:
1251+
name: "Publish Docker training manifest to GHCR"
12251252
runs-on: ubuntu-20.04
1226-
needs: [upload-nc-release-assets]
1227-
if: always()
1253+
needs: [docker-train-build]
1254+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
12281255
steps:
12291256
- uses: actions/checkout@v2
1230-
with:
1231-
fetch-depth: 0
1232-
submodules: 'recursive'
12331257
- name: Log in to the Container registry
1234-
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
1258+
uses: docker/login-action@v1
12351259
with:
12361260
registry: ghcr.io
12371261
username: ${{ github.actor }}
@@ -1240,36 +1264,34 @@ jobs:
12401264
id: compute-tag
12411265
run: |
12421266
set -ex
1267+
base="ghcr.io/coqui-ai/stt-train"
12431268
if [[ "${{ github.ref }}" = "refs/heads/main" ]]; then
12441269
# Push to main
1245-
tags="main ${{ github.sha }}"
1270+
tags="${base}:main,${base}:${{ github.sha }}"
12461271
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
12471272
# PR build
1248-
tags="dev"
1273+
tags="${base}:dev"
12491274
else
12501275
VERSION="v$(cat VERSION)"
12511276
if [[ "${{ github.ref }}" != "refs/tags/${VERSION}" ]]; then
12521277
echo "Pushed tag does not match VERSION file. Aborting push."
12531278
exit 1
12541279
fi
1255-
tags="${VERSION} latest ${{ github.sha }}"
1280+
tags="${base}:${VERSION},${base}:latest,${base}:${{ github.sha }}"
12561281
fi
12571282
echo "::set-output name=tags::${tags}"
1258-
- name: Build
1259-
run: |
1260-
set -ex
1261-
declare -a tag_args=()
1262-
for tag in ${{ steps.compute-tag.outputs.tags }}; do
1263-
tag_args+=("-t" "ghcr.io/coqui-ai/stt-train:${tag}")
1264-
done
1265-
docker build -f Dockerfile.train . ${tag_args[@]}
1266-
- name: Push
1267-
run: |
1268-
set -ex
1269-
for tag in ${{ steps.compute-tag.outputs.tags }}; do
1270-
docker push ghcr.io/coqui-ai/stt-train:${tag}
1283+
- name: Create and push manifest
1284+
run: |
1285+
docker manifest create ghcr.io/coqui-ai/stt-train
1286+
base=${{ steps.compute-tag.outputs.tags }}
1287+
should_push=${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
1288+
for tag in $(echo $base | sed 's/,/ /g'); do
1289+
docker manifest create $tag \
1290+
--amend ${tag}_amd64
1291+
if [[ "$should_push" == "true" ]]; then
1292+
docker manifest push $tag
1293+
fi
12711294
done
1272-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
12731295
twine-upload-decoder:
12741296
name: "Upload coqui_stt_ctcdecoder packages to PyPI"
12751297
runs-on: ubuntu-20.04

Dockerfile.build

Lines changed: 0 additions & 185 deletions
This file was deleted.

0 commit comments

Comments
 (0)