Skip to content

Commit 23f2808

Browse files
author
Benjamin Calef
authored
Merge pull request #38 from zepgram/develop
Develop
2 parents d10104f + e9299ee commit 23f2808

12 files changed

+232
-244
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/.vagrant
22
/.idea
3+
/.DS_Store
34
/ssh
45
/www
56
/vagrant-ssh
67
/config.yaml
7-
/.DS_Store
88
/extra/001-env.sh
99
/extra/100-pre-build.sh
10-
/extra/120-post-build.sh
10+
/extra/120-post-build.sh
11+
/db-dump.sql.gz

Readme.md

+30-29
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![vagrant](https://img.shields.io/badge/vagrant-debian:stretch-blue.svg?longCache=true&style=flat&label=vagrant&logo=vagrant)](https://app.vagrantup.com/debian/boxes/stretch64)
44
[![dev-box](https://img.shields.io/badge/git/composer-blue.svg?longCache=true&style=flat&label=setup&logo=magento)](https://github.com/zepgram/magento2-fast-vm/blob/master/config.yaml.example)
55
[![mount](https://img.shields.io/badge/nfs/rsync-blue.svg?longCache=true&style=flat&label=mount)](https://github.com/zepgram/magento2-fast-vm/releases)
6-
[![release](https://img.shields.io/badge/release-v1.2.0-blue.svg?longCache=true&style=flat&label=release)](https://github.com/zepgram/magento2-fast-vm/releases)
6+
[![release](https://img.shields.io/badge/release-v1.3.0-blue.svg?longCache=true&style=flat&label=release)](https://github.com/zepgram/magento2-fast-vm/releases)
77
[![license](https://img.shields.io/badge/license-MIT-blue.svg?longCache=true&style=flat&label=license)](https://github.com/zepgram/magento2-fast-vm/blob/master/LICENSE)
88

99
![windows](https://img.shields.io/badge/windows-ok-green.svg?longCache=true&style=flat&label=windows&logo=windows)
@@ -23,7 +23,7 @@ Stable version >= 5.2.0
2323
1. Run the installer, choosing all of the default options.
2424
* Windows: Grant the installer access every time you receive a security prompt.
2525
* Mac: Enter your admin password.
26-
* Linux: Enter your root password if prompted.
26+
* Linux: Enter your user password if prompted.
2727
1. Reboot your laptop if prompted to do so when installation completes.
2828
1. Close the VirtualBox window if it pops up at the end of the install.
2929

@@ -35,26 +35,30 @@ Stable version >= 2.2.0
3535
* [Vagrant download](https://www.vagrantup.com/downloads.html)
3636
1. Reboot your laptop if prompted to do so when installation completes.
3737

38-
## Installation
38+
## Configurations
3939

4040
### Related guide
41-
- Made by Onilab for Windows 10:
41+
- Made by Onilab for Windows 10:<br>
4242
https://onilab.com/blog/install-magento-2-on-localhost-a-windows-10-guide/
4343

44-
### First installation
44+
### Pre-installation
4545

4646
&#9888; DO NOT USE SSH KEY WITH PASSPHRASE, this vagrant installation is non-interactive.<br>
47-
If your ssh key has been created with a passphrase, please create an other one and add it to your git account.
47+
If your ssh key has been created with a passphrase, please create an other one.
48+
1. On Windows only: open UEFI BIOS and make sure virtualization is turned 'on'
49+
1. On Windows only: open powershell as administrator and run: ``Add-MpPreference -ExclusionProcess winnfsd.exe``
50+
1. On Windows only: open ``C:\Windows\System32\drivers\etc\hosts`` as administrator then add ``network_ip`` and ``magento_url``<br>Default values would be: ``192.168.200.50 dev.magento.com``
51+
1. On Linux only: in order to install NFS, run ``sudo apt install nfs-kernel-server``
52+
1. On Linux/MacOS only: open ``/etc/hosts`` as sudo then add ``network_ip`` and ``magento_url``<br>Default values would be: ``192.168.200.50 dev.magento.com``
53+
54+
### Installation
55+
4856
1. Clone this project: ``git clone [email protected]:zepgram/magento2-fast-vm.git``
49-
1. On linux only in order to install NFS, run: ``sudo apt install nfs-kernel-server``
50-
1. On windows only, make sur virtualization is turned 'on' in UEFI BIOS
51-
1. Copy and past ``ssh.example``, rename it ``ssh`` and put your ``id_rsa`` and ``id_rsa.pub`` keys
52-
1. Copy and past ``config.yaml.example``, rename it ``config.yaml`` and add your configurations according to [Yaml config overview](#yaml-config-overview)
53-
1. As admin open your host file: ``C:\Windows\System32\drivers\etc\hosts`` for Windows or ``/etc/hosts``for Linux/macOS and add vm_conf[network_ip] and magento[url]<br>
54-
Default values would be: ``192.168.200.50 dev.magento.com``
55-
1. On windows 10 start your terminal as administrator and uncomment option ``# v.gui=true`` in VagrantFile. You can disable it after first setup
56-
1. Run: ``vagrant up`` in your terminal: setup start! (duration: ~20 minutes)
57-
1. Once installation is done run: ``vagrant ssh`` to access to your guest machine
57+
1. Copy/past: ``ssh.example`` rename it ``ssh`` then put your ``id_rsa`` and ``id_rsa.pub`` keys
58+
1. Copy/past: ``config.yaml.example`` rename it ``config.yaml``<br>Then customize configurations according to [Yaml config overview](#yaml-config-overview)
59+
1. If you want to import an existing database: create a compressed sql dump and name it ``db-dump.sql.gz``.<br>You must also fill ``crypt_key`` in config.yaml
60+
1. To start install run: ``vagrant up`` (duration: ~20 minutes)
61+
1. Finally run: ``vagrant ssh`` to access to your guest machine
5862

5963
### Yaml config overview
6064
* Vmconf
@@ -88,13 +92,14 @@ Default values would be: ``192.168.200.50 dev.magento.com``
8892
* edition: magento project edition, used only on composer source installation (community)
8993
* 'community' install magento community edition
9094
* 'enterprise' install magento enterprise edition
91-
* version: set magento version and also define PHP version (2.3.*)
95+
* version: set magento version and also define PHP version (2.3.3)
9296
* php_version: override the default required version by yours, for example '7.1' (default)
9397
* sample: install sample data, used only on composer source installation (true)
9498
* mode: magento mode (developer)
9599
* currency: set currency (USD)
96100
* language: set language (en_US)
97101
* time_zone: set time zone (Europe/London)
102+
* crypt_key: crypt key under your app/etc/env.php (only required if db-dump.sql.gz exist)
98103

99104

100105
### Path
@@ -103,8 +108,8 @@ Default values would be: ``192.168.200.50 dev.magento.com``
103108

104109
### Mount options
105110

106-
#### RSYNC - new (v1.2.0)
107-
Only usefull on path set to ``root``.<br>
111+
#### RSYNC
112+
Only useful on path set to ``root``.<br>
108113
* Loss of performance is due to files generated on the fly, by excluding them you can mount the whole directory ``root`` and get performance equal to an ``app`` mount.
109114
* The ``vagrant rsync-auto`` is launched by default on vagrant up, even with that if you need to force an update you can run ``vagrant rsync``. <b>Terminal should be kept open for rsync-auto: do not close it.</b>
110115
* Rsync is unilateral, your host machine push files to guest but not the other way.<br>
@@ -135,13 +140,9 @@ Those provisions will be executed on pre-defined sequences:
135140
## Usage
136141

137142
### Permission
138-
Magento file system owner is configured for ``magento`` user, it means all commands in magento project must be executed by this user.<br>
139-
By default command line ``vagrant ssh`` will log you as magento user.<br>
140-
* To logout and get back to vagrant user you can run ``exit``
141-
* To login as magento user you can run ``sudo su magento`` or ``bash``
142-
* To re-apply magento permission you can run ``permission`` in command line, used only for ``app`` path and ``default`` mount.
143-
144-
<b>FI: Password for magento user is ``magento``</b>
143+
Magento file system owner is configured for ``vagrant`` user, it means all commands in magento project must be executed by this user.<br>
144+
By default command line ``vagrant ssh`` will log you as vagrant user.<br>
145+
* To re-apply magento permission you can run ``permission`` in command line: this is only applicable for ``app`` path or ``default`` mount configurations.
145146

146147
### Command line
147148
* magento (Magento CLI for your project)
@@ -170,7 +171,8 @@ Disable cron:
170171
- gitflow
171172
- vim
172173
- mariadb
173-
- apache2
174+
- nginx
175+
- php-fpm
174176
- redis-server
175177
- composer
176178
- magento-cloud CLI
@@ -184,11 +186,10 @@ Disable cron:
184186

185187
### Credentials
186188
* User bash terminal
187-
* user: magento
188-
* password: magento
189+
* user: vagrant
189190
* Back-office
190191
* url: magento[url]/admin
191-
* user: admin
192+
* user: magento.admin
192193
* pass: admin123
193194
* Database
194195
* user: vagrant

Vagrantfile

+12-11
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ end
2828

2929
# Mount directory option
3030
hostDirectory = "./www/#{projectName}"
31-
guestDirectory = "/srv/#{projectName}"
31+
guestDirectory = "/home/vagrant/#{projectName}"
3232
if vmconf['path'] == 'app'
3333
hostDirectory = "./www/#{projectName}/app"
34-
guestDirectory = "/srv/#{projectName}/app"
34+
guestDirectory = "/home/vagrant/#{projectName}/app"
3535
end
3636

3737
# Vagrant configure
@@ -63,7 +63,7 @@ Vagrant.configure(2) do |config|
6363
# Default options
6464
config.vm.synced_folder '.', '/vagrant', disabled: true
6565
config.bindfs.default_options = {
66-
force_user: 'magento',
66+
force_user: 'vagrant',
6767
force_group: 'www-data',
6868
perms: 'u=rwx:g=rwx:o=r'
6969
}
@@ -103,21 +103,22 @@ Vagrant.configure(2) do |config|
103103
config.vm.provision 'file', source: './ssh/id_rsa', destination: '~/.ssh/id_rsa'
104104
config.vm.provision 'file', source: './ssh/id_rsa.pub', destination: '~/.ssh/id_rsa.pub'
105105

106-
# Extra provisionner
106+
# Extra provision
107107
process_extra_file(config, 'extra/001-env.sh')
108108
process_extra_file(config, 'extra/100-pre-build.sh')
109109
process_extra_file(config, 'extra/120-post-build.sh')
110+
process_extra_file(config, 'db-dump.sql.gz')
110111

111112
# Environment provisioning
112113
config.vm.provision 'shell', path: 'provision/001-system-env.sh', run: 'always', keep_color: true, args: [
113114
projectName, composer['username'], composer['password'],
114115
git['name'], git['email'], git['host'], git['repository'],
115116
magento['url'], magento['php_version'], magento['source'], magento['edition'],
116117
magento['version'], magento['sample'], magento['mode'], magento['currency'],
117-
magento['language'], magento['time_zone'], vmconf['mount'], vmconf['path']
118+
magento['language'], magento['time_zone'], magento['crypt_key'], vmconf['mount'], vmconf['path']
118119
]
119120

120-
# Shell provisioning
121+
# Shell provisioning
121122
if vmconf['provision'] == 'all'
122123
config.vm.provision 'shell', path: 'provision/010-system-packages.sh', keep_color: true
123124
config.vm.provision 'shell', path: 'provision/020-system-services.sh', keep_color: true
@@ -143,12 +144,12 @@ Vagrant.configure(2) do |config|
143144
"
144145
---------------------------------------------------------
145146
Vagrant machine ready to use for #{git['name']}
146-
type #{vmconf['mount']}
147+
mount #{vmconf['mount']}
147148
path #{guestDirectory}
148-
magento #{magento['url']}
149-
phpinfo #{vmconf['network_ip']}/phpinfo
150-
adminer #{vmconf['network_ip']}/adminer
151-
mailcatcher #{vmconf['network_ip']}:1080
149+
magento http://#{magento['url']}
150+
phpinfo http://#{vmconf['network_ip']}/php
151+
adminer http://#{vmconf['network_ip']}/adminer
152+
mailcatcher http://#{vmconf['network_ip']}:1080
152153
"
153154

154155
# Triggers

config.yaml.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ magento:
1919
url: 'dev.magento.com'
2020
source: 'composer'
2121
edition: 'community'
22-
version: '2.3.2'
22+
version: '2.3.3'
2323
php_version: 'default'
2424
sample: 'true'
2525
mode: 'developer'
2626
currency: 'USD'
2727
language: 'en_US'
2828
time_zone: 'America/New_York'
29+
crypt_key: ''

db-dump.sql.gz.example

Whitespace-only changes.

dependency.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def check_plugins(dependencies)
3535
if ['up', 'reload'].include?(ARGV[0]) && !skip_dependency_manager
3636
installed_dependencies = []
3737

38-
puts "\033[0m" << "Checking dependencies..." << "\e[0m"
38+
puts "\033[0m" << "==> Checking dependencies..." << "\e[0m"
3939

4040
raw_output = `vagrant plugin list`
4141
raw_list = raw_output.split("\n")
@@ -54,18 +54,18 @@ def check_plugins(dependencies)
5454
dependencies.each_with_index do |dependency, index|
5555
if not installed_dependencies.include? dependency
5656
dependencies_already_satisfied = false
57-
puts "\033[0m" << " - Missing '#{dependency}'!" << "\e[0m"
57+
puts "\033[0m" << "==> Missing '#{dependency}'!" << "\e[0m"
5858
if not system "vagrant plugin install #{dependency}"
59-
puts "\n\033[0m" << " - Could not install plugin '#{dependency}'. " << "\e[0m\033[41m" <<"Stopped." << "\e[0m"
59+
puts "\n\033[0m" << "==> Could not install plugin '#{dependency}'. " << "\e[0m\033[41m" <<"Stopped." << "\e[0m"
6060
exit -1
6161
end
6262
end
6363
end
6464
6565
if dependencies_already_satisfied
66-
puts "\033[0m" << " - All dependencies are satisfied" << "\e[0m"
66+
puts "\033[0m" << "==> All dependencies are satisfied" << "\e[0m"
6767
else
68-
puts "\033[0m" << " - Dependencies installed" << "\e[0m"
68+
puts "\033[0m" << "==> Dependencies installed" << "\e[0m"
6969
exec "vagrant " << "--skip-dependency-manager " << ARGV.join(" ")
7070
exit
7171
end

provision/001-system-env.sh

+9-37
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ echo '--- Environment variables ---'
1515
cat <<EOF > /etc/profile.d/env.sh
1616
export PROJECT_NAME="${1}"
1717
export PROJECT_USER="${1}"
18-
export PROJECT_PATH="/srv/${1}"
18+
export PROJECT_PATH="/home/vagrant/${1}"
1919
export PROJECT_COMPOSER_USER="${2}"
2020
export PROJECT_COMPOSER_PASS="${3}"
2121
export PROJECT_GIT_USER="${4}"
@@ -32,35 +32,21 @@ export PROJECT_MODE="${14}"
3232
export PROJECT_CURRENCY="${15}"
3333
export PROJECT_LANGUAGE="${16}"
3434
export PROJECT_TIME_ZONE="${17}"
35-
export PROJECT_MOUNT="${18}"
36-
export PROJECT_MOUNT_PATH="${19}"
35+
export PROJECT_CRYPT_KEY="${18}"
36+
export PROJECT_MOUNT="${19}"
37+
export PROJECT_MOUNT_PATH="${20}"
3738
EOF
3839
source /etc/profile.d/env.sh
3940

40-
# Create magento user and password
41-
if [[ ! -f "/root/.user-${PROJECT_USER}" ]]; then
42-
useradd -m -p $(python -c "import crypt; print crypt.crypt(\"magento\", \"\$6\$$(</dev/urandom tr -dc 'a-zA-Z0-9' | head -c 32)\$\")") "$PROJECT_USER"
43-
usermod -a -G sudo "$PROJECT_USER"
44-
usermod -g www-data "$PROJECT_USER"
45-
usermod --shell /bin/bash "$PROJECT_USER"
46-
touch /root/.user-"$PROJECT_USER"
47-
cat <<EOF >> /home/"$PROJECT_USER"/.bashrc
48-
49-
# Source env
50-
source /etc/profile.d/env.sh
51-
source /etc/profile.d/setup-owner.sh
52-
EOF
53-
fi
54-
55-
# Log as magento user
56-
if [[ -z $(grep "${PROJECT_USER}" "/home/vagrant/.bashrc") ]]; then
57-
cat <<EOF >> /home/vagrant/.bashrc
58-
# Log as $PROJECT_USER user
59-
cd $PROJECT_PATH && sudo su $PROJECT_USER;
41+
# Project path
42+
if [[ -z $(grep "${PROJECT_PATH}" "/home/vagrant/.bashrc") ]]; then
43+
cat <<-EOF >> /home/vagrant/.bashrc
44+
cd $PROJECT_PATH
6045
EOF
6146
fi
6247

6348
# Patch extra files
49+
sudo -u vagrant mkdir -p /home/vagrant/extra
6450
if [[ ! $(dpkg-query -l 'dos2unix') ]]; then
6551
sudo apt-get install -y dos2unix
6652
fi
@@ -79,20 +65,6 @@ if [ -f /home/vagrant/extra/001-env.sh ]; then
7965
bash /home/vagrant/extra/001-env.sh
8066
fi
8167

82-
# Set project owner for setup
83-
MOUNT_FULL_PATH=$PROJECT_PATH
84-
if [ $PROJECT_MOUNT_PATH == "app" ]; then
85-
MOUNT_FULL_PATH=$PROJECT_PATH/app
86-
fi
87-
SETUP_OWNER="$(ls -ld $MOUNT_FULL_PATH | awk 'NR==1 {print $3}')"
88-
if [ $SETUP_OWNER != "magento" ]; then
89-
SETUP_OWNER="vagrant"
90-
fi
91-
cat <<EOF > /etc/profile.d/setup-owner.sh
92-
export PROJECT_SETUP_OWNER="${SETUP_OWNER}"
93-
EOF
94-
9568
# Source and display
9669
source /etc/profile
97-
cat /etc/profile.d/setup-owner.sh
9870
cat /etc/profile.d/env.sh

provision/010-system-packages.sh

+12-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ debconf-set-selections <<< "mysql-server mysql-server/root_password_again passwo
1919
debconf-set-selections <<< "postfix postfix/mailname string $PROJECT_URL"
2020
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
2121

22+
# Configure default locale
23+
cp /etc/locale.gen /etc/locale.gen.old
24+
sed -i "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" /etc/locale.gen
25+
/usr/sbin/locale-gen
26+
export LANG=en_US.UTF-8*
27+
2228
# Required packages
2329
apt-get install -y \
2430
curl graphviz htop net-tools rsync sudo tree wget unzip zip \
2531
libsqlite3-dev libxml2-utils build-essential software-properties-common \
26-
postfix mailutils libsasl2-2 libsasl2-modules ca-certificates \
32+
postfix mailutils libsasl2-2 libsasl2-modules ca-certificates libnss3-tools \
2733
apt-transport-https mysql-client mysql-server redis-server \
28-
openssl apache2 \
34+
openssl nginx \
2935
g++ vim git git-flow
3036

3137
# Sury Repository
@@ -34,6 +40,9 @@ echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sourc
3440

3541
# Set php version
3642
MAGENTO_PHP_VERSION='7.2';
43+
if $(dpkg --compare-versions "${PROJECT_VERSION}" "gt" "2.3.2-p1"); then
44+
MAGENTO_PHP_VERSION='7.3';
45+
fi
3746
if $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.3"); then
3847
MAGENTO_PHP_VERSION='7.1';
3948
fi
@@ -54,7 +63,7 @@ apt-get update -y && apt-get install -y \
5463
php${PROJECT_PHP_VERSION}-curl php${PROJECT_PHP_VERSION}-gd php${PROJECT_PHP_VERSION}-intl \
5564
php${PROJECT_PHP_VERSION}-mbstring php${PROJECT_PHP_VERSION}-soap php${PROJECT_PHP_VERSION}-zip \
5665
php${PROJECT_PHP_VERSION}-xml php${PROJECT_PHP_VERSION}-xml php${PROJECT_PHP_VERSION}-bcmath \
57-
php${PROJECT_PHP_VERSION}-mysql php${PROJECT_PHP_VERSION}-sqlite3 libapache2-mod-php${PROJECT_PHP_VERSION} \
66+
php${PROJECT_PHP_VERSION}-mysql php${PROJECT_PHP_VERSION}-sqlite3 php${PROJECT_PHP_VERSION}-fpm \
5867
php${PROJECT_PHP_VERSION}-memcache php${PROJECT_PHP_VERSION}-redis php${PROJECT_PHP_VERSION}-opcache \
5968
python ruby ruby-dev
6069
if $(dpkg --compare-versions "${PROJECT_PHP_VERSION}" "lt" "7.2"); then

0 commit comments

Comments
 (0)