Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit 2d604a2

Browse files
author
Alexander Paliarush
committed
Refactoring and improvements
- Added use_nfs option to disable NFS folder synchronization, if necessary - Added option to clean existing project files during project initialization
1 parent 0d2e072 commit 2d604a2

File tree

6 files changed

+53
-38
lines changed

6 files changed

+53
-38
lines changed

Vagrantfile

+10-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ magento_host_name = config_data['magento']['host_name']
2828
magento_ip_address = config_data['guest']['ip_address']
2929
guest_memory = config_data['guest']['memory']
3030

31+
# NFS will be used for *nix and OSX hosts, if not disabled explicitly in config
32+
use_nfs_for_synced_folders = !OS.is_windows && (config_data['guest']['use_nfs'] == 1)
33+
3134
host_magento_dir = Dir.pwd + '/magento2ce'
3235

3336
VAGRANT_API_VERSION = 2
@@ -41,20 +44,20 @@ Vagrant.configure(VAGRANT_API_VERSION) do |config|
4144
config.vm.synced_folder '.', '/vagrant', disabled: true
4245
config.vm.synced_folder './local.config', '/vagrant/local.config'
4346
config.vm.synced_folder './scripts', '/vagrant/scripts'
44-
if OS.is_windows
47+
if use_nfs_for_synced_folders
48+
guest_magento_dir = host_magento_dir
49+
config.vm.synced_folder host_magento_dir, guest_magento_dir, type: "nfs"
50+
else
4551
guest_magento_dir = '/var/www/magento2ce'
4652
config.vm.synced_folder host_magento_dir + '/var/generation', guest_magento_dir + '/var/generation'
4753
config.vm.synced_folder host_magento_dir + '/app/etc', guest_magento_dir + '/app/etc'
48-
else
49-
guest_magento_dir = host_magento_dir
50-
config.vm.synced_folder host_magento_dir, guest_magento_dir, type: "nfs"
5154
end
5255

5356
shell_script_args = [
54-
OS.is_windows ? "1" : "0", #1
57+
use_nfs_for_synced_folders ? "1" : "0", #1
5558
guest_magento_dir, #2
5659
magento_host_name, #3
57-
config_data['guest']['use_php7'], #4
60+
config_data['environment']['use_php7'], #4
5861
config_data['magento']['backend_frontname'],#5
5962
config_data['magento']['language'], #6
6063
config_data['magento']['timezone'], #8
@@ -67,7 +70,7 @@ Vagrant.configure(VAGRANT_API_VERSION) do |config|
6770
s.args = shell_script_args
6871
end
6972

70-
if OS.is_windows
73+
if !use_nfs_for_synced_folders
7174
config.vm.provision "deploy_magento_code", type: "file", source: host_magento_dir, destination: '/var/www'
7275
end
7376

init_project.sh

+24-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,30 @@ set -ex
99

1010
bash "${vagrant_dir}/scripts/host/shell/check_requirements.sh"
1111

12-
# Check out CE repository
13-
repository_url_ce=$(bash "${vagrant_dir}/scripts/host/shell/get_variable_value.sh" "repository_url_ce")
14-
git clone ${repository_url_ce} ${magento_ce_dir}
15-
# Check out EE repository
16-
# By default EE repository is not specified and EE project is not checked out
17-
repository_url_ee=$(bash "${vagrant_dir}/scripts/host/shell/get_variable_value.sh" "repository_url_ee")
18-
if [ -n "${repository_url_ee}" ]; then
19-
git clone ${repository_url_ee} ${magento_ee_dir}
12+
force_project_cleaning=0
13+
while getopts 'f' flag; do
14+
case "${flag}" in
15+
f) force_project_cleaning=1 ;;
16+
*) error "Unexpected option ${flag}" ;;
17+
esac
18+
done
19+
20+
# Clean up the project before initialization if "-f" option was specified
21+
if [ ${force_project_cleaning} -eq 1 ]; then
22+
vagrant destroy -f
23+
rm -rf ${magento_ce_dir} ${vagrant_dir}/.idea ${vagrant_dir}/.vagrant
24+
fi
25+
26+
if [ ! -d ${magento_ce_dir} ]; then
27+
# Check out CE repository
28+
repository_url_ce=$(bash "${vagrant_dir}/scripts/host/shell/get_variable_value.sh" "repository_url_ce")
29+
git clone ${repository_url_ce} ${magento_ce_dir}
30+
# Check out EE repository
31+
# By default EE repository is not specified and EE project is not checked out
32+
repository_url_ee=$(bash "${vagrant_dir}/scripts/host/shell/get_variable_value.sh" "repository_url_ee")
33+
if [ -n "${repository_url_ee}" ]; then
34+
git clone ${repository_url_ee} ${magento_ee_dir}
35+
fi
2036
fi
2137

2238
# Update Magento dependencies via Composer

local.config/config.yaml.dist

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ repository_url:
22
ce: "git@github.com:magento/magento2.git"
33
ee: ""
44
guest:
5+
use_nfs: 1 # NFS will be used for folder synchronization on *nix and OSX hosts by default
56
memory: 2048 # Default is 2Gb, around 3Gb is necessary to run functional tests
67
ip_address: "192.168.10.11"
7-
use_php7: 1
8+
environment:
9+
use_php7: 1 # If set to 0, PHP 5 will be installed
810
magento:
911
host_name: "magento2.vagrant"
1012
backend_frontname: "admin"

scripts/host/shell/configure_php_storm.sh

+8-14
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,14 @@ cp -R "${vagrant_dir}/scripts/host/php-storm-configs/." "${vagrant_dir}/.idea/"
1414

1515
enabled_virtual_host_config="/etc/apache2/sites-available/magento2.conf"
1616

17-
current_os="$(bash ${vagrant_dir}/scripts/host/shell/get_current_os.sh)"
18-
if [ ${current_os} -eq "OSX" ]; then
19-
sed_command="sed -i ''"
20-
else
21-
sed_command="sed -i"
22-
fi
23-
24-
${sed_command} "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/webServers.xml"
25-
${sed_command} "s|<ssh_port>|${ssh_port}|g" "${vagrant_dir}/.idea/webServers.xml"
26-
${sed_command} "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/php.xml"
27-
${sed_command} "s|<ssh_port>|${ssh_port}|g" "${vagrant_dir}/.idea/php.xml"
28-
${sed_command} "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/deployment.xml"
29-
${sed_command} "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/.name"
30-
${sed_command} "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/modules.xml"
17+
sed -i.back "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/webServers.xml"
18+
sed -i.back "s|<ssh_port>|${ssh_port}|g" "${vagrant_dir}/.idea/webServers.xml"
19+
sed -i.back "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/php.xml"
20+
sed -i.back "s|<ssh_port>|${ssh_port}|g" "${vagrant_dir}/.idea/php.xml"
21+
sed -i.back "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/deployment.xml"
22+
sed -i.back "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/.name"
23+
sed -i.back "s|<host_name>|${magento_host_name}|g" "${vagrant_dir}/.idea/modules.xml"
24+
rm -rf ${vagrant_dir}/.idea/*.back
3125

3226
mv "${vagrant_dir}/.idea/<host_name>.iml" "${vagrant_dir}/.idea/${magento_host_name}.iml"
3327

scripts/provision/install_environment.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Enable trace printing and exit on the first error
44
set -ex
55

6-
is_windows_host=$1
6+
use_nfs_for_synced_folders=$1
77
guest_magento_dir=$2
88
magento_host_name=$3
99
use_php7=$4
@@ -125,7 +125,7 @@ echo "export PATH=\$PATH:${vagrant_dir}/scripts/guest:${guest_magento_dir}/bin"
125125
echo "export MAGENTO_ROOT=${guest_magento_dir}" >> /etc/profile
126126

127127
# Set permissions to allow Magento codebase upload by Vagrant provision script
128-
if [ ${is_windows_host} -eq 1 ]; then
128+
if [ ${use_nfs_for_synced_folders} -eq 0 ]; then
129129
chown -R vagrant:vagrant /var/www
130130
chmod -R 755 /var/www
131131
fi

scripts/provision/install_magento.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Enable trace printing and exit on the first error
66
set -ex
77

8-
is_windows_host=$1
8+
use_nfs_for_synced_folders=$1
99
guest_magento_dir=$2
1010
magento_host_name=$3
1111

@@ -15,11 +15,11 @@ setupOptions[language]=$6
1515
setupOptions[timezone]=$7
1616
setupOptions[currency]=$8
1717
setupOptions[admin_user]=$9
18-
setupOptions[admin_password]=$10
18+
setupOptions[admin_password]=${10}
1919
setupOptions[db_host]='localhost'
2020
setupOptions[db_name]='magento'
2121
setupOptions[db_user]='root'
22-
setupOptions[base_url]='http://${magento_host_name}/'
22+
setupOptions[base_url]="http://${magento_host_name}/"
2323
setupOptions[admin_lastname]='Admin'
2424
setupOptions[admin_firstname]='Admin'
2525
setupOptions[admin_email]='admin@example.com'
@@ -78,17 +78,17 @@ php ${install_cmd}
7878
# Enable Magento cron jobs
7979
echo "* * * * * php ${guest_magento_dir}/bin/magento cron:run &" | crontab -u vagrant -
8080

81-
if [ ${is_windows_host} -eq 1 ]; then
81+
if [ ${use_nfs_for_synced_folders} -eq 0 ]; then
8282
chown -R vagrant:vagrant ${guest_magento_dir}
8383
fi
8484

8585
set +x
8686
echo "
8787
Magento application was deployed to ${guest_magento_dir} and installed successfully
8888
Access storefront at ${setupOptions[base_url]}
89-
Access admin panel at ${setupOptions[base_url]}${backend_frontame}/"
89+
Access admin panel at ${setupOptions[base_url]}${setupOptions[backend_frontname]}/"
9090

91-
if [ ${is_windows_host} -eq 1 ]; then
91+
if [ ${use_nfs_for_synced_folders} -eq 0 ]; then
9292
echo "
9393
[Optional] To finish developer environment set up:
9494
1. Please create new PhpStorm project using 'magento2ce' directory on your host

0 commit comments

Comments
 (0)