Skip to content

CmampTask12104_Improve_release_flow_of_prod_image_for_runnable_dir #669

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

Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion devops/docker_build/prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#
ARG VERSION
ARG ECR_BASE_PATH
FROM ${ECR_BASE_PATH}/helpers:dev-${VERSION}
ARG IMAGE_NAME
FROM ${ECR_BASE_PATH}/${IMAGE_NAME}:dev-${VERSION}

RUN ls .
COPY . /app
10 changes: 9 additions & 1 deletion helpers/lib_tasks_docker_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,13 @@ def docker_build_prod_image( # type: ignore
opts = "--no-cache" if not cache else ""
# Use dev version for building prod image.
dev_version = hlitadoc.to_dev_version(prod_version)
image_name = hrecouti.get_repo_config().get_docker_base_image_name()
hdbg.dassert(
not hgit.is_inside_submodule(),
"The build should be run from a super repo, not a submodule.",
)
git_root_dir = hgit.find_git_root()
# TODO(heanh): Expose the build context to the interface and use `git_root_dir` by default.
cmd = rf"""
DOCKER_BUILDKIT={DOCKER_BUILDKIT} \
time \
Expand All @@ -809,7 +816,8 @@ def docker_build_prod_image( # type: ignore
--file {dockerfile} \
--build-arg VERSION={dev_version} \
--build-arg ECR_BASE_PATH={os.environ["CSFY_ECR_BASE_PATH"]} \
.
--build-arg IMAGE_NAME={image_name} \
{git_root_dir}
"""
hlitauti.run(ctx, cmd)
if candidate:
Expand Down
17 changes: 14 additions & 3 deletions helpers/test/test_lib_tasks_docker_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,27 @@ def set_up_test(self) -> None:
"os.environ", {"CSFY_ECR_BASE_PATH": "test.ecr.path"}
)
self.env_patcher.start()
self.get_docker_base_image_name_patcher = umock.patch(
"helpers.repo_config_utils.RepoConfig.get_docker_base_image_name"
)
self.mock_get_docker_base_image_name = (
self.get_docker_base_image_name_patcher.start()
)
#
self.patchers = [
self.system_patcher,
self.run_patcher,
self.version_patcher,
self.docker_login_patcher,
self.env_patcher,
self.get_docker_base_image_name_patcher,
]
# Test inputs.
self.mock_ctx = httestlib._build_mock_context_returning_ok()
self.test_version = "1.0.0"
self.test_base_image = "test-registry.com/test-image"
self.test_multi_arch = "linux/amd64,linux/arm64"
self.mock_get_docker_base_image_name.return_value = "test-image"

def tear_down_test(self) -> None:
"""
Expand Down Expand Up @@ -235,7 +243,8 @@ def test_docker_build_prod_image(self) -> None:
--file /app/devops/docker_build/prod.Dockerfile \
--build-arg VERSION=1.0.0 \
--build-arg ECR_BASE_PATH=test.ecr.path \
.
--build-arg IMAGE_NAME=test-image \
$GIT_ROOT
docker tag test-registry.com/test-image:prod-1.0.0 test-registry.com/test-image:prod
docker image ls test-registry.com/test-image:prod
"""
Expand Down Expand Up @@ -307,7 +316,8 @@ def test_docker_build_prod_image_with_candidate_tag(self) -> None:
--file /app/devops/docker_build/prod.Dockerfile \
--build-arg VERSION=1.0.0 \
--build-arg ECR_BASE_PATH=test.ecr.path \
.
--build-arg IMAGE_NAME=test-image \
$GIT_ROOT
docker image ls test-registry.com/test-image:prod-test_tag
"""
self._check_docker_command_output(exp, self.mock_run.call_args_list)
Expand Down Expand Up @@ -342,7 +352,8 @@ def test_docker_build_prod_image_with_candidate_user_tag(self) -> None:
--file /app/devops/docker_build/prod.Dockerfile \
--build-arg VERSION=1.0.0 \
--build-arg ECR_BASE_PATH=test.ecr.path \
.
--build-arg IMAGE_NAME=test-image \
$GIT_ROOT
docker image ls test-registry.com/test-image:prod-test_user-test_tag
"""
self._check_docker_command_output(exp, self.mock_run.call_args_list)
Loading