feat: add Docker image build script and update tasks configuration

This commit is contained in:
2026-01-31 19:09:35 +01:00
parent e690a649e8
commit 2e69f0d5ef
2 changed files with 53 additions and 0 deletions

9
.vscode/tasks.json vendored
View File

@@ -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": []
}
]
}

44
docker/build_image.py Normal file
View File

@@ -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())