setup 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. set -o errexit
  3. MEM=$(docker info | grep "Total Memory" | cut -d':' -f2 | xargs | sed s/GiB//)
  4. # Docker reports RAM 0.2 less than what it is actually set to
  5. (( $(echo "$MEM < 5.8" | bc -l) )) && echo "There must be at least 6GB of RAM allocated to Docker to continue." && exit
  6. # shellcheck source=../env/db.env
  7. source env/db.env
  8. # shellcheck source=../env/elasticsearch.env
  9. source env/elasticsearch.env
  10. # shellcheck source=../env/magento.env
  11. source env/magento.env
  12. # shellcheck source=../env/rabbitmq.env
  13. source env/rabbitmq.env
  14. DOMAIN=${1:-magento.test}
  15. bin/stop
  16. docker compose -f docker-compose.yml up -d
  17. [ $? != 0 ] && echo "Failed to start Docker services" && exit
  18. bin/clinotty chmod u+x bin/magento
  19. rm -rf src && mkdir src
  20. echo "Adding Magento modules to Composer allow-plugins directive..."
  21. bin/clinotty composer config --no-plugins allow-plugins.magento/magento-composer-installer true
  22. bin/clinotty composer config --no-plugins allow-plugins.magento/inventory-composer-installer true
  23. bin/clinotty composer config --no-plugins allow-plugins.laminas/laminas-dependency-plugin true
  24. echo "Waiting for connection to Elasticsearch..."
  25. bin/clinotty timeout $ES_HEALTHCHECK_TIMEOUT bash -c "
  26. until curl --silent --output /dev/null http://$ES_HOST:$ES_PORT/_cat/health?h=st; do
  27. printf '.'
  28. sleep 2
  29. done"
  30. [ $? != 0 ] && echo "Failed to connect to Elasticsearch" && exit
  31. echo ""
  32. echo "Waiting for connection to RabbitMQ..."
  33. bin/clinotty timeout $RABBITMQ_HEALTHCHECK_TIMEOUT bash -c "
  34. until curl --silent --output /dev/null http://$RABBITMQ_DEFAULT_USER:$RABBITMQ_DEFAULT_PASS@$RABBITMQ_HOST:$RABBITMQ_MANAGEMENT_PORT/api/aliveness-test/%2F; do
  35. printf '.'
  36. sleep 2
  37. done"
  38. [ $? != 0 ] && echo "Failed to connect to RabbitMQ" && exit
  39. bin/clinotty bin/magento setup:install \
  40. --db-host="$MYSQL_HOST" \
  41. --db-name="$MYSQL_DATABASE" \
  42. --db-user="$MYSQL_USER" \
  43. --db-password="$MYSQL_PASSWORD" \
  44. --base-url=https://"$DOMAIN"/ \
  45. --base-url-secure=https://"$DOMAIN"/ \
  46. --backend-frontname="$MAGENTO_ADMIN_FRONTNAME" \
  47. --admin-firstname="$MAGENTO_ADMIN_FIRST_NAME" \
  48. --admin-lastname="$MAGENTO_ADMIN_LAST_NAME" \
  49. --admin-email="$MAGENTO_ADMIN_EMAIL" \
  50. --admin-user="$MAGENTO_ADMIN_USER" \
  51. --admin-password="$MAGENTO_ADMIN_PASSWORD" \
  52. --language="$MAGENTO_LOCALE" \
  53. --currency="$MAGENTO_CURRENCY" \
  54. --timezone="$MAGENTO_TIMEZONE" \
  55. --amqp-host="$RABBITMQ_HOST" \
  56. --amqp-port="$RABBITMQ_PORT" \
  57. --amqp-user="$RABBITMQ_DEFAULT_USER" \
  58. --amqp-password="$RABBITMQ_DEFAULT_PASS" \
  59. --amqp-virtualhost="$RABBITMQ_DEFAULT_VHOST" \
  60. --cache-backend=redis \
  61. --cache-backend-redis-server=redis \
  62. --cache-backend-redis-db=0 \
  63. --page-cache=redis \
  64. --page-cache-redis-server=redis \
  65. --page-cache-redis-db=1 \
  66. --session-save=redis \
  67. --session-save-redis-host=redis \
  68. --session-save-redis-log-level=4 \
  69. --session-save-redis-db=2 \
  70. --search-engine=elasticsearch7 \
  71. --elasticsearch-host=$ES_HOST \
  72. --elasticsearch-port=$ES_PORT \
  73. --use-rewrites=1 \
  74. --no-interaction
  75. echo "Copying files from container to host after install..."
  76. bin/copyfromcontainer --all
  77. echo "Forcing deploy of static content to speed up initial requests..."
  78. bin/clinotty bin/magento setup:static-content:deploy -f
  79. echo "Re-indexing with Elasticsearch..."
  80. bin/clinotty bin/magento indexer:reindex
  81. echo "Setting basic URL and generating SSL certificate..."
  82. bin/setup-domain "${DOMAIN}"
  83. echo "Fixing owner and permissions..."
  84. bin/fixowns
  85. bin/fixperms
  86. echo "Clearing the cache to apply updates..."
  87. bin/clinotty bin/magento cache:flush
  88. echo "Installing cron, run 'bin/cron start' to enable..."
  89. bin/clinotty bin/magento cron:install
  90. echo "Turning on developer mode..."
  91. bin/clinotty bin/magento deploy:mode:set developer
  92. cp -r .vscode src/
  93. echo "Docker development environment setup complete."
  94. echo "You may now access your Magento instance at https://${DOMAIN}/"