From 30d85430b4c3fdcccc4ba7b529354cfabbb58c69 Mon Sep 17 00:00:00 2001 From: Oliver Ye Date: Thu, 24 Oct 2024 13:07:50 +1100 Subject: [PATCH] update the github build script and push path --- .github/workflows/docker-release.yml | 5 +++-- .github/workflows/docker.yml | 6 +----- scripts/build_docker.py | 23 ++++++++++------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 73f4133848f81..6f6a022bb30d5 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -1,8 +1,9 @@ name: Docker Publish Release on: - release: - types: [published, edited] + push: + branches: + - "*" # Can be triggered manually workflow_dispatch: diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d02ad7326551a..590c756c4a3a7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,11 +3,7 @@ name: Docker on: push: branches: - - "master" - - "[0-9].[0-9]" - pull_request: - branches: - - "master" + - "*" concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} diff --git a/scripts/build_docker.py b/scripts/build_docker.py index 13453b61f96a7..ffe92ea6c49a1 100755 --- a/scripts/build_docker.py +++ b/scripts/build_docker.py @@ -83,7 +83,7 @@ def is_latest_release(release: str) -> bool: def make_docker_tag(l: list[str]) -> str: - return f"{REPO}:" + "-".join([o for o in l if o]) + return f"lemonyeah:" + "-".join([o for o in l if o]) def get_docker_tags( @@ -178,7 +178,7 @@ def get_docker_command( ) docker_tags = ("\\\n" + 8 * " ").join([f"-t {s} " for s in tags]) - docker_args = "--load" if not is_authenticated else "--push" + docker_args = "--load" target_argument = f"--target {build_target}" if build_target else "" cache_ref = f"{CACHE_REPO}:{py_ver}" @@ -189,19 +189,14 @@ def get_docker_command( platform_arg = "--platform " + ",".join(build_platforms) cache_from_arg = f"--cache-from=type=registry,ref={cache_ref}" - cache_to_arg = ( - f"--cache-to=type=registry,mode=max,ref={cache_ref}" if is_authenticated else "" - ) build_arg = f"--build-arg PY_VER={py_ver}" if py_ver else "" actor = os.getenv("GITHUB_ACTOR") - return dedent( + return {"command": dedent( f"""\ docker buildx build \\ - {docker_args} \\ {docker_tags} \\ {cache_from_arg} \\ - {cache_to_arg} \\ {build_arg} \\ {platform_arg} \\ {target_argument} \\ @@ -211,7 +206,7 @@ def get_docker_command( --label base={py_ver} \\ --label build_actor={actor} \\ {docker_context}""" - ) + ), "tags": tags} @click.command() @@ -259,7 +254,7 @@ def main( print("Release number has to be provided") exit(1) - docker_build_command = get_docker_command( + docker_build_result = get_docker_command( build_preset, platform, is_authenticated, @@ -271,20 +266,22 @@ def main( if not dry_run: print("Executing Docker Build Command:") - print(docker_build_command) + print(docker_build_result["command"]) script = "" if os.getenv("DOCKERHUB_USER"): script = dedent( f"""\ docker logout docker login --username "{os.getenv("DOCKERHUB_USER")}" --password "{os.getenv("DOCKERHUB_TOKEN")}" - DOCKER_ARGS="--push" """ ) - script = script + docker_build_command + script = script + docker_build_result["command"] if verbose: run_cmd("cat Dockerfile") stdout = run_cmd(script) + for tag in docker_build_result["tags"]: + script = script + dedent(f"docker image push {tag}") + stdout = run_cmd(script) else: print("Dry Run - Docker Build Command:") print(docker_build_command)