Skip to content

Commit

Permalink
tools: forcefully build without manifest checking (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
reliveyy authored Jun 18, 2020
1 parent 46239e4 commit a99814f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
17 changes: 7 additions & 10 deletions tools/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions tools/core/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion tools/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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":
Expand Down

0 comments on commit a99814f

Please sign in to comment.