Skip to content

Commit 7abac21

Browse files
author
Alexander Paliarush
committed
- Improved developer experience during project initialization
- Fixed recurring environment variables export - Optimized cache clearing script
1 parent 981ba27 commit 7abac21

File tree

7 files changed

+52
-33
lines changed

7 files changed

+52
-33
lines changed

Vagrantfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ guest_memory = config_data['guest']['memory']
3434
# NFS will be used for *nix and OSX hosts, if not disabled explicitly in config
3535
use_nfs_for_synced_folders = !OS.is_windows && (config_data['guest']['use_nfs'] == 1)
3636

37-
host_magento_dir = Dir.pwd + '/magento2ce'
37+
host_vagrant_dir = Dir.pwd + ''
38+
host_magento_dir = host_vagrant_dir + '/magento2ce'
3839

3940
VAGRANT_API_VERSION = 2
4041
Vagrant.configure(VAGRANT_API_VERSION) do |config|
@@ -64,7 +65,8 @@ Vagrant.configure(VAGRANT_API_VERSION) do |config|
6465
magento_host_name, #3
6566
config_data['environment']['use_php7'], #4
6667
host_magento_dir, #5
67-
OS.is_windows ? "1" : "0" #6
68+
OS.is_windows ? "1" : "0", #6
69+
host_vagrant_dir #7
6870
]
6971

7072
config.vm.provision "configure_environment", type: "shell" do |s|

init_project.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,24 @@ bash "${vagrant_dir}/scripts/host/composer.sh" install
8080
cd ${vagrant_dir}
8181
vagrant up
8282

83+
set +x
84+
echo "Configuring PhpStorm..."
8385
if [ ${force_project_cleaning} -eq 1 ]; then
8486
rm -rf ${vagrant_dir}/.idea/*
8587
fi
8688
bash "${vagrant_dir}/scripts/host/configure_php_storm.sh"
89+
90+
bold=$(tput bold)
91+
regular=$(tput sgr0)
92+
echo "
93+
${bold}[Important]${regular}
94+
Please use ${bold}${vagrant_dir}${regular} directory as PhpStorm project root, NOT ${bold}${magento_ce_dir}${regular}."
95+
96+
use_nfs=$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs")
97+
if [[ ${host_os} == "Windows" || ${use_nfs} == 0 ]]; then
98+
echo "
99+
${bold}[Optional]${regular}
100+
To verify that deployment configuration for ${bold}${magento_ce_dir}${regular} in PhpStorm is correct,
101+
use instructions provided here: ${bold}https://github.com/paliarush/magento2-vagrant-for-developers/blob/2.0/docs/phpstorm-configuration-windows-hosts.md${regular}.
102+
If not using PhpStorm, you can set up synchronization using rsync"
103+
fi

scripts/guest/link_configs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ set -ex
77
# Make guest configs visible and editable in the host IDE
88

99
# Configs located under /etc/*
10-
configs=( apache2 php mysql varnish rabbitmq init.d crontab cron.d timezone hosts )
10+
configs=( apache2 php mysql varnish rabbitmq crontab cron.d timezone hosts profile profile.d )
1111
for config in "${configs[@]}"
1212
do
1313
if [ ! -d /vagrant/etc/guest/${config} ] && [ ! -f /vagrant/etc/guest/${config} ]; then
14-
mv /etc/${config} /vagrant/etc/guest/${config}
15-
ln -s /vagrant/etc/guest/${config} /etc/${config}
14+
if [ -d /etc/${config} ] || [ -f /etc/${config} ]; then
15+
mv /etc/${config} /vagrant/etc/guest/${config}
16+
ln -s /vagrant/etc/guest/${config} /etc/${config}
17+
fi
1618
fi
1719
done
1820

@@ -21,7 +23,9 @@ configs=( .bashrc .composer .profile )
2123
for config in "${configs[@]}"
2224
do
2325
if [ ! -d /vagrant/etc/guest/${config} ] && [ ! -f /vagrant/etc/guest/${config} ]; then
24-
mv /home/vagrant/${config} /vagrant/etc/guest/${config}
25-
ln -s /vagrant/etc/guest/${config} /home/vagrant/${config}
26+
if [ -d /home/vagrant/${config} ] || [ -f /home/vagrant/${config} ]; then
27+
mv /home/vagrant/${config} /vagrant/etc/guest/${config}
28+
ln -s /vagrant/etc/guest/${config} /home/vagrant/${config}
29+
fi
2630
fi
2731
done

scripts/guest/m-clear-cache

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ echo "Clearing Magento cache..."
44

55
rm -f ${MAGENTO_ROOT}/app/etc/paths.php
66
#clear var
7-
for dir in `ls ${MAGENTO_ROOT}/var` ; do
8-
rm -rf ${MAGENTO_ROOT}/var/${dir}/* ;
9-
done
7+
cd ${MAGENTO_ROOT} && mv var/.htaccess var_htaccess.back && rm -rf var/* var/.[^.]* && mv var_htaccess.back var/.htaccess
108
#clear pub/statics
11-
cd ${MAGENTO_ROOT}/pub && mv static/.htaccess static_htaccess.back && rm -rf static/* && mv static_htaccess.back static/.htaccess
9+
cd ${MAGENTO_ROOT}/pub && mv static/.htaccess static_htaccess.back && rm -rf static && mkdir static && mv static_htaccess.back static/.htaccess
1210
#clear integration tests tmp
13-
cd ${MAGENTO_ROOT}/dev/tests/integration && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp/* && mv tmp_gitignore.back tmp/.gitignore
11+
cd ${MAGENTO_ROOT}/dev/tests/integration && mv tmp/.gitignore tmp_gitignore.back && rm -rf tmp && mkdir tmp && mv tmp_gitignore.back tmp/.gitignore
1412
#clear unit tests tmp
15-
cd ${MAGENTO_ROOT}/dev/tests/unit && rm -rf tmp/*
13+
cd ${MAGENTO_ROOT}/dev/tests/unit && rm -rf tmp && mkdir tmp
1614

1715
echo "Magento cache cleared."

scripts/guest/m-reinstall

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ install_cmd="./bin/magento setup:install \
6363
--use-rewrites=1"
6464

6565
# Configure Rabbit MQ
66-
if [ -f "${MAGENTO_ROOT}/app/code/Magento/Amqp/registration.php" ]; then
66+
if [ -f "${MAGENTO_ROOT}/app/etc/enterprise/di.xml" ] && [ -d "${MAGENTO_ROOT}/app/code/Magento/Amqp" ]; then
6767
install_cmd="${install_cmd} \
6868
--amqp-host=${setupOptions[amqp_host]} \
6969
--amqp-port=${setupOptions[amqp_port]} \
@@ -93,15 +93,6 @@ sed -i "s|${MAGENTO_ROOT}|${MAGENTO_ROOT_HOST}|g" "/vagrant/.idea/misc.xml"
9393
set +x
9494
echo "
9595
Magento application was deployed to ${MAGENTO_ROOT} and installed successfully
96+
9697
Access storefront at ${setupOptions[base_url]}
9798
Access admin panel at ${setupOptions[base_url]}${setupOptions[admin_frontname]}/"
98-
99-
if [[ ${is_windows_host} == 1 || ${use_nfs} == 0 ]]; then
100-
echo "
101-
[Optional] To finish developer environment set up:
102-
1. Please create new PhpStorm project using 'magento2ce' directory on your host
103-
(this directory should already contain Magento repository cloned earlier)
104-
105-
2. Use instructions provided here https://github.com/paliarush/vagrant-magento/blob/2.0/docs/phpstorm-configuration-windows-hosts.md
106-
to set up synchronization in PhpStorm (or using rsync) with ${MAGENTO_ROOT} directory"
107-
fi

scripts/provision/configure_environment.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ if [ -f ${composer_auth_json} ]; then
7070
fi
7171
fi
7272

73-
# Declare path to scripts supplied with vagrant and Magento
74-
echo "export PATH=\$PATH:${vagrant_dir}/scripts/guest:${guest_magento_dir}/bin" >> /etc/profile
75-
echo "export MAGENTO_ROOT=${guest_magento_dir}" >> /etc/profile
76-
echo "export MAGENTO_ROOT_HOST=${host_magento_dir}" >> /etc/profile
77-
echo "export IS_WINDOWS_HOST=${is_windows_host}" >> /etc/profile
78-
7973
# Set permissions to allow Magento codebase upload by Vagrant provision script
8074
if [ ${use_nfs_for_synced_folders} -eq 0 ]; then
8175
chown -R vagrant:vagrant /var/www

scripts/provision/export_env_variables_recurring.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@ set -e
66
guest_magento_dir=$2
77
host_magento_dir=$5
88
is_windows_host=$6
9+
host_vagrant_dir=$7
10+
vagrant_dir="/vagrant"
911

10-
export MAGENTO_ROOT=${guest_magento_dir}
11-
export MAGENTO_ROOT_HOST=${host_magento_dir}
12-
export IS_WINDOWS_HOST=${is_windows_host}
12+
if ! cat /etc/profile | grep -q 'export PATH=' ; then
13+
echo "export PATH=\$PATH:${vagrant_dir}/scripts/guest:${guest_magento_dir}/bin" >> /etc/profile
14+
fi
15+
16+
if ! cat /etc/profile | grep -q 'export MAGENTO_ROOT=' ; then
17+
echo "export MAGENTO_ROOT=${guest_magento_dir}" >> /etc/profile
18+
echo "export MAGENTO_ROOT_HOST=${host_magento_dir}" >> /etc/profile
19+
echo "export IS_WINDOWS_HOST=${is_windows_host}" >> /etc/profile
20+
fi
21+
22+
if ! cat /etc/profile | grep -q 'export VAGRANT_ROOT=' ; then
23+
echo "export VAGRANT_ROOT=${vagrant_dir}" >> /etc/profile
24+
echo "export VAGRANT_ROOT_HOST=${host_vagrant_dir}" >> /etc/profile
25+
fi

0 commit comments

Comments
 (0)