Last active
November 14, 2025 07:05
-
-
Save sumanchapai/4d324b15cf1bbd2fbd295c6fb5a1bc4d to your computer and use it in GitHub Desktop.
helper script to build/tag and push to docker. follows a convention to save latest tag name in a file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| from pathlib import Path | |
| # --- SETTINGS --- | |
| username = "sumanchapai" | |
| folder_name = "bean-docker" | |
| local_docker_image_name = folder_name | |
| remote_docker_image_name = f"{username}/{folder_name}" | |
| version_file = Path(".dockerversion") | |
| # --- HELPERS --- | |
| def yes(msg: str = "Do you want to proceed?") -> bool: | |
| got = input(f"{msg} (Y/n): ").strip().lower() | |
| return got in ("", "y", "yes") | |
| def ask_and_run_cmd(cmd: str): | |
| print("\nAttempting to run:") | |
| print(" ", cmd) | |
| if yes(): | |
| subprocess.run(cmd, shell=True, check=True) | |
| else: | |
| print("Aborted.") | |
| exit(1) | |
| # --- MAIN --- | |
| if not version_file.exists(): | |
| print( | |
| version_file, "doesn't exist. create one and specify your latest version there" | |
| ) | |
| exit(1) # <-- FIXED: os.exit() does not exist; use exit() or sys.exit() | |
| with open(version_file) as fd: | |
| current_version = fd.read().strip() | |
| print("Current version:", current_version) | |
| new_version = input("Enter new version: ").strip() | |
| if not new_version: | |
| print("No version entered. Exiting.") | |
| exit(1) | |
| # Update the version file | |
| with open(version_file, "w") as fd: | |
| fd.write(new_version) | |
| ask_and_run_cmd( | |
| f"docker buildx build " | |
| f"--platform linux/amd64,linux/arm64 " | |
| f"-t {remote_docker_image_name}:{new_version} " | |
| f"-t {remote_docker_image_name}:latest " | |
| f"--push ." | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment