From a8d1c65db2c22cc816fc48ca6c9d6a634b3c3301 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Thu, 18 Jun 2020 16:13:54 +0800 Subject: [PATCH] tools: forcefully build without manifest checking --- tools/core/image.py | 17 +++++++---------- tools/core/toolkit.py | 5 +++-- tools/helper.py | 3 ++- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tools/core/image.py b/tools/core/image.py index df03f9a18..bd7c20d36 100644 --- a/tools/core/image.py +++ b/tools/core/image.py @@ -195,23 +195,20 @@ def _buildx_build(self, args: List[str], build_dir: str, build_tag: str, platfor errmsg = "Failed to append application branch and revision labels to the image: {}".format(build_tag) self.run_command(cmd, errmsg) - def _build_platform(self, platform: Platform, no_cache: bool = False) -> bool: + def _build_platform(self, platform: Platform, no_cache: bool, force: bool) -> bool: prefix = "[_build_platform] ({})".format(platform) build_tag = self.get_build_tag(self.branch, platform) unmodified_history = self.context.get_unmodified_history(self) self._logger.debug("%s unmodified_history=%r", prefix, unmodified_history) - if self._skip_build(platform, unmodified_history): + self.print_title("Building {}".format(self.name), "{} ({})".format(self.tag, platform.tag_suffix)) + + if not force and self._skip_build(platform, unmodified_history): + print("Image is up-to-date. Skip building.") self._logger.debug("%s Skip building", prefix) - if platform == self.context.current_platform and "TRAVIS_BRANCH" not in os.environ: - tag = self.get_build_tag(self.branch) - self.run_command(f"docker pull {tag}", "Failed to pull " + tag) - self.run_command(f"docker tag {tag} {build_tag}", "Failed to re-tag " + tag) return False - self.print_title("Building {}".format(self.name), "{} ({})".format(self.tag, platform.tag_suffix)) - build_labels = self.get_labels(unmodified_history) build_dir = self.get_build_dir() @@ -252,11 +249,11 @@ def _build_platform(self, platform: Platform, no_cache: bool = False) -> bool: return True - def build(self, no_cache: bool = False) -> [Platform]: + def build(self, no_cache: bool = False, force: bool = False) -> [Platform]: os.chdir(self.context.project_dir + "/images") result = [] for p in self.context.platforms: - if self._build_platform(p, no_cache=no_cache): + if self._build_platform(p, no_cache=no_cache, force=force): result.append(p) return result diff --git a/tools/core/toolkit.py b/tools/core/toolkit.py index 906d2aeb4..ea8455345 100644 --- a/tools/core/toolkit.py +++ b/tools/core/toolkit.py @@ -121,6 +121,7 @@ def build(self, dry_run: bool = False, no_cache: bool = False, cross_build: bool = False, + force: bool = False, ) -> None: self._logger.debug("Build with images=%r, dry_run=%r, no_cache=%r, cross_build=%r", @@ -135,10 +136,10 @@ def build(self, if images: for name in images: - Image(ctx, name).build(no_cache=no_cache) + Image(ctx, name).build(no_cache=no_cache, force=force) else: for image in self.git_template.get_modified_images(ctx): - image.build(no_cache=no_cache) + image.build(no_cache=no_cache, force=force) def push(self, images: List[str] = None, diff --git a/tools/helper.py b/tools/helper.py index d37134985..788347765 100755 --- a/tools/helper.py +++ b/tools/helper.py @@ -12,6 +12,7 @@ def main(): build_parser.add_argument("--dry-run", action="store_true") build_parser.add_argument("--cross-build", action="store_true") build_parser.add_argument("--no-cache", action="store_true") + build_parser.add_argument("-f", "--force", action="store_true") build_parser.add_argument("images", type=str, nargs="*") push_parser = subparsers.add_parser("push") @@ -33,7 +34,7 @@ def main(): toolkit = Toolkit(project_dir, ["linux/amd64", "linux/arm64"]) if args.command == "build": - toolkit.build(args.images, args.dry_run, args.no_cache, args.cross_build) + toolkit.build(args.images, args.dry_run, args.no_cache, args.cross_build, args.force) elif args.command == "push": toolkit.push(args.images, args.dry_run, args.no_cache, args.cross_build, args.dirty_push) elif args.command == "test":