Browse Source

bin/docker-start helper script (#956)

Co-authored-by: Mark Shust <mark@shust.com>
Co-authored-by: Dan Church <h3xx@users.noreply.github.com>
Neven Kajić 2 months ago
parent
commit
919ae17f4f
3 changed files with 55 additions and 0 deletions
  1. 1 0
      README.md
  2. 1 0
      compose/Makefile
  3. 53 0
      compose/bin/docker-start

+ 1 - 0
README.md

@@ -321,6 +321,7 @@ It is recommended to keep your root docker config files in one repository, and y
 - `bin/dev-urn-catalog-generate`: Generate URN's for PhpStorm and remap paths to local host. Restart PhpStorm after running this command.
 - `bin/devconsole`: Alias for `bin/n98-magerun2 dev:console`
 - `bin/docker-compose`: Support V1 (`docker-compose`) and V2 (`docker compose`) docker compose command, and use custom configuration files, such as `compose.yml` and `compose.dev.yml`
+- `bin/docker-start`: Start the Docker application (either Orbstack or Docker Desktop)
 - `bin/docker-stats`: Display container name and container ID, status for CPU, memory usage(in MiB and %), and memory limit of currently-running Docker containers.
 - `bin/download`: Download specific Magento version from Composer to the container, with optional arguments of the type ("community" [default], "enterprise", or "mageos") and version ([default] is defined in `bin/download`). Ex. `bin/download mageos` or `bin/download enterprise 2.4.7-p3`
 - `bin/ece-patches`: Run the Cloud Patches CLI. Ex: `bin/ece-tools apply`

+ 1 - 0
compose/Makefile

@@ -39,6 +39,7 @@ help:
 	@echo "$(call format,dev-urn-catalog-generate,'Generate URNs for PHPStorm and remap paths to local host.')"
 	@echo "$(call format,devconsole,'Alias for n98-magerun2 dev:console.')"
 	@echo "$(call format,docker-compose,'Support V1 (`docker-compose`) and V2 (`docker compose`) docker compose command, and use custom configuration files.')"
+	@echo "$(call format,docker-start,'Start the Docker application (either Orbstack or Docker Desktop)"
 	@echo "$(call format,docker-stats,'Display status for CPU$(comma) memory usage$(comma) and memory limit of currently-running Docker containers.')"
 	@echo "$(call format,download,'Download & extract specific Magento version to the src directory.')"
 	@echo "$(call format,ece-patches,'Run the Cloud Patches CLI.')"

+ 53 - 0
compose/bin/docker-start

@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+
+# Function to check if Docker daemon is running
+docker_running() {
+  docker stats --no-stream &> /dev/null
+  return $?
+}
+
+# Check if OrbStack is installed and not running
+if [ -d "/Applications/OrbStack.app" ]; then
+  echo "* OrbStack is installed"
+  
+  if (! docker_running); then
+    echo "* Starting OrbStack..."
+    open /Applications/OrbStack.app
+    
+    # Wait until Docker daemon is running via OrbStack
+    while (! docker_running); do
+      echo "* Waiting for OrbStack to initialize Docker..."
+      sleep 2
+    done
+    
+    echo "* Docker is now running via OrbStack"
+    exit 0
+  else
+    echo "* Docker is already running (possibly via OrbStack)"
+    exit 0
+  fi
+fi
+
+# Check if Docker Desktop is installed
+if [ -d "/Applications/Docker.app" ]; then
+  echo "* Docker Desktop is installed"
+  
+  # Check if Docker is running
+  if (! docker_running); then
+    echo "* Starting Docker Desktop..."
+    open /Applications/Docker.app
+    
+    # Wait until Docker daemon is running
+    while (! docker_running); do
+      echo "* Waiting for Docker Desktop to initialize..."
+      sleep 2
+    done
+    
+    echo "* Docker Desktop is now running"
+  else
+    echo "* Docker is already running"
+  fi
+else
+  echo "* Docker Desktop is not installed. Please install Docker Desktop or OrbStack."
+  exit 1
+fi