45 lines
1017 B
Python
45 lines
1017 B
Python
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())
|