diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 798c3d4..d19140c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -22,6 +22,15 @@ ], "problemMatcher": "$msCompile", "group": "build" + }, + { + "label": "Build Docker Image", + "type": "shell", + "command": "${workspaceFolder}\\.venv\\Scripts\\python.exe", + "args": [ + "${workspaceFolder}/docker/build_image.py" + ], + "problemMatcher": [] } ] } \ No newline at end of file diff --git a/docker/build_image.py b/docker/build_image.py new file mode 100644 index 0000000..02f7304 --- /dev/null +++ b/docker/build_image.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +import datetime as dt +import subprocess +from pathlib import Path + + +def get_timestamp_tag(today: dt.date) -> str: + year_suffix = today.year % 100 + day_of_year = today.timetuple().tm_yday + return f"{year_suffix}.{day_of_year}" + + +def main() -> int: + repo_root = Path(__file__).resolve().parents[1] + dockerfile_path = repo_root / "docker" / "Dockerfile" + + today = dt.date.today() + timestamp_tag = get_timestamp_tag(today) + + image_name = "troogs/astrain" + tags = ["latest", timestamp_tag] + + build_cmd = [ + "docker", + "build", + "-f", + str(dockerfile_path), + "-t", + f"{image_name}:{tags[0]}", + "-t", + f"{image_name}:{tags[1]}", + str(repo_root), + ] + + print(f"Building Docker image with tags: {', '.join(tags)}") + print(" ".join(build_cmd)) + + result = subprocess.run(build_cmd, cwd=str(repo_root)) + return result.returncode + + +if __name__ == "__main__": + raise SystemExit(main())