Parcourir la source

Merge pull request #787 from rangerz/docker-compose

Mark Shust il y a 2 ans
Parent
commit
c973f918b4

+ 3 - 2
README.md

@@ -161,7 +161,7 @@ curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/te
 bin/download 2.4.5
 bin/download 2.4.5
 
 
 # or for Magento core development:
 # or for Magento core development:
-# docker-compose -f docker-compose.yml up -d
+# bin/docker-compose --no-dev up -d
 # bin/setup-composer-auth
 # bin/setup-composer-auth
 # bin/cli git clone git@github.com:magento/magento2.git .
 # bin/cli git clone git@github.com:magento/magento2.git .
 # bin/cli git checkout 2.4-develop
 # bin/cli git checkout 2.4-develop
@@ -191,7 +191,7 @@ cp -R ~/Sites/existing src
 # or: git clone git@github.com:myrepo.git src
 # or: git clone git@github.com:myrepo.git src
 
 
 # Start some containers, copy files to them and then restart the containers:
 # Start some containers, copy files to them and then restart the containers:
-docker-compose -f docker-compose.yml up -d
+bin/docker-compose --no-dev up -d
 bin/copytocontainer --all ## Initial copy will take a few minutes...
 bin/copytocontainer --all ## Initial copy will take a few minutes...
 
 
 # Import existing database:
 # Import existing database:
@@ -238,6 +238,7 @@ It is recommended to keep your root docker config files in one repository, and y
 - `bin/cron`: Start or stop the cron service. Ex. `bin/cron start`
 - `bin/cron`: Start or stop the cron service. Ex. `bin/cron start`
 - `bin/dev-urn-catalog-generate`: Generate URN's for PhpStorm and remap paths to local host. Restart PhpStorm after running this command.
 - `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/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 `docker-compose.yml` and `docker-compose.dev.yml`
 - `bin/download`: Download specific Magento version from Composer to the container, with an optional type of either "community" (default) or "enterprise". Ex. `bin/download 2.4.5 enterprise`
 - `bin/download`: Download specific Magento version from Composer to the container, with an optional type of either "community" (default) or "enterprise". Ex. `bin/download 2.4.5 enterprise`
 - `bin/fixowns`: This will fix filesystem ownerships within the container.
 - `bin/fixowns`: This will fix filesystem ownerships within the container.
 - `bin/fixperms`: This will fix filesystem permissions within the container.
 - `bin/fixperms`: This will fix filesystem permissions within the container.

+ 1 - 1
compose/bin/cli

@@ -1,3 +1,3 @@
 #!/bin/bash
 #!/bin/bash
 [ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
 [ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
-docker compose exec phpfpm "$@"
+bin/docker-compose exec phpfpm "$@"

+ 1 - 1
compose/bin/clinotty

@@ -1,4 +1,4 @@
 #!/bin/bash
 #!/bin/bash
 [ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
 [ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
 # -T: Disable pseudo-tty allocation
 # -T: Disable pseudo-tty allocation
-docker compose exec -T phpfpm "$@"
+bin/docker-compose exec -T phpfpm "$@"

+ 3 - 3
compose/bin/copyfromcontainer

@@ -3,13 +3,13 @@
 
 
 REAL_SRC=$(cd -P "src" && pwd)
 REAL_SRC=$(cd -P "src" && pwd)
 if [ "$1" == "--all" ]; then
 if [ "$1" == "--all" ]; then
-  docker cp "$(docker compose ps -q phpfpm|awk '{print $1}')":/var/www/html/./ "$REAL_SRC/"
+  docker cp "$(bin/docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/./ "$REAL_SRC/"
   echo "Completed copying all files from container to host"
   echo "Completed copying all files from container to host"
 else
 else
   if [ -f "$1" ] ; then
   if [ -f "$1" ] ; then
-    docker cp "$(docker compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1" "$REAL_SRC/$1"
+    docker cp "$(bin/docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1" "$REAL_SRC/$1"
   else
   else
-    docker cp "$(docker compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1" "$REAL_SRC/$(dirname "$1")"
+    docker cp "$(bin/docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1" "$REAL_SRC/$(dirname "$1")"
   fi
   fi
   echo "Completed copying $1 from container to host"
   echo "Completed copying $1 from container to host"
 fi
 fi

+ 3 - 3
compose/bin/copytocontainer

@@ -3,15 +3,15 @@
 
 
 REAL_SRC=$(cd -P "src" && pwd)
 REAL_SRC=$(cd -P "src" && pwd)
 if [ "$1" == "--all" ]; then
 if [ "$1" == "--all" ]; then
-  docker cp "$REAL_SRC/./" "$(docker compose ps -q phpfpm|awk '{print $1}')":/var/www/html/
+  docker cp "$REAL_SRC/./" "$(bin/docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/
   echo "Completed copying all files from host to container"
   echo "Completed copying all files from host to container"
   bin/fixowns
   bin/fixowns
   bin/fixperms
   bin/fixperms
 else
 else
   if [ -f "$REAL_SRC/$1" ]; then
   if [ -f "$REAL_SRC/$1" ]; then
-    docker cp "$REAL_SRC/${1}" "$(docker compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1"
+    docker cp "$REAL_SRC/${1}" "$(bin/docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1"
   else
   else
-    docker cp "$REAL_SRC/${1}" "$(docker compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$(dirname "$1")"
+    docker cp "$REAL_SRC/${1}" "$(bin/docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$(dirname "$1")"
   fi
   fi
   echo "Completed copying $1 from host to container"
   echo "Completed copying $1 from host to container"
   bin/fixowns "$1"
   bin/fixowns "$1"

+ 13 - 0
compose/bin/docker-compose

@@ -0,0 +1,13 @@
+#!/bin/bash
+
+if hash docker-compose 2>/dev/null; then
+  DOCKER_COMPOSE="docker-compose"
+else
+  DOCKER_COMPOSE="docker compose"
+fi
+
+if [ "$1" == "--no-dev" ]; then
+  ${DOCKER_COMPOSE} -f docker-compose.yml "${@:2}"
+else
+  ${DOCKER_COMPOSE} -f docker-compose.yml -f docker-compose.dev.yml "$@"
+fi

+ 1 - 1
compose/bin/download

@@ -14,7 +14,7 @@ else
   sed -i -e 's/7.4\-fpm\-15/8.1\-fpm\-1/g' docker-compose.yml
   sed -i -e 's/7.4\-fpm\-15/8.1\-fpm\-1/g' docker-compose.yml
 fi
 fi
 
 
-docker compose -f docker-compose.yml up -d
+bin/docker-compose --no-dev up -d
 [ $? != 0 ] && echo "Failed to start Docker services" && exit
 [ $? != 0 ] && echo "Failed to start Docker services" && exit
 
 
 bin/setup-composer-auth
 bin/setup-composer-auth

+ 1 - 1
compose/bin/redis

@@ -1,2 +1,2 @@
 #!/bin/bash
 #!/bin/bash
-docker compose exec redis "$@"
+bin/docker-compose exec redis "$@"

+ 1 - 1
compose/bin/remove

@@ -1,2 +1,2 @@
 #!/bin/bash
 #!/bin/bash
-docker compose -f docker-compose.yml -f docker-compose.dev.yml rm
+bin/docker-compose rm

+ 1 - 1
compose/bin/root

@@ -1,3 +1,3 @@
 #!/bin/bash
 #!/bin/bash
 [ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
 [ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
-docker compose exec -u root phpfpm "$@"
+bin/docker-compose exec -u root phpfpm "$@"

+ 1 - 1
compose/bin/rootnotty

@@ -1,3 +1,3 @@
 #!/bin/bash
 #!/bin/bash
 [ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
 [ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
-docker compose exec -u root -T phpfpm "$@"
+bin/docker-compose exec -u root -T phpfpm "$@"

+ 1 - 1
compose/bin/setup

@@ -18,7 +18,7 @@ DOMAIN=${1:-magento.test}
 
 
 bin/stop
 bin/stop
 
 
-docker compose -f docker-compose.yml up -d
+bin/docker-compose --no-dev up -d
 [ $? != 0 ] && echo "Failed to start Docker services" && exit
 [ $? != 0 ] && echo "Failed to start Docker services" && exit
 
 
 bin/clinotty chmod u+x bin/magento
 bin/clinotty chmod u+x bin/magento

+ 4 - 4
compose/bin/setup-ssl

@@ -2,15 +2,15 @@
 [ -z "$1" ] && echo "Please specify a domain (ex. mydomain.test)" && exit
 [ -z "$1" ] && echo "Please specify a domain (ex. mydomain.test)" && exit
 
 
 # Generate certificate authority if not already setup
 # Generate certificate authority if not already setup
-if ! docker compose exec -T -u root app cat /root/.local/share/mkcert/rootCA.pem | grep -q 'BEGIN CERTIFICATE'; then
+if ! bin/docker-compose exec -T -u root app cat /root/.local/share/mkcert/rootCA.pem | grep -q 'BEGIN CERTIFICATE'; then
   bin/setup-ssl-ca
   bin/setup-ssl-ca
 fi
 fi
 
 
 # Generate the certificate for the specified domain
 # Generate the certificate for the specified domain
-docker compose exec -T -u root app mkcert -key-file nginx.key -cert-file nginx.crt "$@"
+bin/docker-compose exec -T -u root app mkcert -key-file nginx.key -cert-file nginx.crt "$@"
 echo "Moving key and cert to /etc/nginx/certs/..."
 echo "Moving key and cert to /etc/nginx/certs/..."
-docker compose exec -T -u root app chown app:app nginx.key nginx.crt
-docker compose exec -T -u root app mv nginx.key nginx.crt /etc/nginx/certs/
+bin/docker-compose exec -T -u root app chown app:app nginx.key nginx.crt
+bin/docker-compose exec -T -u root app mv nginx.key nginx.crt /etc/nginx/certs/
 
 
 # Restart nginx to apply the updates
 # Restart nginx to apply the updates
 echo "Restarting containers to apply updates..."
 echo "Restarting containers to apply updates..."

+ 2 - 2
compose/bin/setup-ssl-ca

@@ -1,9 +1,9 @@
 #!/bin/bash
 #!/bin/bash
 set -o errexit
 set -o errexit
 # Generate a new local CA "/root/.local/share/mkcert"
 # Generate a new local CA "/root/.local/share/mkcert"
-docker compose exec -T -u root app mkcert -install
+bin/docker-compose exec -T -u root app mkcert -install
 
 
-docker cp "$(docker compose ps -q app|awk '{print $1}')":/root/.local/share/mkcert/rootCA.pem .
+docker cp "$(bin/docker-compose ps -q app|awk '{print $1}')":/root/.local/share/mkcert/rootCA.pem .
 echo "System password requested to install certificate authority on host..."
 echo "System password requested to install certificate authority on host..."
 
 
 if [ "$(uname)" == "Darwin" ]; then
 if [ "$(uname)" == "Darwin" ]; then

+ 1 - 1
compose/bin/start

@@ -52,7 +52,7 @@ done
 # Wait to exit until all missing files have been outputted to the user
 # Wait to exit until all missing files have been outputted to the user
 [ $IS_VALID = false ] && echo "Failed to start docker for missing volume files" && exit
 [ $IS_VALID = false ] && echo "Failed to start docker for missing volume files" && exit
 
 
-docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --remove-orphans "$@"
+bin/docker-compose up -d --remove-orphans "$@"
 
 
 ## Blackfire support
 ## Blackfire support
 ## ------------------
 ## ------------------

+ 1 - 1
compose/bin/status

@@ -1,2 +1,2 @@
 #!/bin/bash
 #!/bin/bash
-docker compose -f docker-compose.yml -f docker-compose.dev.yml ps
+bin/docker-compose ps

+ 1 - 1
compose/bin/stop

@@ -1,2 +1,2 @@
 #!/bin/bash
 #!/bin/bash
-docker compose -f docker-compose.yml -f docker-compose.dev.yml stop "$@"
+bin/docker-compose stop "$@"