-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DockerビルドCI: イメージタグの別名を別々にビルドしないようにする (#1498)
* Docker: イメージタグの別名を別々にビルドしないようにする * create tools/generate_docker_image_names.bash * comment: quote shell args * comment: improve examples * comment: improve examples * comment: improve examples * comment: 冗長な例を削除 * -eq -> = * fix SC2086: double quote $GITHUB_OUTPUT * fix wrong step output reference * remove shell: bash * コンフリクト解消時にUbuntu 22.04のincludeが増殖していたのを削除 * print usage to stderr * add matrix var descriptions * add comment * fix comment * update comment * fix buildcache image name: add repository * remove typo quote * create tools/generate_docker_image_names.py * pysen run format * update usage * fix B950 * Bashの行コメント"#"をdocstringに変えたときに消し忘れていたので削除 * コメントの表現修正: タグ名 -> Dockerイメージ名 * コメントの表現修正: タグ名 -> Dockerイメージ名 * コメントの表現修正: タグ名 -> Dockerイメージ名 * add --repository argument help * コメントの表現修正: 空文字 -> 空文字列 * helpの出力を末尾句点なしに統一 * Update .github/workflows/build-engine-container.yml Co-authored-by: Hiroshiba <[email protected]> * Update .github/workflows/build-engine-container.yml Co-authored-by: Hiroshiba <[email protected]> * Update tools/generate_docker_image_names.py Co-authored-by: Hiroshiba <[email protected]> * Update tools/generate_docker_image_names.py Co-authored-by: Hiroshiba <[email protected]> * Update tools/generate_docker_image_names.py Co-authored-by: Hiroshiba <[email protected]> * Update tools/generate_docker_image_names.py * Update .github/workflows/build-engine-container.yml * Update tools/generate_docker_image_names.py * Update tools/generate_docker_image_names.py * Update tools/generate_docker_image_names.py * pysen run format * Update .github/workflows/build-engine-container.yml Co-authored-by: Hiroshiba <[email protected]> * Update .github/workflows/build-engine-container.yml Co-authored-by: Hiroshiba <[email protected]> * Update tools/generate_docker_image_names.py Co-authored-by: Hiroshiba <[email protected]> * Update .github/workflows/build-engine-container.yml Co-authored-by: Hiroshiba <[email protected]> * Update .github/workflows/build-engine-container.yml Co-authored-by: Hiroshiba <[email protected]> * Update tools/generate_docker_image_names.py Co-authored-by: Hiroshiba <[email protected]> * Update .github/workflows/build-engine-container.yml Co-authored-by: Hiroshiba <[email protected]> * rename matrix.tags -> matrix.prefixes * rename buildcache_tag -> buildcache_prefix * lockファイルに更新があったっぽいので追従 * generate_docker_image_names: styling arguments * Update .github/workflows/build-engine-container.yml --------- Co-authored-by: Hiroshiba <[email protected]> Co-authored-by: Hiroshiba Kazuyuki <[email protected]>
- Loading branch information
1 parent
94b748f
commit a000c66
Showing
2 changed files
with
172 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
""" | ||
Dockerリポジトリ名、バージョン文字列、カンマ区切りのプレフィックスを受け取り、 | ||
バージョン文字列付きのDockerイメージ名を改行区切りで標準出力に出力する | ||
例 | ||
$ python3 ./tools/generate_docker_image_names.py \ | ||
--repository "REPO" \ | ||
--version "VER" \ | ||
--prefix ",A,B" | ||
REPO:VER | ||
REPO:A-VER | ||
REPO:B-VER | ||
$ python3 ./tools/generate_docker_image_names.py \ | ||
--repository "REPO" \ | ||
--version "VER" \ | ||
--prefix "" | ||
REPO:VER | ||
""" | ||
|
||
from argparse import ArgumentParser | ||
|
||
|
||
def generate_docker_image_names( | ||
repository: str, | ||
version: str, | ||
comma_separated_prefix: str, | ||
) -> list[str]: | ||
""" | ||
Dockerリポジトリ名、バージョン文字列、カンマ区切りのプレフィックスを受け取り、 | ||
バージョン文字列付きのDockerイメージ名を配列で返す | ||
prefixが空文字列でない場合、"{prefix}-{version}"をタグにする | ||
- 例: repository="REPO", version="VER", prefix="A" -> "REPO:A-VER" | ||
prefixが空文字列の場合、"{version}"をタグにする | ||
- 例: repository="REPO", version="VER", prefix="" -> "REPO:VER" | ||
Parameters | ||
---------- | ||
repository : str | ||
Dockerリポジトリ名 | ||
version : str | ||
バージョン文字列 | ||
comma_separated_prefix : str | ||
カンマ区切りのプレフィックス | ||
Returns | ||
------- | ||
list[str] | ||
Dockerイメージ名の配列。 | ||
Examples | ||
-------- | ||
>>> generate_docker_image_names("voicevox/voicevox_engine", "0.22.0", "cpu,cpu-ubuntu22.04") | ||
['voicevox/voicevox_engine:0.22.0', | ||
'voicevox/voicevox_engine:cpu-0.22.0', | ||
'voicevox/voicevox_engine:cpu-ubuntu22.04-0.22.0'] | ||
""" | ||
# カンマ区切りのタグ名を配列に変換 | ||
prefixes = comma_separated_prefix.split(",") | ||
|
||
# 戻り値の配列 | ||
docker_image_names: list[str] = [] | ||
|
||
for prefix in prefixes: | ||
# プレフィックスが空文字列でない場合、末尾にハイフンを付ける | ||
if prefix: | ||
prefix = f"{prefix}-" | ||
docker_image_names.append(f"{repository}:{prefix}{version}") | ||
|
||
return docker_image_names | ||
|
||
|
||
def main() -> None: | ||
parser = ArgumentParser() | ||
parser.add_argument( | ||
"--repository", | ||
type=str, | ||
required=True, | ||
help="Dockerリポジトリ名(例: voicevox/voicevox_engine)", | ||
) | ||
parser.add_argument( | ||
"--version", | ||
type=str, | ||
default="latest", | ||
help='バージョン文字列(例: "0.22.0", "latest")', | ||
) | ||
parser.add_argument( | ||
"--prefix", | ||
type=str, | ||
default="", | ||
help='カンマ区切りのプレフィックス(例: ",cpu,cpu-ubuntu22.04", "nvidia,nvidia-ubuntu22.04")', | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
repository: str = args.repository | ||
version: str = args.version | ||
comma_separated_prefix: str = args.prefix | ||
|
||
# Dockerイメージ名を生成 | ||
docker_image_names = generate_docker_image_names( | ||
repository=repository, | ||
version=version, | ||
comma_separated_prefix=comma_separated_prefix, | ||
) | ||
|
||
# 標準出力に出力 | ||
for docker_image_name in docker_image_names: | ||
print(docker_image_name) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |