2024-11-14 03:38:44 +01:00
|
|
|
import subprocess
|
2024-11-14 03:44:27 +01:00
|
|
|
import os
|
2024-11-15 22:39:49 +01:00
|
|
|
from run_command import run_command
|
2024-11-16 00:05:50 +01:00
|
|
|
from get_path import get_path
|
2024-11-14 03:38:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2024-11-15 22:39:49 +01:00
|
|
|
try:
|
2024-12-18 01:41:12 +01:00
|
|
|
docker_compose_file = os.getenv(
|
|
|
|
"DOCKER_COMPOSE_FILE", f"{get_path()}/app/docker-compose.yaml"
|
|
|
|
)
|
|
|
|
service_name = os.getenv("SERVICE_NAME", "scraper")
|
|
|
|
script_name = os.getenv("SCRIPT_NAME", "main.py")
|
|
|
|
try:
|
|
|
|
print("Starting Docker Compose services...\n")
|
|
|
|
run_command(f"docker compose -f {docker_compose_file} up -d")
|
2024-11-14 03:44:27 +01:00
|
|
|
|
2024-12-18 01:41:12 +01:00
|
|
|
print(run_command(f"docker exec -it {service_name} xvfb-run --auto-servernum --server-num=1 --server-args='-screen 0, 1920x1080x24' python3 {script_name}"))
|
2024-11-14 03:38:44 +01:00
|
|
|
|
2024-12-18 01:41:12 +01:00
|
|
|
print("Stopping and removing Docker Compose services...")
|
|
|
|
run_command(f"docker compose -f {docker_compose_file} down")
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print("An error occurred while running the script.")
|
|
|
|
print(e)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("Keyboard interrupt detected. Exiting...")
|
|
|
|
run_command(f"docker compose -f {docker_compose_file} down")
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("Keyboard interrupt detected. Exiting...")
|
2024-11-15 22:39:49 +01:00
|
|
|
run_command(f"docker compose -f {docker_compose_file} down")
|
2024-11-14 03:38:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|