File size: 1,208 Bytes
82bf89e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

import subprocess
from datetime import datetime
from pathlib import Path
from typing import Annotated
import typer


def main(

    tag: Annotated[str | None, typer.Option(help="Image tag")] = None,
    dockerfile: Annotated[Path | None, typer.Option(help="Dockerfile path")] = None,
    docker_cmd: Annotated[str, typer.Option(help="docker command")] = "docker",
):
    git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("UTF-8").strip()[:8]
    timestamp = datetime.now().strftime("%Y%m%d")
    if tag is None:
        tag_val = f"{timestamp}-{git_hash}"
    else:
        tag_val = tag

    if dockerfile is None:
        # Default to Dockerfile next to this script
        dockerfile = Path(__file__).parent / "Dockerfile"

    image_name = f"review_mcp:{tag_val}"
    print(f"[bold green]Building image {image_name}[/bold green]")
    subprocess.run(
        [
            docker_cmd,
            "build",
            "-t",
            image_name,
            "-f",
            str(dockerfile),
            str(Path(__file__).parent),
        ],
        check=True,
    )
    print(f"[bold blue]Built image {image_name}[/bold blue]")

if __name__ == "__main__":
    typer.run(main)