Skip to content

Commit e90e409

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

File tree

11 files changed

+164
-296
lines changed

11 files changed

+164
-296
lines changed

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

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,44 +1164,68 @@ jobs:
11641164
name: '' # use filename
11651165
path: "*.zip"
11661166
release-tag: ${{ needs.create-release.outputs.release-tag }}
1167-
docker-build:
1168-
name: "Build Dockerfile.build image"
1167+
docker-train-build:
1168+
name: "Build Docker training images"
11691169
runs-on: ubuntu-20.04
1170+
strategy:
1171+
matrix:
1172+
arch: ["amd64"]
11701173
steps:
11711174
- uses: actions/checkout@v2
11721175
with:
11731176
fetch-depth: 0
11741177
submodules: 'recursive'
1178+
- name: Log in to the Container registry
1179+
uses: docker/login-action@v1
1180+
with:
1181+
registry: ghcr.io
1182+
username: ${{ github.actor }}
1183+
password: ${{ secrets.GITHUB_TOKEN }}
11751184
- name: Check VERSION matches Git tag and compute Docker tag
11761185
id: compute-tag
11771186
run: |
1178-
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
1187+
set -ex
1188+
base="ghcr.io/coqui-ai/stt-train"
1189+
if [[ "${{ github.ref }}" = "refs/heads/main" ]]; then
1190+
# Push to main
1191+
tags="${base}:main_${{ matrix.arch }},${base}:${{ github.sha }}_${{ matrix.arch }}"
1192+
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
11791193
# PR build
1180-
echo "::set-output name=tag::dev"
1194+
tags="${base}:dev_${{ matrix.arch }}"
11811195
else
11821196
VERSION="v$(cat VERSION)"
11831197
if [[ "${{ github.ref }}" != "refs/tags/${VERSION}" ]]; then
11841198
echo "Pushed tag does not match VERSION file. Aborting push."
11851199
exit 1
11861200
fi
1187-
echo "::set-output name=tag::${VERSION}"
1201+
tags="${base}:${VERSION}_${{ matrix.arch }},${base}:latest_${{ matrix.arch }},${base}:${{ github.sha }}_${{ matrix.arch }}"
11881202
fi
1189-
- name: Build
1190-
run: |
1191-
DOCKER_TAG="${{ steps.compute-tag.outputs.tag }}"
1192-
docker build -f Dockerfile.build . -t ghcr.io/coqui-ai/stt-build:latest -t "ghcr.io/coqui-ai/stt-build:${DOCKER_TAG}"
1193-
docker-publish:
1194-
name: "Build and publish Docker training image to GHCR"
1203+
echo "::set-output name=tags::${tags}"
1204+
- name: Set up QEMU
1205+
uses: docker/setup-qemu-action@v1
1206+
- name: Set up Docker Buildx
1207+
id: buildx
1208+
uses: docker/setup-buildx-action@v1
1209+
- name: Generate version info for build
1210+
run: |
1211+
make -C native_client/ctcdecode workspace_status.cc
1212+
- name: Build and push
1213+
uses: docker/build-push-action@v2
1214+
with:
1215+
context: .
1216+
file: Dockerfile.train
1217+
platforms: linux/${{ matrix.arch }}
1218+
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
1219+
tags: ${{ steps.compute-tag.outputs.tags }}
1220+
docker-train-manifest:
1221+
name: "Publish Docker training manifest to GHCR"
11951222
runs-on: ubuntu-20.04
1196-
needs: [upload-nc-release-assets]
1197-
if: always()
1223+
needs: [docker-train-build]
1224+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
11981225
steps:
11991226
- uses: actions/checkout@v2
1200-
with:
1201-
fetch-depth: 0
1202-
submodules: 'recursive'
12031227
- name: Log in to the Container registry
1204-
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
1228+
uses: docker/login-action@v1
12051229
with:
12061230
registry: ghcr.io
12071231
username: ${{ github.actor }}
@@ -1210,36 +1234,34 @@ jobs:
12101234
id: compute-tag
12111235
run: |
12121236
set -ex
1237+
base="ghcr.io/coqui-ai/stt-train"
12131238
if [[ "${{ github.ref }}" = "refs/heads/main" ]]; then
12141239
# Push to main
1215-
tags="main ${{ github.sha }}"
1240+
tags="${base}:main,${base}:${{ github.sha }}"
12161241
elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
12171242
# PR build
1218-
tags="dev"
1243+
tags="${base}:dev"
12191244
else
12201245
VERSION="v$(cat VERSION)"
12211246
if [[ "${{ github.ref }}" != "refs/tags/${VERSION}" ]]; then
12221247
echo "Pushed tag does not match VERSION file. Aborting push."
12231248
exit 1
12241249
fi
1225-
tags="${VERSION} latest ${{ github.sha }}"
1250+
tags="${base}:${VERSION},${base}:latest,${base}:${{ github.sha }}"
12261251
fi
12271252
echo "::set-output name=tags::${tags}"
1228-
- name: Build
1229-
run: |
1230-
set -ex
1231-
declare -a tag_args=()
1232-
for tag in ${{ steps.compute-tag.outputs.tags }}; do
1233-
tag_args+=("-t" "ghcr.io/coqui-ai/stt-train:${tag}")
1234-
done
1235-
docker build -f Dockerfile.train . ${tag_args[@]}
1236-
- name: Push
1237-
run: |
1238-
set -ex
1239-
for tag in ${{ steps.compute-tag.outputs.tags }}; do
1240-
docker push ghcr.io/coqui-ai/stt-train:${tag}
1253+
- name: Create and push manifest
1254+
run: |
1255+
docker manifest create ghcr.io/coqui-ai/stt-train
1256+
base=${{ steps.compute-tag.outputs.tags }}
1257+
should_push=${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
1258+
for tag in $(echo $base | sed 's/,/ /g'); do
1259+
docker manifest create $tag \
1260+
--amend ${tag}_amd64
1261+
if [[ "$should_push" == "true" ]]; then
1262+
docker manifest push $tag
1263+
fi
12411264
done
1242-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
12431265
twine-upload-decoder:
12441266
name: "Upload coqui_stt_ctcdecoder packages to PyPI"
12451267
runs-on: ubuntu-20.04

Dockerfile.build

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

0 commit comments

Comments
 (0)