Initialisation depot
This commit is contained in:
64
samba-api/build.py
Executable file
64
samba-api/build.py
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Build script for Samba API Docker image
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
def run_command(command, check=True):
|
||||
"""Run shell command and return result"""
|
||||
print(f"Running: {command}")
|
||||
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||
|
||||
if check and result.returncode != 0:
|
||||
print(f"Error running command: {command}")
|
||||
print(f"Error output: {result.stderr}")
|
||||
sys.exit(1)
|
||||
|
||||
return result
|
||||
|
||||
def build_image(tag, push=False, registry=None):
|
||||
"""Build Docker image"""
|
||||
|
||||
# Build image
|
||||
build_cmd = f"docker build -t samba-api:{tag} ."
|
||||
if registry:
|
||||
build_cmd = f"docker build -t {registry}/samba-api:{tag} ."
|
||||
|
||||
run_command(build_cmd)
|
||||
|
||||
# Tag as latest
|
||||
if tag != "latest":
|
||||
if registry:
|
||||
run_command(f"docker tag {registry}/samba-api:{tag} {registry}/samba-api:latest")
|
||||
else:
|
||||
run_command(f"docker tag samba-api:{tag} samba-api:latest")
|
||||
|
||||
# Push if requested
|
||||
if push and registry:
|
||||
run_command(f"docker push {registry}/samba-api:{tag}")
|
||||
run_command(f"docker push {registry}/samba-api:latest")
|
||||
print(f"Image pushed to registry: {registry}/samba-api:{tag}")
|
||||
|
||||
print(f"Build completed: samba-api:{tag}")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Build Samba API Docker image")
|
||||
parser.add_argument("--tag", default="latest", help="Docker image tag")
|
||||
parser.add_argument("--push", action="store_true", help="Push image to registry")
|
||||
parser.add_argument("--registry", help="Docker registry (required if --push is used)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.push and not args.registry:
|
||||
print("Error: --registry is required when --push is used")
|
||||
sys.exit(1)
|
||||
|
||||
build_image(args.tag, args.push, args.registry)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user