setup 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. BASE_URL=${1:-magento2.test}
  3. bin/stop
  4. # fix for invalid google-shopping-api checksum contained in archive installs (temporary fix until nexcess archive is patched)
  5. sed -e 's/5f5929ef9f2ec4ca048a2add261d22c92807630f/ce31e720d60451784b9fdb3769e43e149f50d436/' src/composer.lock > composer.lock && mv composer.lock src/composer.lock
  6. docker-compose -f docker-compose.yml up -d
  7. sleep 1 #Ensure containers are started...
  8. curl -O https://files.magerun.net/n98-magerun2.phar
  9. chmod +x n98-magerun2.phar
  10. mv n98-magerun2.phar src/bin/n98-magerun2.phar
  11. echo "Copying all files from host to container..."
  12. rm -rf src/vendor #Clear for step below
  13. bin/copytocontainer --all
  14. bin/clinotty chmod u+x bin/magento
  15. if hash composer 2>/dev/null; then
  16. PUBLIC_KEY="$(composer config -gl | grep '\[http-basic.repo.magento.com.username\]' | cut -c40-)"
  17. PRIVATE_KEY="$(composer config -gl | grep '\[http-basic.repo.magento.com.password\]' | cut -c40-)"
  18. fi
  19. if [ -z "$PUBLIC_KEY" ] || [ -z "$PRIVATE_KEY" ]; then
  20. exec < /dev/tty
  21. echo
  22. echo
  23. echo " Authentication required (repo.magento.com, public_key and private_key):"
  24. read -p " Username: " PUBLIC_KEY
  25. read -p " Password: " PRIVATE_KEY
  26. echo
  27. if [ -n "$PUBLIC_KEY" ] && [ -n "$PRIVATE_KEY" ] && hash composer 2>/dev/null; then
  28. read -p " Add authentication information to host composer config? y/n: " ADD_AUTH
  29. echo
  30. if [[ $ADD_AUTH =~ ^[Yy]$ ]]; then
  31. composer global config http-basic.repo.magento.com $PUBLIC_KEY $PRIVATE_KEY
  32. fi
  33. ADD_AUTH=''
  34. fi
  35. exec <&-
  36. fi
  37. if [ -n "$PUBLIC_KEY" ] && [ -n "$PRIVATE_KEY" ]; then
  38. bin/clinotty composer config http-basic.repo.magento.com $PUBLIC_KEY $PRIVATE_KEY
  39. PUBLIC_KEY=''
  40. PRIVATE_KEY=''
  41. fi
  42. echo "Forcing reinstall of composer deps to ensure perms & reqs..."
  43. bin/clinotty composer global require hirak/prestissimo
  44. bin/clinotty composer install
  45. bin/clinotty bin/magento setup:install \
  46. --db-host=db \
  47. --db-name=magento \
  48. --db-user=magento \
  49. --db-password=magento \
  50. --base-url=https://$BASE_URL/ \
  51. --admin-firstname=John \
  52. --admin-lastname=Smith \
  53. --admin-email=john.smith@gmail.com \
  54. --admin-user=john.smith \
  55. --admin-password=password123 \
  56. --language=en_US \
  57. --currency=USD \
  58. --timezone=America/New_York \
  59. --use-rewrites=1
  60. echo "Turning on developer mode.."
  61. bin/clinotty bin/magento deploy:mode:set developer
  62. bin/clinotty bin/magento indexer:reindex
  63. echo "Forcing deploy of static content to speed up initial requests..."
  64. bin/clinotty bin/magento setup:static-content:deploy -f
  65. echo "Enabling Redis for cache..."
  66. bin/clinotty bin/magento setup:config:set --no-interaction --cache-backend=redis --cache-backend-redis-server=redis --cache-backend-redis-db=0
  67. echo "Enabling Redis for Full Page Cache..."
  68. bin/clinotty bin/magento setup:config:set --no-interaction --page-cache=redis --page-cache-redis-server=redis --page-cache-redis-db=1
  69. echo "Enabling Redis for session..."
  70. bin/clinotty bin/magento setup:config:set --no-interaction --session-save=redis --session-save-redis-host=redis --session-save-redis-log-level=4 --session-save-redis-db=2
  71. echo "Clearing the cache for good measure..."
  72. bin/clinotty bin/magento cache:flush
  73. echo "Copying files from container to host after install..."
  74. bin/copyfromcontainer app
  75. bin/copyfromcontainer vendor
  76. echo "Restarting containers with host bind mounts for dev..."
  77. bin/restart
  78. echo "Docker development environment setup complete."
  79. echo "You may now access your Magento instance at https://${BASE_URL}/"