2
0

setup 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "Waiting for connection to Elasticsearch..."
  21. bin/clinotty timeout $ES_HEALTHCHECK_TIMEOUT bash -c "
  22. until curl --silent --output /dev/null http://$ES_HOST:$ES_PORT/_cat/health?h=st; do
  23. printf '.'
  24. sleep 2
  25. done"
  26. [ $? != 0 ] && echo "Failed to connect to Elasticsearch" && exit
  27. echo ""
  28. echo "Waiting for connection to RabbitMQ..."
  29. bin/clinotty timeout $RABBITMQ_HEALTHCHECK_TIMEOUT bash -c "
  30. until curl --silent --output /dev/null http://$RABBITMQ_DEFAULT_USER:$RABBITMQ_DEFAULT_PASS@$RABBITMQ_HOST:$RABBITMQ_MANAGEMENT_PORT/api/aliveness-test/%2F; do
  31. printf '.'
  32. sleep 2
  33. done"
  34. [ $? != 0 ] && echo "Failed to connect to RabbitMQ" && exit
  35. bin/clinotty bin/magento setup:install \
  36. --db-host="$MYSQL_HOST" \
  37. --db-name="$MYSQL_DATABASE" \
  38. --db-user="$MYSQL_USER" \
  39. --db-password="$MYSQL_PASSWORD" \
  40. --base-url=https://"$DOMAIN"/ \
  41. --base-url-secure=https://"$DOMAIN"/ \
  42. --backend-frontname="$MAGENTO_ADMIN_FRONTNAME" \
  43. --admin-firstname="$MAGENTO_ADMIN_FIRST_NAME" \
  44. --admin-lastname="$MAGENTO_ADMIN_LAST_NAME" \
  45. --admin-email="$MAGENTO_ADMIN_EMAIL" \
  46. --admin-user="$MAGENTO_ADMIN_USER" \
  47. --admin-password="$MAGENTO_ADMIN_PASSWORD" \
  48. --language="$MAGENTO_LOCALE" \
  49. --currency="$MAGENTO_CURRENCY" \
  50. --timezone="$MAGENTO_TIMEZONE" \
  51. --amqp-host="$RABBITMQ_HOST" \
  52. --amqp-port="$RABBITMQ_PORT" \
  53. --amqp-user="$RABBITMQ_DEFAULT_USER" \
  54. --amqp-password="$RABBITMQ_DEFAULT_PASS" \
  55. --amqp-virtualhost="$RABBITMQ_DEFAULT_VHOST" \
  56. --cache-backend=redis \
  57. --cache-backend-redis-server=redis \
  58. --cache-backend-redis-db=0 \
  59. --page-cache=redis \
  60. --page-cache-redis-server=redis \
  61. --page-cache-redis-db=1 \
  62. --session-save=redis \
  63. --session-save-redis-host=redis \
  64. --session-save-redis-log-level=4 \
  65. --session-save-redis-db=2 \
  66. --search-engine=elasticsearch7 \
  67. --elasticsearch-host=$ES_HOST \
  68. --elasticsearch-port=$ES_PORT \
  69. --use-rewrites=1 \
  70. --no-interaction
  71. echo "Copying files from container to host after install..."
  72. bin/copyfromcontainer --all
  73. echo "Forcing deploy of static content to speed up initial requests..."
  74. bin/clinotty bin/magento setup:static-content:deploy -f
  75. echo "Re-indexing with Elasticsearch..."
  76. bin/clinotty bin/magento indexer:reindex
  77. echo "Setting basic URL and generating SSL certificate..."
  78. bin/setup-domain "${DOMAIN}"
  79. echo "Clearing the cache to apply updates..."
  80. bin/clinotty bin/magento cache:flush
  81. echo "Installing cron, run 'bin/cron start' to enable..."
  82. bin/clinotty bin/magento cron:install
  83. echo "Turning on developer mode..."
  84. bin/clinotty bin/magento deploy:mode:set developer
  85. mv .vscode src/
  86. echo "Docker development environment setup complete."
  87. echo "You may now access your Magento instance at https://${DOMAIN}/"