2024-11-14 03:38:44 +01:00
|
|
|
import subprocess
|
2024-11-14 03:44:27 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2024-11-14 03:38:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def run_command(command: str) -> str:
|
|
|
|
process = subprocess.run(
|
|
|
|
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
|
|
|
)
|
|
|
|
if process.returncode != 0:
|
|
|
|
print(f"Error running command: {command}")
|
2024-11-14 03:44:27 +01:00
|
|
|
print(process.stderr.decode())
|
|
|
|
sys.exit(process.returncode)
|
2024-11-14 03:38:44 +01:00
|
|
|
return process.stdout.decode()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2024-11-14 03:50:21 +01:00
|
|
|
docker_compose_file = os.getenv("DOCKER_COMPOSE_FILE", "./app/docker-compose.yaml")
|
2024-11-14 03:44:27 +01:00
|
|
|
service_name = os.getenv("SERVICE_NAME", "webscraper")
|
|
|
|
script_name = os.getenv("SCRIPT_NAME", "main.py")
|
|
|
|
|
2024-11-14 03:38:44 +01:00
|
|
|
print("Starting Docker Compose services...\n")
|
2024-11-14 03:44:27 +01:00
|
|
|
run_command(f"docker compose -f {docker_compose_file} up -d")
|
2024-11-14 03:38:44 +01:00
|
|
|
|
2024-11-14 03:44:27 +01:00
|
|
|
print(run_command(f"docker exec {service_name} python {script_name}"))
|
2024-11-14 03:38:44 +01:00
|
|
|
|
|
|
|
print("Stopping and removing Docker Compose services...")
|
2024-11-14 03:44:27 +01:00
|
|
|
run_command(f"docker compose -f {docker_compose_file} down")
|
2024-11-14 03:38:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|