feat: enhance Docker command execution with environment variable support
Some checks are pending
Docker Image CI / build (push) Waiting to run

This commit is contained in:
patilk 2024-11-14 03:44:27 +01:00
parent cf45719d66
commit d303dd4204
Signed by: s500042
GPG Key ID: 1921AD722E7392EE

View File

@ -1,4 +1,6 @@
import subprocess
import os
import sys
def run_command(command: str) -> str:
@ -7,18 +9,23 @@ def run_command(command: str) -> str:
)
if process.returncode != 0:
print(f"Error running command: {command}")
return process.stderr.decode()
print(process.stderr.decode())
sys.exit(process.returncode)
return process.stdout.decode()
def main():
print("Starting Docker Compose services...\n")
run_command("docker compose -f ../app/docker-compose.yaml up -d")
docker_compose_file = os.getenv("DOCKER_COMPOSE_FILE", "../app/docker-compose.yaml")
service_name = os.getenv("SERVICE_NAME", "webscraper")
script_name = os.getenv("SCRIPT_NAME", "main.py")
print(run_command("docker exec -it webscraper python main.py"))
print("Starting Docker Compose services...\n")
run_command(f"docker compose -f {docker_compose_file} up -d")
print(run_command(f"docker exec {service_name} python {script_name}"))
print("Stopping and removing Docker Compose services...")
run_command("docker compose -f ../app/docker-compose.yaml down")
run_command(f"docker compose -f {docker_compose_file} down")
if __name__ == "__main__":