first commit
This commit is contained in:
2
vagrant/config/.gitignore
vendored
Executable file
2
vagrant/config/.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
# local configuration
|
||||
vagrant-local.yml
|
22
vagrant/config/vagrant-local.example.yml
Executable file
22
vagrant/config/vagrant-local.example.yml
Executable file
@ -0,0 +1,22 @@
|
||||
# Your personal GitHub token
|
||||
github_token: <your-personal-github-token>
|
||||
# Read more: https://github.com/blog/1509-personal-api-tokens
|
||||
# You can generate it here: https://github.com/settings/tokens
|
||||
|
||||
# Guest OS timezone
|
||||
timezone: Europe/London
|
||||
|
||||
# Are we need check box updates for every 'vagrant up'?
|
||||
box_check_update: false
|
||||
|
||||
# Virtual machine name
|
||||
machine_name: y2aa
|
||||
|
||||
# Virtual machine IP
|
||||
ip: 192.168.83.137
|
||||
|
||||
# Virtual machine CPU cores number
|
||||
cpus: 1
|
||||
|
||||
# Virtual machine RAM
|
||||
memory: 1024
|
77
vagrant/nginx/app.conf
Executable file
77
vagrant/nginx/app.conf
Executable file
@ -0,0 +1,77 @@
|
||||
server {
|
||||
charset utf-8;
|
||||
client_max_body_size 128M;
|
||||
sendfile off;
|
||||
|
||||
listen 80; ## listen for ipv4
|
||||
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
|
||||
|
||||
server_name y2aa-frontend.test;
|
||||
root /app/frontend/web/;
|
||||
index index.php;
|
||||
|
||||
access_log /app/vagrant/nginx/log/frontend-access.log;
|
||||
error_log /app/vagrant/nginx/log/frontend-error.log;
|
||||
|
||||
location / {
|
||||
# Redirect everything that isn't a real file to index.php
|
||||
try_files $uri $uri/ /index.php$is_args$args;
|
||||
}
|
||||
|
||||
# uncomment to avoid processing of calls to non-existing static files by Yii
|
||||
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
|
||||
# try_files $uri =404;
|
||||
#}
|
||||
#error_page 404 /404.html;
|
||||
|
||||
location ~ \.php$ {
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
#fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location ~ /\.(ht|svn|git) {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
charset utf-8;
|
||||
client_max_body_size 128M;
|
||||
sendfile off;
|
||||
|
||||
listen 80; ## listen for ipv4
|
||||
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
|
||||
|
||||
server_name y2aa-backend.test;
|
||||
root /app/backend/web/;
|
||||
index index.php;
|
||||
|
||||
access_log /app/vagrant/nginx/log/backend-access.log;
|
||||
error_log /app/vagrant/nginx/log/backend-error.log;
|
||||
|
||||
location / {
|
||||
# Redirect everything that isn't a real file to index.php
|
||||
try_files $uri $uri/ /index.php$is_args$args;
|
||||
}
|
||||
|
||||
# uncomment to avoid processing of calls to non-existing static files by Yii
|
||||
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
|
||||
# try_files $uri =404;
|
||||
#}
|
||||
#error_page 404 /404.html;
|
||||
|
||||
location ~ \.php$ {
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
#fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location ~ /\.(ht|svn|git) {
|
||||
deny all;
|
||||
}
|
||||
}
|
5
vagrant/nginx/log/.gitignore
vendored
Executable file
5
vagrant/nginx/log/.gitignore
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
# nginx logs
|
||||
backend-access.log
|
||||
backend-error.log
|
||||
frontend-access.log
|
||||
frontend-error.log
|
12
vagrant/provision/always-as-root.sh
Executable file
12
vagrant/provision/always-as-root.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source /app/vagrant/provision/common.sh
|
||||
|
||||
#== Provision script ==
|
||||
|
||||
info "Provision-script user: `whoami`"
|
||||
|
||||
info "Restart web-stack"
|
||||
service php7.4-fpm restart
|
||||
service nginx restart
|
||||
service mysql restart
|
9
vagrant/provision/common.sh
Executable file
9
vagrant/provision/common.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#== Bash helpers ==
|
||||
|
||||
function info {
|
||||
echo " "
|
||||
echo "--> $1"
|
||||
echo " "
|
||||
}
|
74
vagrant/provision/once-as-root.sh
Executable file
74
vagrant/provision/once-as-root.sh
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source /app/vagrant/provision/common.sh
|
||||
|
||||
#== Import script args ==
|
||||
|
||||
timezone=$(echo "$1")
|
||||
readonly IP=$2
|
||||
|
||||
#== Provision script ==
|
||||
|
||||
info "Provision-script user: `whoami`"
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
info "Configure timezone"
|
||||
timedatectl set-timezone ${timezone} --no-ask-password
|
||||
|
||||
info "AWK initial replacement work"
|
||||
awk -v ip=$IP -f /app/vagrant/provision/provision.awk /app/environments/dev/*end/config/main-local.php
|
||||
|
||||
info "Prepare root password for MySQL"
|
||||
debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password \"''\""
|
||||
debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password \"''\""
|
||||
echo "Done!"
|
||||
|
||||
info "Update OS software"
|
||||
apt-get update
|
||||
apt-get upgrade -y
|
||||
|
||||
info "Add ppa:ondrej/php"
|
||||
apt-get install -y python-software-properties
|
||||
apt-get update && apt-get upgrade -y
|
||||
add-apt-repository -y ppa:ondrej/php
|
||||
|
||||
info "Install additional software"
|
||||
apt-get install -y php7.4-curl php7.4-cli php7.4-intl php7.4-mysqlnd php7.4-gd php7.4-fpm php7.4-mbstring php7.4-xml unzip nginx mysql-server-5.7 php7.4-xdebug
|
||||
|
||||
info "Configure MySQL"
|
||||
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf
|
||||
mysql -uroot <<< "CREATE USER 'root'@'%' IDENTIFIED BY ''"
|
||||
mysql -uroot <<< "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'"
|
||||
mysql -uroot <<< "DROP USER 'root'@'localhost'"
|
||||
mysql -uroot <<< "FLUSH PRIVILEGES"
|
||||
echo "Done!"
|
||||
|
||||
info "Configure PHP-FPM"
|
||||
sed -i 's/user = www-data/user = vagrant/g' /etc/php/7.4/fpm/pool.d/www.conf
|
||||
sed -i 's/group = www-data/group = vagrant/g' /etc/php/7.4/fpm/pool.d/www.conf
|
||||
sed -i 's/owner = www-data/owner = vagrant/g' /etc/php/7.4/fpm/pool.d/www.conf
|
||||
cat << EOF > /etc/php/7.4/mods-available/xdebug.ini
|
||||
zend_extension=xdebug.so
|
||||
xdebug.remote_enable=1
|
||||
xdebug.remote_connect_back=1
|
||||
xdebug.remote_port=9000
|
||||
xdebug.remote_autostart=1
|
||||
EOF
|
||||
echo "Done!"
|
||||
|
||||
info "Configure NGINX"
|
||||
sed -i 's/user www-data/user vagrant/g' /etc/nginx/nginx.conf
|
||||
echo "Done!"
|
||||
|
||||
info "Enabling site configuration"
|
||||
ln -s /app/vagrant/nginx/app.conf /etc/nginx/sites-enabled/app.conf
|
||||
echo "Done!"
|
||||
|
||||
info "Initailize databases for MySQL"
|
||||
mysql -uroot <<< "CREATE DATABASE yii2advanced"
|
||||
mysql -uroot <<< "CREATE DATABASE yii2advanced_test"
|
||||
echo "Done!"
|
||||
|
||||
info "Install composer"
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
32
vagrant/provision/once-as-vagrant.sh
Executable file
32
vagrant/provision/once-as-vagrant.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source /app/vagrant/provision/common.sh
|
||||
|
||||
#== Import script args ==
|
||||
|
||||
github_token=$(echo "$1")
|
||||
|
||||
#== Provision script ==
|
||||
|
||||
info "Provision-script user: `whoami`"
|
||||
|
||||
info "Configure composer"
|
||||
composer config --global github-oauth.github.com ${github_token}
|
||||
echo "Done!"
|
||||
|
||||
info "Install project dependencies"
|
||||
cd /app
|
||||
composer --no-progress --prefer-dist install
|
||||
|
||||
info "Init project"
|
||||
./init --env=Development --overwrite=y
|
||||
|
||||
info "Apply migrations"
|
||||
./yii migrate --interactive=0
|
||||
./yii_test migrate --interactive=0
|
||||
|
||||
info "Create bash-alias 'app' for vagrant user"
|
||||
echo 'alias app="cd /app"' | tee /home/vagrant/.bash_aliases
|
||||
|
||||
info "Enabling colorized prompt for guest console"
|
||||
sed -i "s/#force_color_prompt=yes/force_color_prompt=yes/" /home/vagrant/.bashrc
|
70
vagrant/provision/provision.awk
Executable file
70
vagrant/provision/provision.awk
Executable file
@ -0,0 +1,70 @@
|
||||
###
|
||||
# Modifying Yii2's files for initialize Vagrant VM
|
||||
#
|
||||
# @author HA3IK <golubha3ik@gmail.com>
|
||||
# @version 1.0.0
|
||||
|
||||
BEGIN {
|
||||
print "AWK BEGINs its work:"
|
||||
IGNORECASE = 1
|
||||
# Correct IP - wildcard last octet
|
||||
match(ip, /(([0-9]+\.)+)/, arr)
|
||||
ip = arr[1] "*"
|
||||
}
|
||||
BEGINFILE {
|
||||
msg = "- Work with: " FILENAME
|
||||
# Define array index for the file
|
||||
switch (FILENAME) {
|
||||
case /environments\/dev\/(back|front)end\/config\/main\-local\.php$/:
|
||||
isFile["IsMainLocConf"] = 1
|
||||
msg = msg " - allow VM IP for Gii and debug toolbar"
|
||||
break
|
||||
}
|
||||
# Print the final message
|
||||
print msg
|
||||
}
|
||||
# BODY
|
||||
{
|
||||
# IF environments/dev/(back|front)end/config/main-local.php
|
||||
if (isFile["IsMainLocConf"]) {
|
||||
# IF the line[s] after yii\(debug|gii)\Module
|
||||
if (FNR == nextLine["nubmer"]) {
|
||||
# Prepare for next line
|
||||
++nextLine["nubmer"]
|
||||
# IF line has "allowedIPs"
|
||||
if (index($0, "allowedIPs")) {
|
||||
# IF our IP is not there
|
||||
if (!index($0, ip)) {
|
||||
# Add it
|
||||
match($0, /([^\]]+)(.+)/, arr)
|
||||
$0 = sprintf("%s, '%s'%s", arr[1], ip, arr[2])
|
||||
}
|
||||
# Delete next line
|
||||
delete nextLine
|
||||
# IF "allowedIPs" are not set - search for the end of an array structure
|
||||
} else if ($0 ~ /\];$/) {
|
||||
# Rewrite line
|
||||
$0 = nextLine["indent"] "'allowedIPs' => ['127.0.0.1', '::1', '" ip "'],\n" $0
|
||||
delete nextLine
|
||||
}
|
||||
# IF line is done
|
||||
if (!length(nextLine)) {
|
||||
printf " Line %d: Allowed IP: %s\n", FNR, ip
|
||||
}
|
||||
# Search for yii\(debug|gii)\Module
|
||||
} else if (match($0, /^(\s+).+yii\\(debug|gii)\\Module/, arr)) {
|
||||
# Save next line and indent
|
||||
nextLine["nubmer"] = FNR + 1
|
||||
nextLine["indent"] = arr[1]
|
||||
}
|
||||
# Rewrite the file
|
||||
print $0 > FILENAME
|
||||
}
|
||||
}
|
||||
ENDFILE {
|
||||
delete isFile
|
||||
close(FILENAME)
|
||||
}
|
||||
END {
|
||||
print "AWK ENDs its work."
|
||||
}
|
Reference in New Issue
Block a user