Skip to content

Commit

Permalink
Docker イメージをリリース時にテストするように追加 & ubuntu18 をベースとしたイメージのサポートを終了 (VOICEVOX…
Browse files Browse the repository at this point in the history
  • Loading branch information
K-shir0 authored Apr 10, 2023
1 parent 78ef656 commit fa8ecee
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 30 deletions.
48 changes: 26 additions & 22 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,33 @@ env:
PYTHON_VERSION: "3.8.10"
VOICEVOX_RESOURCE_VERSION: "0.14.2"
VOICEVOX_CORE_VERSION: "0.14.3"
VOICEVOX_ENGINE_VERSION:
|- # releaseタグ名か、workflow_dispatchでのバージョン名か、latestが入る
${{ github.event.release.tag_name || github.event.inputs.version || 'latest' }}

jobs:
config: # 全 jobs で利用する定数の定義. `env` が利用できないコンテキストでも利用できる.
runs-on: ubuntu-latest
outputs:
version_or_latest: ${{ steps.vars.outputs.version_or_latest }}
steps:
- name: declare variables
id: vars
shell: bash
run: |
: # releaseタグ名か、workflow_dispatchでのバージョン名か、latestが入る
echo "version_or_latest=${{ github.event.release.tag_name || github.event.inputs.version || 'latest' }}" >> $GITHUB_OUTPUT
build-docker:
needs: [ config ]
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
os: [ ubuntu-latest ]
tag:
- ""
- cpu
- cpu-ubuntu20.04
- nvidia
- nvidia-ubuntu20.04
- cpu-ubuntu18.04
- nvidia-ubuntu18.04
include:
# Ubuntu 20.04
- tag: ""
Expand Down Expand Up @@ -68,19 +76,6 @@ jobs:
base_runtime_image: nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu20.04
onnxruntime_version: 1.13.1
platforms: linux/amd64
# Ubuntu 18.04
- tag: cpu-ubuntu18.04
target: runtime-env
base_image: ubuntu:18.04
base_runtime_image: ubuntu:18.04
onnxruntime_version: 1.13.1
platforms: linux/amd64,linux/arm64/v8
- tag: nvidia-ubuntu18.04
target: runtime-nvidia-env
base_image: ubuntu:18.04
base_runtime_image: nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu18.04
onnxruntime_version: 1.13.1
platforms: linux/amd64

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -128,8 +123,8 @@ jobs:
|- # If it's a release, add the version, otherwise add the `latest`
${{ (
matrix.tag != '' && (
format('{0}:{1}-{2}', env.IMAGE_NAME, matrix.tag, env.VOICEVOX_ENGINE_VERSION)
) || format('{0}:{1}', env.IMAGE_NAME, env.VOICEVOX_ENGINE_VERSION)
format('{0}:{1}-{2}', env.IMAGE_NAME, matrix.tag, needs.config.outputs.version_or_latest)
) || format('{0}:{1}', env.IMAGE_NAME, needs.config.outputs.version_or_latest)
) }}
with:
context: .
Expand All @@ -139,7 +134,7 @@ jobs:
BASE_IMAGE=${{ matrix.base_image }}
BASE_RUNTIME_IMAGE=${{ matrix.base_runtime_image }}
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
VOICEVOX_ENGINE_VERSION=${{ env.VOICEVOX_ENGINE_VERSION }}
VOICEVOX_ENGINE_VERSION=${{ needs.config.outputs.version_or_latest }}
VOICEVOX_CORE_VERSION=${{ env.VOICEVOX_CORE_VERSION }}
VOICEVOX_RESOURCE_VERSION=${{ env.VOICEVOX_RESOURCE_VERSION }}
USE_GPU=${{ matrix.target == 'runtime-nvidia-env' }}
Expand All @@ -150,3 +145,12 @@ jobs:
cache-from: type=registry,ref=${{ env.IMAGE_TAG }}-buildcache
cache-to: type=registry,ref=${{ env.IMAGE_TAG }}-buildcache,mode=max
platforms: ${{ matrix.platforms }}

run-release-test-workflow:
# version が指定されている場合のみ実行する
if: needs.config.outputs.version_or_latest != 'latest'
needs: [ config, build-docker ]
uses: ./.github/workflows/release-test-docker.yml
with:
version: ${{ needs.config.outputs.version }}
repo_url: ${{ format('{0}/{1}', github.server_url, github.repository) }} # このリポジトリのURL
98 changes: 98 additions & 0 deletions .github/workflows/release-test-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Test Docker Release Build

on:
workflow_call:
inputs:
version:
type: string
required: true
repo_url:
type: string
required: false
workflow_dispatch:
inputs:
version:
type: string
description: "テストしたいタグ名"
required: true

env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/voicevox_engine
VERSION: |- # version指定時はversionを、それ以外はタグ名を使用
${{ (github.event.inputs || inputs).version }}
jobs:
test:
runs-on: [ ubuntu-20.04 ]
strategy:
fail-fast: false
matrix:
tag:
- ""
- cpu
- cpu-ubuntu20.04

steps:
- uses: actions/checkout@v2

#
# Setup Python Environment
#
- uses: actions/setup-python@v2
with:
python-version: "3.8.10"
cache: pip

- name: Install libsndfile1
run: |
sudo apt-get update
sudo apt-get install libsndfile1
- name: Install requirements
run: |
pip install -r requirements-test.txt
#
# Setup Docker Environment
#
- name: Declare variables
id: docker_vars
run: |
if [ "${{ matrix.tag }}" != "" ]; then
echo "image_tag=${{ env.IMAGE_NAME }}:${{ matrix.tag }}-${{ env.VERSION }}" >> $GITHUB_OUTPUT
else
echo "image_tag=${{ env.IMAGE_NAME }}:${{ env.VERSION }}" >> $GITHUB_OUTPUT
fi
- name: Docker pull
run: docker pull ${{ steps.docker_vars.outputs.image_tag }}

- name: Docker run
run: docker run -d -p 50021:50021 ${{ steps.docker_vars.outputs.image_tag }}

# Docker コンテナが起動してから、レスポンスが返ってくるまで待機する
# リトライは10回まで `/version` にアクセスしてレスポンスのステータスコードをチェック
# - ステータスコードが `200` の場合は正常終了します
# - ステータスコードが `200` 以外の場合は、5秒間スリープしてリトライします
- name: Wait for container to start
shell: bash -xv {0}
run: |
url="http://127.0.0.1:50021/version"
max_attempts=10
sleep_interval=5
for i in $(seq 1 $max_attempts); do
status=$(curl -o /dev/null -s -w '%{http_code}\n' $url)
if [ $status -eq 200 ]; then
echo "Container is ready! Response status code: $status"
exit 0
else
echo "Attempt $i/$max_attempts: Response status code $status"
sleep $sleep_interval
fi
done
exit 1
- name: Test
shell: bash
run: python build_util/check_release_build.py --skip_run_process --dist_dir dist/
20 changes: 12 additions & 8 deletions build_util/check_release_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
base_url = "http://127.0.0.1:50021/"


def test_release_build(dist_dir: Path) -> None:
def test_release_build(dist_dir: Path, skip_run_process: bool) -> None:
run_file = dist_dir / "run"
if not run_file.exists():
run_file = dist_dir / "run.exe"

# 起動
process = Popen([run_file.absolute()], cwd=dist_dir)
time.sleep(120) # 待機
process = None
if not skip_run_process:
process = Popen([run_file.absolute()], cwd=dist_dir)
time.sleep(60) # 待機

# バージョン取得テスト
req = Request(base_url + "version")
Expand Down Expand Up @@ -52,15 +54,17 @@ def test_release_build(dist_dir: Path) -> None:
manifest = json.loads(res.read().decode("utf-8"))
assert "uuid" in manifest

# プロセスが稼働中であることを確認
assert process.poll() is None
if not skip_run_process:
# プロセスが稼働中であることを確認
assert process.poll() is None

# 停止
process.terminate()
# 停止
process.terminate()


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--dist_dir", type=Path, default=Path("dist/"))
parser.add_argument("--skip_run_process", action="store_true")
args = parser.parse_args()
test_release_build(dist_dir=args.dist_dir)
test_release_build(dist_dir=args.dist_dir, skip_run_process=args.skip_run_process)

0 comments on commit fa8ecee

Please sign in to comment.