Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8/n][pipeline-gen] Add method to generate build step #48

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion scripts/pipeline_generator/pipeline_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from pydantic import BaseModel, field_validator

from .step import BuildkiteStep, BuildkiteBlockStep, TestStep
from .utils import VLLM_ECR_URL, VLLM_ECR_REPO
from .utils import VLLM_ECR_URL, VLLM_ECR_REPO, AgentQueue
from .pipeline_generator_helper import get_build_commands

class PipelineGeneratorConfig:
def __init__(
Expand Down Expand Up @@ -43,6 +44,24 @@ def __init__(
config.validate()
self.config = config

def generate_build_step(self) -> BuildkiteStep:
"""Build the Docker image and push it to container registry."""
build_commands = get_build_commands(self.config.container_registry, self.config.commit, self.config.container_image)

return BuildkiteStep(
label=":docker: build image",
key="build",
agents={"queue": AgentQueue.AWS_CPU.value},
env={"DOCKER_BUILDKIT": "1"},
retry={
"automatic": [
{"exit_status": -1, "limit": 2},
{"exit_status": -10, "limit": 2}
]
},
commands=build_commands,
depends_on=None,
)

def read_test_steps(file_path: str) -> List[TestStep]:
"""Read test steps from test pipeline yaml and parse them into TestStep objects."""
Expand Down
26 changes: 26 additions & 0 deletions scripts/pipeline_generator/pipeline_generator_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import List

def get_build_commands(container_registry: str, buildkite_commit: str, container_image: str) -> List[str]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any unit test? or is this so simple that does not require one?

maybe we should have some form of integration test to test these commands.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just replacing placeholders for container registry, container image, and commit so I don't think unit test is needed here.

ecr_login_command = (
"aws ecr-public get-login-password --region us-east-1 | "
f"docker login --username AWS --password-stdin {container_registry}"
)
image_check_command = f"""#!/bin/bash
if [[ -z $(docker manifest inspect {container_image}) ]]; then
echo "Image not found, proceeding with build..."
else
echo "Image found"
exit 0
fi
"""
docker_build_command = (
f"docker build "
f"--build-arg max_jobs=64 "
f"--build-arg buildkite_commit={buildkite_commit} "
f"--build-arg USE_SCCACHE=1 "
f"--tag {container_image} "
f"--target test "
f"--progress plain ."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you leave a todo here to not using . to include everything as the build context?

)
docker_push_command = f"docker push {container_image}"
return [ecr_login_command, image_check_command, docker_build_command, docker_push_command]
Loading