Skip to content

Commit

Permalink
Merge pull request #38 from zepgram/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Benjamin Calef authored Nov 1, 2019
2 parents d10104f + e9299ee commit 23f2808
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 244 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/.vagrant
/.idea
/.DS_Store
/ssh
/www
/vagrant-ssh
/config.yaml
/.DS_Store
/extra/001-env.sh
/extra/100-pre-build.sh
/extra/120-post-build.sh
/extra/120-post-build.sh
/db-dump.sql.gz
59 changes: 30 additions & 29 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![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)
[![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)
[![mount](https://img.shields.io/badge/nfs/rsync-blue.svg?longCache=true&style=flat&label=mount)](https://github.com/zepgram/magento2-fast-vm/releases)
[![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)
[![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)
[![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)

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

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

## Installation
## Configurations

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

### First installation
### Pre-installation

&#9888; DO NOT USE SSH KEY WITH PASSPHRASE, this vagrant installation is non-interactive.<br>
If your ssh key has been created with a passphrase, please create an other one and add it to your git account.
If your ssh key has been created with a passphrase, please create an other one.
1. On Windows only: open UEFI BIOS and make sure virtualization is turned 'on'
1. On Windows only: open powershell as administrator and run: ``Add-MpPreference -ExclusionProcess winnfsd.exe``
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``
1. On Linux only: in order to install NFS, run ``sudo apt install nfs-kernel-server``
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``

### Installation

1. Clone this project: ``git clone [email protected]:zepgram/magento2-fast-vm.git``
1. On linux only in order to install NFS, run: ``sudo apt install nfs-kernel-server``
1. On windows only, make sur virtualization is turned 'on' in UEFI BIOS
1. Copy and past ``ssh.example``, rename it ``ssh`` and put your ``id_rsa`` and ``id_rsa.pub`` keys
1. Copy and past ``config.yaml.example``, rename it ``config.yaml`` and add your configurations according to [Yaml config overview](#yaml-config-overview)
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>
Default values would be: ``192.168.200.50 dev.magento.com``
1. On windows 10 start your terminal as administrator and uncomment option ``# v.gui=true`` in VagrantFile. You can disable it after first setup
1. Run: ``vagrant up`` in your terminal: setup start! (duration: ~20 minutes)
1. Once installation is done run: ``vagrant ssh`` to access to your guest machine
1. Copy/past: ``ssh.example`` rename it ``ssh`` then put your ``id_rsa`` and ``id_rsa.pub`` keys
1. Copy/past: ``config.yaml.example`` rename it ``config.yaml``<br>Then customize configurations according to [Yaml config overview](#yaml-config-overview)
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
1. To start install run: ``vagrant up`` (duration: ~20 minutes)
1. Finally run: ``vagrant ssh`` to access to your guest machine

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


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

### Mount options

#### RSYNC - new (v1.2.0)
Only usefull on path set to ``root``.<br>
#### RSYNC
Only useful on path set to ``root``.<br>
* 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.
* 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>
* Rsync is unilateral, your host machine push files to guest but not the other way.<br>
Expand Down Expand Up @@ -135,13 +140,9 @@ Those provisions will be executed on pre-defined sequences:
## Usage

### Permission
Magento file system owner is configured for ``magento`` user, it means all commands in magento project must be executed by this user.<br>
By default command line ``vagrant ssh`` will log you as magento user.<br>
* To logout and get back to vagrant user you can run ``exit``
* To login as magento user you can run ``sudo su magento`` or ``bash``
* To re-apply magento permission you can run ``permission`` in command line, used only for ``app`` path and ``default`` mount.

<b>FI: Password for magento user is ``magento``</b>
Magento file system owner is configured for ``vagrant`` user, it means all commands in magento project must be executed by this user.<br>
By default command line ``vagrant ssh`` will log you as vagrant user.<br>
* To re-apply magento permission you can run ``permission`` in command line: this is only applicable for ``app`` path or ``default`` mount configurations.

### Command line
* magento (Magento CLI for your project)
Expand Down Expand Up @@ -170,7 +171,8 @@ Disable cron:
- gitflow
- vim
- mariadb
- apache2
- nginx
- php-fpm
- redis-server
- composer
- magento-cloud CLI
Expand All @@ -184,11 +186,10 @@ Disable cron:

### Credentials
* User bash terminal
* user: magento
* password: magento
* user: vagrant
* Back-office
* url: magento[url]/admin
* user: admin
* user: magento.admin
* pass: admin123
* Database
* user: vagrant
Expand Down
23 changes: 12 additions & 11 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ end

# Mount directory option
hostDirectory = "./www/#{projectName}"
guestDirectory = "/srv/#{projectName}"
guestDirectory = "/home/vagrant/#{projectName}"
if vmconf['path'] == 'app'
hostDirectory = "./www/#{projectName}/app"
guestDirectory = "/srv/#{projectName}/app"
guestDirectory = "/home/vagrant/#{projectName}/app"
end

# Vagrant configure
Expand Down Expand Up @@ -63,7 +63,7 @@ Vagrant.configure(2) do |config|
# Default options
config.vm.synced_folder '.', '/vagrant', disabled: true
config.bindfs.default_options = {
force_user: 'magento',
force_user: 'vagrant',
force_group: 'www-data',
perms: 'u=rwx:g=rwx:o=r'
}
Expand Down Expand Up @@ -103,21 +103,22 @@ Vagrant.configure(2) do |config|
config.vm.provision 'file', source: './ssh/id_rsa', destination: '~/.ssh/id_rsa'
config.vm.provision 'file', source: './ssh/id_rsa.pub', destination: '~/.ssh/id_rsa.pub'

# Extra provisionner
# Extra provision
process_extra_file(config, 'extra/001-env.sh')
process_extra_file(config, 'extra/100-pre-build.sh')
process_extra_file(config, 'extra/120-post-build.sh')
process_extra_file(config, 'db-dump.sql.gz')

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

# Shell provisioning
# Shell provisioning
if vmconf['provision'] == 'all'
config.vm.provision 'shell', path: 'provision/010-system-packages.sh', keep_color: true
config.vm.provision 'shell', path: 'provision/020-system-services.sh', keep_color: true
Expand All @@ -143,12 +144,12 @@ Vagrant.configure(2) do |config|
"
---------------------------------------------------------
Vagrant machine ready to use for #{git['name']}
type #{vmconf['mount']}
mount #{vmconf['mount']}
path #{guestDirectory}
magento #{magento['url']}
phpinfo #{vmconf['network_ip']}/phpinfo
adminer #{vmconf['network_ip']}/adminer
mailcatcher #{vmconf['network_ip']}:1080
magento http://#{magento['url']}
phpinfo http://#{vmconf['network_ip']}/php
adminer http://#{vmconf['network_ip']}/adminer
mailcatcher http://#{vmconf['network_ip']}:1080
"

# Triggers
Expand Down
3 changes: 2 additions & 1 deletion config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ magento:
url: 'dev.magento.com'
source: 'composer'
edition: 'community'
version: '2.3.2'
version: '2.3.3'
php_version: 'default'
sample: 'true'
mode: 'developer'
currency: 'USD'
language: 'en_US'
time_zone: 'America/New_York'
crypt_key: ''
Empty file added db-dump.sql.gz.example
Empty file.
10 changes: 5 additions & 5 deletions dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def check_plugins(dependencies)
if ['up', 'reload'].include?(ARGV[0]) && !skip_dependency_manager
installed_dependencies = []

puts "\033[0m" << "Checking dependencies..." << "\e[0m"
puts "\033[0m" << "==> Checking dependencies..." << "\e[0m"

raw_output = `vagrant plugin list`
raw_list = raw_output.split("\n")
Expand All @@ -54,18 +54,18 @@ def check_plugins(dependencies)
dependencies.each_with_index do |dependency, index|
if not installed_dependencies.include? dependency
dependencies_already_satisfied = false
puts "\033[0m" << " - Missing '#{dependency}'!" << "\e[0m"
puts "\033[0m" << "==> Missing '#{dependency}'!" << "\e[0m"
if not system "vagrant plugin install #{dependency}"
puts "\n\033[0m" << " - Could not install plugin '#{dependency}'. " << "\e[0m\033[41m" <<"Stopped." << "\e[0m"
puts "\n\033[0m" << "==> Could not install plugin '#{dependency}'. " << "\e[0m\033[41m" <<"Stopped." << "\e[0m"
exit -1
end
end
end
if dependencies_already_satisfied
puts "\033[0m" << " - All dependencies are satisfied" << "\e[0m"
puts "\033[0m" << "==> All dependencies are satisfied" << "\e[0m"
else
puts "\033[0m" << " - Dependencies installed" << "\e[0m"
puts "\033[0m" << "==> Dependencies installed" << "\e[0m"
exec "vagrant " << "--skip-dependency-manager " << ARGV.join(" ")
exit
end
Expand Down
46 changes: 9 additions & 37 deletions provision/001-system-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ echo '--- Environment variables ---'
cat <<EOF > /etc/profile.d/env.sh
export PROJECT_NAME="${1}"
export PROJECT_USER="${1}"
export PROJECT_PATH="/srv/${1}"
export PROJECT_PATH="/home/vagrant/${1}"
export PROJECT_COMPOSER_USER="${2}"
export PROJECT_COMPOSER_PASS="${3}"
export PROJECT_GIT_USER="${4}"
Expand All @@ -32,35 +32,21 @@ export PROJECT_MODE="${14}"
export PROJECT_CURRENCY="${15}"
export PROJECT_LANGUAGE="${16}"
export PROJECT_TIME_ZONE="${17}"
export PROJECT_MOUNT="${18}"
export PROJECT_MOUNT_PATH="${19}"
export PROJECT_CRYPT_KEY="${18}"
export PROJECT_MOUNT="${19}"
export PROJECT_MOUNT_PATH="${20}"
EOF
source /etc/profile.d/env.sh

# Create magento user and password
if [[ ! -f "/root/.user-${PROJECT_USER}" ]]; then
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"
usermod -a -G sudo "$PROJECT_USER"
usermod -g www-data "$PROJECT_USER"
usermod --shell /bin/bash "$PROJECT_USER"
touch /root/.user-"$PROJECT_USER"
cat <<EOF >> /home/"$PROJECT_USER"/.bashrc
# Source env
source /etc/profile.d/env.sh
source /etc/profile.d/setup-owner.sh
EOF
fi

# Log as magento user
if [[ -z $(grep "${PROJECT_USER}" "/home/vagrant/.bashrc") ]]; then
cat <<EOF >> /home/vagrant/.bashrc
# Log as $PROJECT_USER user
cd $PROJECT_PATH && sudo su $PROJECT_USER;
# Project path
if [[ -z $(grep "${PROJECT_PATH}" "/home/vagrant/.bashrc") ]]; then
cat <<-EOF >> /home/vagrant/.bashrc
cd $PROJECT_PATH
EOF
fi

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

# Set project owner for setup
MOUNT_FULL_PATH=$PROJECT_PATH
if [ $PROJECT_MOUNT_PATH == "app" ]; then
MOUNT_FULL_PATH=$PROJECT_PATH/app
fi
SETUP_OWNER="$(ls -ld $MOUNT_FULL_PATH | awk 'NR==1 {print $3}')"
if [ $SETUP_OWNER != "magento" ]; then
SETUP_OWNER="vagrant"
fi
cat <<EOF > /etc/profile.d/setup-owner.sh
export PROJECT_SETUP_OWNER="${SETUP_OWNER}"
EOF

# Source and display
source /etc/profile
cat /etc/profile.d/setup-owner.sh
cat /etc/profile.d/env.sh
15 changes: 12 additions & 3 deletions provision/010-system-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ debconf-set-selections <<< "mysql-server mysql-server/root_password_again passwo
debconf-set-selections <<< "postfix postfix/mailname string $PROJECT_URL"
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"

# Configure default locale
cp /etc/locale.gen /etc/locale.gen.old
sed -i "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" /etc/locale.gen
/usr/sbin/locale-gen
export LANG=en_US.UTF-8*

# Required packages
apt-get install -y \
curl graphviz htop net-tools rsync sudo tree wget unzip zip \
libsqlite3-dev libxml2-utils build-essential software-properties-common \
postfix mailutils libsasl2-2 libsasl2-modules ca-certificates \
postfix mailutils libsasl2-2 libsasl2-modules ca-certificates libnss3-tools \
apt-transport-https mysql-client mysql-server redis-server \
openssl apache2 \
openssl nginx \
g++ vim git git-flow

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

# Set php version
MAGENTO_PHP_VERSION='7.2';
if $(dpkg --compare-versions "${PROJECT_VERSION}" "gt" "2.3.2-p1"); then
MAGENTO_PHP_VERSION='7.3';
fi
if $(dpkg --compare-versions "${PROJECT_VERSION}" "lt" "2.3"); then
MAGENTO_PHP_VERSION='7.1';
fi
Expand All @@ -54,7 +63,7 @@ apt-get update -y && apt-get install -y \
php${PROJECT_PHP_VERSION}-curl php${PROJECT_PHP_VERSION}-gd php${PROJECT_PHP_VERSION}-intl \
php${PROJECT_PHP_VERSION}-mbstring php${PROJECT_PHP_VERSION}-soap php${PROJECT_PHP_VERSION}-zip \
php${PROJECT_PHP_VERSION}-xml php${PROJECT_PHP_VERSION}-xml php${PROJECT_PHP_VERSION}-bcmath \
php${PROJECT_PHP_VERSION}-mysql php${PROJECT_PHP_VERSION}-sqlite3 libapache2-mod-php${PROJECT_PHP_VERSION} \
php${PROJECT_PHP_VERSION}-mysql php${PROJECT_PHP_VERSION}-sqlite3 php${PROJECT_PHP_VERSION}-fpm \
php${PROJECT_PHP_VERSION}-memcache php${PROJECT_PHP_VERSION}-redis php${PROJECT_PHP_VERSION}-opcache \
python ruby ruby-dev
if $(dpkg --compare-versions "${PROJECT_PHP_VERSION}" "lt" "7.2"); then
Expand Down
Loading

0 comments on commit 23f2808

Please sign in to comment.