forked from VOICEVOX/voicevox_engine
-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (187 loc) · 9.21 KB
/
build-engine-container.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: build-docker
on:
push:
branches:
- master
- feature/docker-commonize-hash-of-same-feature-image-latest
release:
types:
- created
workflow_dispatch:
inputs:
version:
description: "バージョン情報(A.BB.C / A.BB.C-preview.D)"
required: true
env:
IMAGE_NAME: ${{ vars.DOCKERHUB_USERNAME }}/voicevox_engine
VOICEVOX_RESOURCE_VERSION: "0.22-preview.0"
VOICEVOX_CORE_VERSION: "0.15.5"
defaults:
run:
shell: bash
jobs:
config: # 全 jobs で利用する定数の定義. `env` が利用できないコンテキストでも利用できる.
runs-on: ubuntu-latest
outputs:
version_or_latest: ${{ steps.vars.outputs.version_or_latest }}
steps:
- name: <Setup> Declare variables
id: vars
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: ubuntu-latest
strategy:
matrix:
# 各変数の説明
# tags: カンマ区切りのタグ名(バージョン文字列の前のプレフィックス)。空文字列の場合、バージョン文字列のみのタグ名になる
# buildcache_tag: ビルドキャッシュのタグ名(latestの前のプレフィックス)。空文字列やカンマは使用不可
# target: Dockerfile のビルドステージ名
# base_image: Dockerfile のビルド変数 BASE_IMAGE に渡すベースイメージ
# base_runtime_image: Dockerfile のビルド変数 BASE_RUNTIME_IMAGE に渡す実行ステージ用のベースイメージ
# onnxruntime_version: Dockerfile のビルド変数 ONNXRUNTIME_VERSION に渡すONNX Runtimeのバージョン
# platforms: docker build コマンドのオプション --platform に渡すプラットフォーム
include:
# Ubuntu 20.04
- tags: ",cpu,cpu-ubuntu20.04"
buildcache_tag: "cpu-ubuntu20.04"
target: runtime-env
base_image: ubuntu:20.04
base_runtime_image: ubuntu:20.04
onnxruntime_version: 1.13.1
platforms: linux/amd64,linux/arm64/v8
- tags: "nvidia,nvidia-ubuntu20.04"
buildcache_tag: "nvidia-ubuntu20.04"
target: runtime-nvidia-env
base_image: ubuntu:20.04
base_runtime_image: nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu20.04
onnxruntime_version: 1.13.1
platforms: linux/amd64
# Ubuntu 22.04
- tags: "cpu-ubuntu22.04"
buildcache_tag: "cpu-ubuntu22.04"
target: runtime-env
base_image: ubuntu:22.04
base_runtime_image: ubuntu:22.04
onnxruntime_version: 1.13.1
platforms: linux/amd64,linux/arm64/v8
- tags: "nvidia-ubuntu22.04"
buildcache_tag: "nvidia-ubuntu22.04"
target: runtime-nvidia-env
base_image: ubuntu:22.04
base_runtime_image: nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
onnxruntime_version: 1.13.1
platforms: linux/amd64
steps:
- name: <Setup> Check out the repository
uses: actions/checkout@v4
- name: <Setup> Prepare Python version
id: prepare-python
uses: ./.github/actions/prepare_python
with:
only-export-python-version: true
- name: <Setup> Set up QEMU
uses: docker/setup-qemu-action@v3
- name: <Setup> Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: <Setup> Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: <Setup> Prepare VOICEVOX RESOURCE cache
uses: actions/cache@v4
id: voicevox-resource-cache
with:
key: voicevox-resource-${{ env.VOICEVOX_RESOURCE_VERSION }}
path: download/resource
- name: <Setup> Check out the VOICEVOX RESOURCE repository
if: steps.voicevox-resource-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: VOICEVOX/voicevox_resource
ref: ${{ env.VOICEVOX_RESOURCE_VERSION }}
path: download/resource
- name: <Build> Merge VOICEVOX RESOURCE
env:
DOWNLOAD_RESOURCE_PATH: download/resource
run: bash tools/process_voicevox_resource.bash
# Matrixのtags(カンマ区切りのタグ名)から、バージョン文字列付きのタグ名を生成する
#
# 例1: tags=",cpu,cpu-ubuntu22.04", version="0.22.0"
# voicevox/voicevox_engine:0.22.0
# voicevox/voicevox_engine:cpu-0.22.0
# voicevox/voicevox_engine:cpu-ubuntu22.04-0.22.0
#
# 例2: tags="nvidia,nvidia-ubuntu22.04", version="latest"
# voicevox/voicevox_engine:nvidia-latest
# voicevox/voicevox_engine:nvidia-ubuntu22.04-latest
- name: <Build> Generate Docker image names
id: generate-docker-image-names
run: |
# バージョン文字列付きのタグ名を steps.generate-docker-image-names.outputs.tags に改行区切りで格納する
{
echo "tags<<EOF"
# Usage: $0 <repository> [version_or_latest] [comma_separated_prefixes]
bash tools/generate_docker_image_names.bash "${{ env.IMAGE_NAME }}" "${{ needs.config.outputs.version_or_latest }}" "${{ matrix.tags }}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
# ビルドキャッシュ(docker build コマンドのオプション --cache-from と --cache-to)に指定するためのタグ名を生成する
#
# 例1: buildcache_tag="cpu-ubuntu22.04", version="latest"
# cache-from: type=registry,ref=voicevox/voicevox_engine:cpu-ubuntu22.04-latest-buildcache
# cache-to: type=registry,ref=voicevox/voicevox_engine:cpu-ubuntu22.04-latest-buildcache,mode=max
#
# 例2: buildcache_tag="nvidia-ubuntu22.04", version="0.22.0"
# cache-from: type=registry,ref=voicevox/voicevox_engine:nvidia-ubuntu22.04-latest-buildcache
# cache-to: (空文字列)
- name: <Build> Generate Docker buildcache image names
id: generate-docker-buildcache-image-names
run: |
# --cache-from に指定するためのタグ名を steps.generate-docker-buildcache-image-names.outputs.cache-from に格納する
# 常にデフォルトブランチのビルドキャッシュ(*-latest-buildcache)を使用する
# 例: type=registry,ref=voicevox/voicevox_engine:cpu-ubuntu22.04-latest-buildcache
echo "cache-from=type=registry,ref=${{ env.IMAGE_NAME }}:${{ matrix.buildcache_tag }}-latest-buildcache" >> "$GITHUB_OUTPUT"
# --cache-to に指定するためのタグ名を steps.generate-docker-buildcache-image-names.outputs.cache-to に格納する
# リリースの場合、ビルドキャッシュを作成しないため、空文字列を格納する
# 例: type=registry,ref=voicevox/voicevox_engine:cpu-ubuntu22.04-latest-buildcache,mode=max
{
echo "cache-to<<EOF"
if [ "${{ needs.config.outputs.version_or_latest }}" = "latest" ]; then
# デフォルトブランチへのコミットの場合( needs.config.outputs.version_or_latest = "latest" )、ビルドキャッシュを作成する
echo "type=registry,ref=${{ env.IMAGE_NAME }}:${{ matrix.buildcache_tag }}-latest-buildcache,mode=max"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: <Build/Deploy> Build and Deploy Docker image
uses: docker/build-push-action@v5
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: ./Dockerfile
build-args: |
BASE_IMAGE=${{ matrix.base_image }}
BASE_RUNTIME_IMAGE=${{ matrix.base_runtime_image }}
PYTHON_VERSION=${{ steps.prepare-python.outputs.python-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' }}
ONNXRUNTIME_VERSION=${{ matrix.onnxruntime_version }}
target: ${{ matrix.target }}
push: true
tags: ${{ steps.generate-docker-image-names.outputs.tags }}
cache-from: ${{ steps.generate-docker-buildcache-image-names.outputs.cache-from }}
cache-to: ${{ steps.generate-docker-buildcache-image-names.outputs.cache-to }}
platforms: ${{ matrix.platforms }}
run-release-test-workflow:
# version が指定されている場合のみ実行する
if: needs.config.outputs.version_or_latest != 'latest'
needs: [config, build-docker]
uses: ./.github/workflows/test-engine-container.yml
with:
version: ${{ needs.config.outputs.version_or_latest }}
repo_url: ${{ format('{0}/{1}', github.server_url, github.repository) }} # このリポジトリのURL