feat: update Dockerfile to use fixed user and enhance directory ownership; add push command to docker.py for DockerHub integration
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Docker image commands."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import typer
|
||||
|
||||
@@ -10,6 +11,7 @@ app = typer.Typer(help="Build and manage Docker images.", no_args_is_help=True)
|
||||
|
||||
DOCKER_IMAGE = "python-dev"
|
||||
DOCKER_DIR = "docker/python-dev"
|
||||
DOCKERHUB_IMAGE = "roxauto/python-dev"
|
||||
|
||||
|
||||
@app.command()
|
||||
@@ -30,3 +32,20 @@ def build(
|
||||
f"{'--no-cache ' if no_cache else ''}"
|
||||
f"--network=host {DOCKER_DIR}",
|
||||
)
|
||||
|
||||
|
||||
@app.command()
|
||||
def push(tag: str = typer.Option("latest", help="Image tag.")):
|
||||
"""Tag and push the python-dev image to DockerHub."""
|
||||
token = os.environ.get("DOCKERHUB_TOKEN")
|
||||
if not token:
|
||||
typer.echo("DOCKERHUB_TOKEN env variable is not set.", err=True)
|
||||
raise typer.Exit(1)
|
||||
subprocess.run(
|
||||
["docker", "login", "-u", "roxauto", "--password-stdin"],
|
||||
input=token,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
run(f"docker tag {DOCKER_IMAGE}:{tag} {DOCKERHUB_IMAGE}:{tag}")
|
||||
run(f"docker push {DOCKERHUB_IMAGE}:{tag}")
|
||||
|
||||
Reference in New Issue
Block a user