feat: add Docker image build script and update tasks configuration
This commit is contained in:
9
.vscode/tasks.json
vendored
9
.vscode/tasks.json
vendored
@@ -22,6 +22,15 @@
|
|||||||
],
|
],
|
||||||
"problemMatcher": "$msCompile",
|
"problemMatcher": "$msCompile",
|
||||||
"group": "build"
|
"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
44
docker/build_image.py
Normal 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())
|
||||||
Reference in New Issue
Block a user