From fa8eceeba5a0e619933294b5fc26f725586c5784 Mon Sep 17 00:00:00 2001 From: K-shir0 <50326556+K-shir0@users.noreply.github.com> Date: Tue, 11 Apr 2023 01:18:05 +0900 Subject: [PATCH] =?UTF-8?q?Docker=20=E3=82=A4=E3=83=A1=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=82=92=E3=83=AA=E3=83=AA=E3=83=BC=E3=82=B9=E6=99=82=E3=81=AB?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E8=BF=BD=E5=8A=A0=20&=20ubuntu18=20=E3=82=92=E3=83=99?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=A8=E3=81=97=E3=81=9F=E3=82=A4=E3=83=A1?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=81=AE=E3=82=B5=E3=83=9D=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=82=92=E7=B5=82=E4=BA=86=20(#650)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-docker.yml | 48 ++++++----- .github/workflows/release-test-docker.yml | 98 +++++++++++++++++++++++ build_util/check_release_build.py | 20 +++-- 3 files changed, 136 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/release-test-docker.yml diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index aaa353f35..3c2c28c61 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -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: "" @@ -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 @@ -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: . @@ -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' }} @@ -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 \ No newline at end of file diff --git a/.github/workflows/release-test-docker.yml b/.github/workflows/release-test-docker.yml new file mode 100644 index 000000000..61019b2fd --- /dev/null +++ b/.github/workflows/release-test-docker.yml @@ -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/ diff --git a/build_util/check_release_build.py b/build_util/check_release_build.py index a01e571c9..71bf49c08 100644 --- a/build_util/check_release_build.py +++ b/build_util/check_release_build.py @@ -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") @@ -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)