setup 3.6 KB

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