Skip to content

Commit

Permalink
[ci] Build and push docker image on release pr pipeline (#37981)
Browse files Browse the repository at this point in the history
Always build docker image for release branch pr

Signed-off-by: can <can@anyscale.com>
  • Loading branch information
can-anyscale authored Aug 2, 2023
1 parent b47c408 commit ddc55c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
34 changes: 14 additions & 20 deletions ci/build/build-docker-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

IMAGE_NAMES = list(DOCKER_HUB_DESCRIPTION.keys())

IS_PR_BUILD = os.environ.get("BUILDKITE_PULL_REQUEST") != "false"
RELEASE_PR_PIPELINE_ID = "d912884a-5198-497d-9ac3-178420500b6e"


def _with_suffix(tag: str, suffix: Optional[str] = None):
Expand Down Expand Up @@ -495,20 +495,19 @@ def _tag_and_push(
old_tag,
new_tag,
merge_build=False,
push_pr_build=False,
release_pr_build=False,
):
# Do not tag release builds because they are no longer up to
# date after the branch cut.
if "nightly" in new_tag and (_release_build() or IS_PR_BUILD):
if "nightly" in new_tag and (_release_build() or release_pr_build):
return
if old_tag != new_tag:
DOCKER_CLIENT.api.tag(
image=f"{full_image_name}:{old_tag}",
repository=full_image_name,
tag=new_tag,
)
should_push = merge_build or (push_pr_build and IS_PR_BUILD)
if not should_push:
if not merge_build and not release_pr_build:
print(
"Not pushing build. "
"Otherwise we would have pushed to: {full_image_name}:{new_tag}"
Expand Down Expand Up @@ -611,17 +610,17 @@ def push_and_tag_images(
py_versions: List[str],
image_types: List[str],
merge_build: bool = False,
release_pr_build: bool = False,
image_list: Optional[List[str]] = None,
suffix: Optional[str] = None,
push_pr_build: bool = False,
):
date_tag = datetime.datetime.now().strftime("%Y-%m-%d")
sha_tag = _get_commit_sha()
if _release_build():
release_name = _get_branch()[len("releases/") :]
date_tag = release_name + "." + date_tag
sha_tag = release_name + "." + sha_tag
if IS_PR_BUILD:
if release_pr_build:
pr = f"pr-{os.environ['BUILDKITE_PULL_REQUEST']}"
date_tag = pr + "." + date_tag
sha_tag = pr + "." + sha_tag
Expand Down Expand Up @@ -723,7 +722,7 @@ def push_and_tag_images(
old_tag=old_tag,
new_tag=new_tag,
merge_build=merge_build,
push_pr_build=push_pr_build,
release_pr_build=release_pr_build,
)


Expand Down Expand Up @@ -770,9 +769,10 @@ def push_readmes(merge_build: bool):
MERGE = "MERGE"
HUMAN = "HUMAN"
PR = "PR"
RELEASE_PR = "RELEASE_PR"
BUILDKITE = "BUILDKITE"
LOCAL = "LOCAL"
BUILD_TYPES = [MERGE, HUMAN, PR, BUILDKITE, LOCAL]
BUILD_TYPES = [MERGE, HUMAN, PR, RELEASE_PR, BUILDKITE, LOCAL]


@click.command()
Expand Down Expand Up @@ -815,21 +815,13 @@ def push_readmes(merge_build: bool):
default=False,
help="Whether only to build ray-worker-container",
)
@click.option(
"--push-pr-build",
is_flag=True,
show_default=True,
default=False,
help="Whether to push PR builds to Docker Hub",
)
def main(
py_versions: Tuple[str],
device_types: Tuple[str],
build_type: str,
suffix: Optional[str] = None,
build_base: bool = True,
only_build_worker_container: bool = False,
push_pr_build: bool = False,
):
py_versions = (
list(py_versions) if isinstance(py_versions, (list, tuple)) else [py_versions]
Expand Down Expand Up @@ -878,14 +870,16 @@ def main(
if build_type == BUILDKITE:
if os.environ.get("BUILDKITE_PULL_REQUEST", "") == "false":
build_type = MERGE
elif os.environ.get("BUILDKITE_PIPELINE_ID", "") == RELEASE_PR_PIPELINE_ID:
build_type = RELEASE_PR
else:
build_type = PR

if build_type == HUMAN:
# If manually triggered, request user for branch and SHA value to use.
_configure_human_version()
if (
build_type in {HUMAN, MERGE, BUILDKITE, LOCAL}
build_type in {HUMAN, MERGE, BUILDKITE, LOCAL, RELEASE_PR}
or _check_if_docker_files_modified()
or only_build_worker_container
):
Expand Down Expand Up @@ -956,17 +950,17 @@ def main(
all_tagged_images, target_dir="/artifact-mount/.image-info"
)

if build_type in {MERGE, PR}:
if build_type in {MERGE, RELEASE_PR}:
valid_branch = _valid_branch()
if (not valid_branch) and is_merge:
print(f"Invalid Branch found: {_get_branch()}")
push_and_tag_images(
py_versions,
image_types,
merge_build=valid_branch and is_merge,
release_pr_build=build_type == RELEASE_PR,
image_list=images_to_tag_and_push,
suffix=suffix,
push_pr_build=push_pr_build,
)

# TODO(ilr) Re-Enable Push READMEs by using a normal password
Expand Down
6 changes: 3 additions & 3 deletions release/ray_release/byod/build_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def _get_build(py_version: str) -> Dict[str, Any]:
"pip install -q docker aws_requests_auth boto3",
"./ci/env/env_info.sh",
"python .buildkite/copy_files.py --destination docker_login",
"python ./ci/build/build-docker-images.py "
f"--py-versions {py_version} -T cpu -T cu118 "
"--build-type BUILDKITE --build-base --push-pr-build",
f"python ./ci/build/build-docker-images.py --py-versions {py_version} "
"-T cpu -T cu118 --build-type BUILDKITE --build-base",
]
return {
"label": py_version,
Expand Down Expand Up @@ -99,6 +98,7 @@ def _get_build(py_version: str) -> Dict[str, Any]:
"BUILDKITE_BUILD_ID",
"BUILDKITE_MESSAGE",
"BUILDKITE_BUILD_NUMBER",
"BUILDKITE_PIPELINE_ID",
],
"mount-checkout": "false",
},
Expand Down

0 comments on commit ddc55c0

Please sign in to comment.