Skip to content
Merged
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
12 changes: 8 additions & 4 deletions webhook_server_container/libs/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ def _run_build_container(
tag=tag,
is_merged=is_merged,
)
no_cache = " --no-cache" if (tag or self.container_tag == _container_repository_and_tag.split(":")[-1]) else ""
no_cache = " --no-cache" if is_merged else ""
build_cmd = f"--network=host {no_cache} -f {self.container_repo_dir}/{self.dockerfile} . -t {_container_repository_and_tag}"

if self.container_build_args:
Expand All @@ -1489,7 +1489,7 @@ def _run_build_container(
build_cmd += f" && podman push --creds {repository_creds} {_container_repository_and_tag}"
podman_build_cmd = f"podman build {build_cmd}"

rc, out, err = self._run_in_container(command=podman_build_cmd, ignore_pull_request=is_merged is not None)
rc, out, err = self._run_in_container(command=podman_build_cmd, is_merged=is_merged)
output = {
"title": "Build container",
"summary": "",
Expand Down Expand Up @@ -1642,7 +1642,7 @@ def set_check_run_status(self, check_run, status=None, conclusion=None, output=N
self.repository_by_github_app.create_check_run(**kwargs)
return f"Done setting check run status: {kwargs}"

def _run_in_container(self, command, env=None, ignore_pull_request=False):
def _run_in_container(self, command, env=None, is_merged=False):
podman_base_cmd = (
"podman run --network=host --privileged -v /tmp/containers:/var/lib/containers/:Z "
f"--rm {env if env else ''} --entrypoint bash quay.io/myakove/github-webhook-server -c"
Expand All @@ -1659,8 +1659,12 @@ def _run_in_container(self, command, env=None, ignore_pull_request=False):
clone_base_cmd += " && git config --local --add remote.origin.fetch +refs/pull/*/head:refs/remotes/origin/pr/*"
clone_base_cmd += " && git remote update >/dev/null 2>&1"

# Checkout the branch if pull request is merged
if is_merged:
clone_base_cmd += f" && git checkout {self.pull_request_branch}"

# Checkout the pull request
if self.pull_request and not ignore_pull_request:
else:
clone_base_cmd += f" && git checkout origin/pr/{self.pull_request.number}"

# final podman command
Expand Down