From 3316b40049f237f77614fd39530e3dd247635a1a Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Thu, 30 Apr 2020 15:35:19 -0700 Subject: [PATCH 01/15] in progress commit --- .gitignore | 3 ++ .gitmodules | 3 ++ Vagrantfile | 81 +++++++++++++++++++++++++++++++++++ lib/functions.rb | 23 ++++++++++ log/README.md | 5 +++ src/etc/profile.d/pmc-env.sh | 3 ++ vvv | 1 + www/default/index.php | 16 +++++++ www/default/phpinfo/index.php | 6 +++ 9 files changed, 141 insertions(+) create mode 100644 .gitmodules create mode 100644 Vagrantfile create mode 100644 lib/functions.rb create mode 100644 log/README.md create mode 100644 src/etc/profile.d/pmc-env.sh create mode 160000 vvv create mode 100644 www/default/index.php create mode 100644 www/default/phpinfo/index.php diff --git a/.gitignore b/.gitignore index e9ee7f7..b0ff0c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ VVV +/.vagrant +/log +/www \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a98d8f9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vvv"] + path = vvv + url = git@github.com:Varying-Vagrant-Vagrants/VVV.git diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..84c694b --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +# -*- mode: ruby -*- +# vi: set ft=ruby ts=2 sw=2 et: +Vagrant.require_version '>= 2.2.4' + +# Define constant for vvv folder +VVV='vvv' + +require "getoptlong" +require 'fileutils' +require 'open3' +require "readline" +require 'yaml' +require './lib/functions.rb' + +# Auto install all required plugins +install_required_plugins() + +# Copy our config.yml to vvv folder, currently there is no way for us to use a different config file from different location +FileUtils.cp( 'config.yml', File.join( 'vvv', 'config', 'config.yml' ) ); + +# Load the VVV Vagrantfile +load File.join( VVV, 'Vagrantfile' ) + +Vagrant.configure('2') do |config| + + config.vm.provision "file", source: "./src/.", destination: "/tmp/pmc-src/" + config.vm.provision "pmc-src", type: 'shell' do |s| + s.inline = "rsync -r /tmp/pmc-src/ / && rm -rf /tmp/pmc-src" + s.privileged = true + end + + # @TODO submit a PR to VVV project to fix some of these issues + # Will require an upstream fix to properly support Vagrantfile load from another folder + # Workaround fix, some of the file folder mapping as Vagranfile load under a sub folder does not reflect vagrant_dir reference :( + + config.vm.synced_folder '../../wp-themes', '/srv/www/wpcom/public_html/wp-content/themes/vip' + + config.vm.synced_folder 'vvv/database/sql/', '/srv/database' + config.vm.synced_folder 'vvv/config/', '/srv/config' + config.vm.synced_folder 'vvv/provision/', '/srv/provision' + config.vm.synced_folder 'vvv/certificates/', '/srv/certificates', create: true + + if File.exist?(File.join(VVV, 'provision', 'provision-custom.sh')) + config.vm.provision 'default', type: 'shell' do |p| + p.path = File.join(VVV, 'provision', 'provision-custom.sh') + end + else + config.vm.provision 'default', type: 'shell' do |p| + p.path = File.join(VVV, 'provision', 'provision.sh') + end + end + config.vm.provision 'dashboard', type: 'shell' do |p| + p.path = File.join(VVV, 'provision', 'provision-dashboard.sh') + end + + $vvv_config['utility-sources'].each do |name, args| + config.vm.provision "utility-source-#{name}", type: 'shell' do |p| + p.path = File.join(VVV, 'provision', 'provision-utility-source.sh') + end + end + + $vvv_config['utilities'].each do |name, utilities| + utilities = {} unless utilities.is_a? Array + utilities.each do |utility| + config.vm.provision "utility-#{name}-#{utility}", type: 'shell' do |p| + p.path = File.join(VVV, 'provision', 'provision-utility.sh') + end + end + end + + $vvv_config['sites'].each do |site, args| + next if args['skip_provisioning'] + + config.vm.provision "site-#{site}", type: 'shell' do |p| + p.path = File.join(VVV, 'provision', 'provision-site.sh') + end + end + +end diff --git a/lib/functions.rb b/lib/functions.rb new file mode 100644 index 0000000..b161a6b --- /dev/null +++ b/lib/functions.rb @@ -0,0 +1,23 @@ +$logger = Vagrant::UI::Colored.new + +def install_required_plugins() + + required_plugins = %w( rb-readline vagrant-ghost vagrant-vbguest vagrant-persistent-storage vagrant-git vagrant-docker-compose vagrant-hostsupdater vagrant-disksize ) + missing_plugins = [] + required_plugins.each do |plugin| + missing_plugins.push(plugin) unless Vagrant.has_plugin? plugin + end + if ! missing_plugins.empty? + install_these = missing_plugins.join(' ') + $logger.warn "Required following plugins: #{install_these}." + if system "vagrant plugin install #{install_these}" + exec "vagrant #{ARGV.join(' ')}" + Kernel.exit!(0) + else + $logger.warn "Error install plugins, please install these plugins then restart vagrant:" + $logger.warn " #{install_these}" + Kernel.exit!(0) + end + end + +end diff --git a/log/README.md b/log/README.md new file mode 100644 index 0000000..2613f4a --- /dev/null +++ b/log/README.md @@ -0,0 +1,5 @@ +# VVV Log Files + +This directory will remain empty until log files are written to by services within the virtual machine. + +By default, PHP errors will be logged here in a `php_errors.log` file. \ No newline at end of file diff --git a/src/etc/profile.d/pmc-env.sh b/src/etc/profile.d/pmc-env.sh new file mode 100644 index 0000000..766ca9d --- /dev/null +++ b/src/etc/profile.d/pmc-env.sh @@ -0,0 +1,3 @@ +XDEBUG_REMOTE_HOST=10.0.2.2 +PMC_PHPUNIT_BOOTSTRAP=/srv/www/pmc/wp-config/bootstrap-phpunit.php +WP_TESTS_DIR=/srv/www/wp-core/wp-tests/tests/phpunit/ diff --git a/vvv b/vvv new file mode 160000 index 0000000..5f26935 --- /dev/null +++ b/vvv @@ -0,0 +1 @@ +Subproject commit 5f269359cb6aaef0df438447d62197a923aaf645 diff --git a/www/default/index.php b/www/default/index.php new file mode 100644 index 0000000..20081ef --- /dev/null +++ b/www/default/index.php @@ -0,0 +1,16 @@ + +

VVV

+

VVV hasn't finished provisioning, and the dashboard hasn't been set up yet. Come back in a minute or two

+ Date: Fri, 1 May 2020 11:52:22 -0700 Subject: [PATCH 02/15] re-configure provision script --- .gitignore | 3 +- Customfile | 31 +++++++++ Vagrantfile | 67 ++----------------- config-tests.yml | 62 +++++++++++++++++ config.yml | 1 + .../www/pmc/wp-config/bootstrap-phpunit.php | 3 + www/default/index.php | 16 ----- www/default/phpinfo/index.php | 6 -- 8 files changed, 106 insertions(+), 83 deletions(-) create mode 100644 Customfile create mode 100644 config-tests.yml create mode 100644 src/srv/www/pmc/wp-config/bootstrap-phpunit.php delete mode 100644 www/default/index.php delete mode 100644 www/default/phpinfo/index.php diff --git a/.gitignore b/.gitignore index b0ff0c2..65b448d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ VVV /.vagrant /log -/www \ No newline at end of file +/www +/git diff --git a/Customfile b/Customfile new file mode 100644 index 0000000..0a5bf8d --- /dev/null +++ b/Customfile @@ -0,0 +1,31 @@ +pmc_vvv=File.realdirpath( '..' ); +pmc_src=File.realdirpath( 'src', '..' ); +pmc_provision_dir=File.realdirpath( 'provision', '..' ); + +config.vm.provider :virtualbox do |v| + v.name = "pmc-vvv_" + (Digest::SHA256.hexdigest vagrant_dir)[0..10] +end + +config.vm.provision "file", before: "pmc-src", source: File.join(pmc_src, '.'), destination: "/tmp/pmc-src/" +config.vm.provision "pmc-src", type: 'shell' do |s| + s.inline = "rsync -r /tmp/pmc-src/ / && rm -rf /tmp/pmc-src" + s.privileged = true +end + +# These are added for local development testing for custom site template provision scripts + +if Dir.exist?(File.join(pmc_vvv, 'git', 'custom-site-template')) + + $vvv_config['sites'].each do |site, args| + next if args['skip_provisioning'] + + $vvv_config['sites'][site]['repo'] = false + + config.vm.provision "dev-file-#{site}", + before: "site-#{site}", + type: 'file', + source: File.join(pmc_vvv, 'git', 'custom-site-template','provision'), + destination: args['vm_dir'] + '/' + end + +end diff --git a/Vagrantfile b/Vagrantfile index 84c694b..ee34284 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -12,70 +12,17 @@ require 'fileutils' require 'open3' require "readline" require 'yaml' -require './lib/functions.rb' +require File.join( __dir__,'lib','functions.rb' ) # Auto install all required plugins install_required_plugins() # Copy our config.yml to vvv folder, currently there is no way for us to use a different config file from different location -FileUtils.cp( 'config.yml', File.join( 'vvv', 'config', 'config.yml' ) ); -# Load the VVV Vagrantfile -load File.join( VVV, 'Vagrantfile' ) +# development testing for now +FileUtils.cp( 'config-tests.yml', File.join( 'vvv', 'config', 'config.yml' ) ); +FileUtils.cp( 'Customfile', File.join( 'vvv', 'Customfile' ) ); -Vagrant.configure('2') do |config| - - config.vm.provision "file", source: "./src/.", destination: "/tmp/pmc-src/" - config.vm.provision "pmc-src", type: 'shell' do |s| - s.inline = "rsync -r /tmp/pmc-src/ / && rm -rf /tmp/pmc-src" - s.privileged = true - end - - # @TODO submit a PR to VVV project to fix some of these issues - # Will require an upstream fix to properly support Vagrantfile load from another folder - # Workaround fix, some of the file folder mapping as Vagranfile load under a sub folder does not reflect vagrant_dir reference :( - - config.vm.synced_folder '../../wp-themes', '/srv/www/wpcom/public_html/wp-content/themes/vip' - - config.vm.synced_folder 'vvv/database/sql/', '/srv/database' - config.vm.synced_folder 'vvv/config/', '/srv/config' - config.vm.synced_folder 'vvv/provision/', '/srv/provision' - config.vm.synced_folder 'vvv/certificates/', '/srv/certificates', create: true - - if File.exist?(File.join(VVV, 'provision', 'provision-custom.sh')) - config.vm.provision 'default', type: 'shell' do |p| - p.path = File.join(VVV, 'provision', 'provision-custom.sh') - end - else - config.vm.provision 'default', type: 'shell' do |p| - p.path = File.join(VVV, 'provision', 'provision.sh') - end - end - config.vm.provision 'dashboard', type: 'shell' do |p| - p.path = File.join(VVV, 'provision', 'provision-dashboard.sh') - end - - $vvv_config['utility-sources'].each do |name, args| - config.vm.provision "utility-source-#{name}", type: 'shell' do |p| - p.path = File.join(VVV, 'provision', 'provision-utility-source.sh') - end - end - - $vvv_config['utilities'].each do |name, utilities| - utilities = {} unless utilities.is_a? Array - utilities.each do |utility| - config.vm.provision "utility-#{name}-#{utility}", type: 'shell' do |p| - p.path = File.join(VVV, 'provision', 'provision-utility.sh') - end - end - end - - $vvv_config['sites'].each do |site, args| - next if args['skip_provisioning'] - - config.vm.provision "site-#{site}", type: 'shell' do |p| - p.path = File.join(VVV, 'provision', 'provision-site.sh') - end - end - -end +Dir.chdir 'vvv' +exec "vagrant #{ARGV.join(' ')}" +Kernel.exit!(0) diff --git a/config-tests.yml b/config-tests.yml new file mode 100644 index 0000000..b7491af --- /dev/null +++ b/config-tests.yml @@ -0,0 +1,62 @@ +--- +sites: + wpcom: + skip_provisioning: false + repo: https://github.com/hauvong/custom-site-template.git + hosts: + - wpcom.test + - bgr.wpcom.test + - pmc-corporate-2018.wpcom.test + - pmc-deadline-2019.wpcom.test + - pmc-footwearnews-2018.wpcom.test + - pmc-hollywoodlife-2017.wpcom.test + - pmc-spy.wpcom.test + - pmc-summits.wpcom.test + - pmc-summits-rr1.wpcom.test + - pmc-summits-variety.wpcom.test + - pmc-summits-wwd.wpcom.test + - pmc-summits.wpcom.test + - pmc-tvline.wpcom.test + - pmc-variety-2017.wpcom.test + - pmc-wwd-2016.wpcom.test + - pmc-variety-2020.wpcom.test + custom: + wp_type: subdomain + wp_tests: true + + vipgo: + skip_provisioning: false + repo: https://github.com/hauvong/custom-site-template.git + hosts: + - vipgo.test + - rollingstone.vipgo.test + - artnews.vipgo.test + - goldderby.vipgo.test + - sheknows.vipgo.test + - soaps.vipgo.test + custom: + wp_type: vipgo + wp_tests: true + +utilities: + core: + - memcached-admin + - mongodb + - opcache-status + - php74 + - phpmyadmin + - tideways + - tls-ca + - webgrind + +vm_config: + cores: 4 + memory: 4096 + +general: + db_backup: true + db_restore: true + db_share_type: false + +vagrant-plugins: + disksize: 10GB diff --git a/config.yml b/config.yml index e8d42d6..49192a2 100644 --- a/config.yml +++ b/config.yml @@ -22,6 +22,7 @@ sites: - pmc-variety-2020.wpcom.test custom: wp_type: subdomain + wp_tests: true # VIPGO sites: # @NOTE: name === theme-name && host diff --git a/src/srv/www/pmc/wp-config/bootstrap-phpunit.php b/src/srv/www/pmc/wp-config/bootstrap-phpunit.php new file mode 100644 index 0000000..7f2c067 --- /dev/null +++ b/src/srv/www/pmc/wp-config/bootstrap-phpunit.php @@ -0,0 +1,3 @@ + -

VVV

-

VVV hasn't finished provisioning, and the dashboard hasn't been set up yet. Come back in a minute or two

- Date: Fri, 1 May 2020 15:42:01 -0700 Subject: [PATCH 03/15] get phpunit working --- src/etc/{profile.d/pmc-env.sh => environment} | 2 + .../www/pmc/wp-config/bootstrap-phpunit.php | 85 +++++- src/srv/www/pmc/wp-config/bootstrap.php | 244 ++++++++++++++++++ src/srv/www/pmc/wp-config/functions.php | 30 +++ 4 files changed, 360 insertions(+), 1 deletion(-) rename src/etc/{profile.d/pmc-env.sh => environment} (57%) create mode 100644 src/srv/www/pmc/wp-config/bootstrap.php create mode 100644 src/srv/www/pmc/wp-config/functions.php diff --git a/src/etc/profile.d/pmc-env.sh b/src/etc/environment similarity index 57% rename from src/etc/profile.d/pmc-env.sh rename to src/etc/environment index 766ca9d..faedd18 100644 --- a/src/etc/profile.d/pmc-env.sh +++ b/src/etc/environment @@ -1,3 +1,5 @@ +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/srv/config/homebin XDEBUG_REMOTE_HOST=10.0.2.2 PMC_PHPUNIT_BOOTSTRAP=/srv/www/pmc/wp-config/bootstrap-phpunit.php WP_TESTS_DIR=/srv/www/wp-core/wp-tests/tests/phpunit/ +WP_CONFIG_BOOTSTRAP=true \ No newline at end of file diff --git a/src/srv/www/pmc/wp-config/bootstrap-phpunit.php b/src/srv/www/pmc/wp-config/bootstrap-phpunit.php index 7f2c067..35eb3bc 100644 --- a/src/srv/www/pmc/wp-config/bootstrap-phpunit.php +++ b/src/srv/www/pmc/wp-config/bootstrap-phpunit.php @@ -1,3 +1,86 @@ _bootstrap = $matches[0] . 'pmc-unit-test/bootstrap.php'; + } + + parent::__construct(); + + $theme_folder = dirname( $this->site_info->folder ); + if ( empty( $this->_bootstrap ) ) { + if ( file_exists( $theme_folder . '/pmc-plugins/pmc-unit-test/bootstrap.php' ) ) { + $this->_bootstrap = $theme_folder . '/pmc-plugins/pmc-unit-test/bootstrap.php'; + } else { + if ( preg_match( '#^.*/wp-content#', $this->site_info->folder, $matches ) ) { + if ( file_exists( $matches[0] . '/plugins/pmc-plugins/pmc-unit-test/bootstrap.php' ) ) { + $this->_bootstrap = $matches[0] . '/plugins/pmc-plugins/pmc-unit-test/bootstrap.php'; + } + } + if ( empty( $this->_bootstrap ) ) { + if ( file_exists( '/srv/www/pmc/coretech/pmc-plugins/pmc-unit-test/bootstrap.php' ) ) { + $this->_bootstrap = '/srv/www/pmc/coretech/pmc-plugins/pmc-unit-test/bootstrap.php'; + } + } + } + } + + $phpunit_dir = getenv( 'WP_TESTS_DIR' ); + if ( empty( $phpunit_dir ) || ! file_exists( $phpunit_dir ) ) { + $phpunit_dir = false; + if ( preg_match( '#(.*)/[^/]+/wp-content/#', $theme_folder, $matches ) ) { + if ( file_exists( $matches[1] . '/wp-tests/phpunit' ) ) { + $phpunit_dir = $matches[1] . '/wp-tests/phpunit'; + } + } + } + if ( empty( $phpunit_dir ) || ! file_exists( $phpunit_dir ) ) { + throw new \Error( 'Cannot auto detect location for wp-tests folder' ); + } + putenv( 'WP_TESTS_DIR=' . $phpunit_dir ); + if ( file_exists( $phpunit_dir . '/../wp-tests-config.php' ) ) { + ifndef( 'WP_TESTS_CONFIG_FILE_PATH', realpath( $phpunit_dir . '/../wp-tests-config.php' ) ); + } + + } + + /** + * phpunit test should always active once it is manually referenced + */ + public function is_active() { + return true; + } + + public function start() { + if ( empty( $this->_bootstrap ) ) { + throw new \Error( sprintf('Cannot auto detect pmc plugin bootstrap file location' ) ); + } + if ( ! file_exists( $this->_bootstrap ) ) { + throw new \Error( sprintf('Cannot locate bootstrap file: %s', $this->_bootstrap ) ); + } + require_once $this->_bootstrap; + } +} + +Bootstrap_Phpunit::get_instance()->start(); diff --git a/src/srv/www/pmc/wp-config/bootstrap.php b/src/srv/www/pmc/wp-config/bootstrap.php new file mode 100644 index 0000000..e358ed6 --- /dev/null +++ b/src/srv/www/pmc/wp-config/bootstrap.php @@ -0,0 +1,244 @@ +is_active() ) { + return; + } + + $this->define_constants(); + + } + + /** + * Determine if wp configuration bootstrap is active or not + * @return bool + */ + public function is_active() { + $use_bootstrap = getenv( 'WP_CONFIG_BOOTSTRAP' ); + return ( ! empty( $use_bootstrap ) && in_array( $use_bootstrap, [ 'true', 'yes' ], true ) ); + } + + public function start() { + $this->maybe_create_db(); + } + + /** + * Helper function to auto create database if not exist avoiding having to manually create each db for multiple project development + */ + public function maybe_create_db() { + $dbh = mysqli_init(); + mysqli_real_connect( $dbh, DB_HOST, DB_USER, DB_PASSWORD ); + + if ( ! $dbh ) { + return; + } + + $sql = sprintf( 'create database if not exists %s;', DB_NAME ); + mysqli_query( $dbh, $sql ); + mysqli_select_db( $dbh, DB_NAME ); + + } + + /** + * Responsible to detect and setup various WP constant for VIP Go vs VIP Classic configuration + */ + public function define_constants() { + $site = $this->detect_site(); + + if ( $site ) { + if ( defined( 'IS_UNIT_TEST' ) && IS_UNIT_TEST ) { + unset( $site->db_name ); + unset( $site->hosts ); + } + + if ( ! empty( $site->hosts ) ) { + if ( empty( $_SERVER['HTTP_HOST'] ) || ! in_array( $_SERVER['HTTP_HOST'], $site->hosts ) ) { + $_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME'] = $site->hosts[0]; + } + } + + if ( ! empty( $site->db_name ) ) { + ifdefenv( 'DB_NAME', $site->db_name ); + } + + if ( ! empty( $site->name ) ) { + ifndef( 'SITE_NAME', $site->name ); + } + + if ( ! empty( $site->hosting_env ) ) { + switch( $site->hosting_env ) { + case "vipclassic": + ifdefenv('IS_VIP_GO', false); + break; + case "vipgo": + ifdefenv('IS_VIP_GO', true); + break; + default: + break; + } + } + + if ( ! empty( $_SERVER['HTTP_HOST'] ) ) { + ifndef( 'WP_HOME', 'https://'. $_SERVER['HTTP_HOST'] ); + ifndef( 'WP_SITEURL', WP_HOME ); + } + + } + + if ( defined( 'DB_NAME' ) ) { + ifndef( 'AUTH_KEY', DB_NAME ); + ifndef( 'AUTH_SALT', DB_NAME ); + ifndef( 'NONCE_KEY', DB_NAME ); + ifndef( 'NONCE_SALT', DB_NAME ); + ifndef( 'LOGGED_IN_KEY', DB_NAME ); + ifndef( 'LOGGED_IN_SALT', DB_NAME ); + ifndef( 'SECURE_AUTH_KEY', DB_NAME ); + ifndef( 'SECURE_AUTH_SALT', DB_NAME ); + } + + ifndef( 'IS_VIP_GO', true ); + if ( IS_VIP_GO ) { + ifndef( 'VIP_GO_ENV', 'dev' ); + ifndef( 'PMC_IS_VIP_GO_SITE', true ); + } + + } + + /** + * Auto detect current site base on available wp themes information + * @return array|bool|mixed|object + */ + public function detect_site() { + $this->detect_wp_themes(); + $cwd = getcwd(); + if ( isset( $_SERVER['HTTP_HOST'] ) ) { + foreach ( $this->_wp_themes_info as $item ) { + if ( in_array( $_SERVER['HTTP_HOST'], $item->hosts ) ) { + $this->site_info = $item; + break; + } + if ( $cwd === $item->folder ) { + $this->site_info = $item; + break; + } + } + } else { + $this->site_info = $this->get_folder_info( $cwd ); + } + return $this->site_info; + } + + /** + * Auto detect all available themes + */ + public function detect_wp_themes() { + // @TODO: + } + + /** + * Helper function to load and detect theme folder for related information + * @param $folder + * @return array|mixed|object + */ + public function get_folder_info( $folder ) { + + if ( file_exists( $folder . '/.pmc-dev.json' ) ) { + $settings = json_decode( file_get_contents( $folder . '/.pmc-dev.json' ), false ); + if ( empty( $settings ) ) { + $settings = (object) []; + } + } else { + $settings = (object) []; + } + + if ( preg_match( '@/pmc-plugins@', $folder ) ) { + $settings = (object)[ + 'hosting_env' => 'vipclassic', + 'hosts' => [ 'pmc-plugins.' . $this->_domain ], + 'name' => 'pmc-plugins', + 'theme' => false, + ]; + } + + $settings->folder = $folder; + if ( ! isset( $settings->theme ) ) { + $settings->theme = basename( $folder ); + if ( preg_match( '#(?:vip/)?[^/]+$#', $folder, $matches ) ) { + $settings->theme = $matches[0]; + } + } + + if ( ! isset( $settings->name ) ) { + $name = basename( $folder ); + $name = str_replace( 'pmc-', '', $name ); + $name = preg_replace( '/-\d+.*/', '', $name ); + $settings->name = $name; + } + + if ( empty( $settings->hosts ) ) { + $settings->hosts = [ + $settings->name . '.' . $this->_domain, + basename( $settings->theme ) . '.' . $this->_domain, + ]; + } elseif ( ! in_array( basename( $settings->theme ) . '.' . $this->_domain, $settings->hosts ) ) { + $settings->hosts[] = basename( $settings->theme ) . '.' . $this->_domain; + } + + if ( empty( $settings->hosting_env ) ) { + if ( file_exists( $settings->folder . '/docker-compose.yml' ) ) { + $bufs = file_get_contents( $settings->folder . '/docker-compose.yml' ); + if ( strpos( $bufs, 'vipclassic' ) ) { + $settings->hosting_env = 'vipclassic'; + } elseif ( strpos( $bufs, 'vipgo' ) ) { + $settings->hosting_env = 'vipgo'; + } + } + if ( empty( $settings->hosting_env ) ) { + if ( 'vip/' === substr( $settings->theme, 4 ) || preg_match( '#^.*/wpcom/#', $settings->folder, $matches ) ) { + $settings->hosting_env = 'vipclassic'; + } elseif ( preg_match( '#^.*/vipgo/#', $settings->folder, $matches ) ) { + $settings->hosting_env = 'vipgo'; + } else { + $settings->hosting_env = false; + } + } + } + + return $settings; + + } + +} + +Bootstrap::get_instance(); diff --git a/src/srv/www/pmc/wp-config/functions.php b/src/srv/www/pmc/wp-config/functions.php new file mode 100644 index 0000000..1780286 --- /dev/null +++ b/src/srv/www/pmc/wp-config/functions.php @@ -0,0 +1,30 @@ + Date: Fri, 1 May 2020 20:27:49 -0700 Subject: [PATCH 04/15] Add unit test support for pmc/coretech/pmc-plugins --- config-tests.yml | 9 +++++ .../www/pmc/wp-config/bootstrap-phpunit.php | 38 ++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/config-tests.yml b/config-tests.yml index b7491af..de81beb 100644 --- a/config-tests.yml +++ b/config-tests.yml @@ -1,5 +1,14 @@ --- sites: + pmc: + skip_provisioning: false + repo: https://github.com/hauvong/custom-site-template.git + hosts: + - pmc.test + custom: + wp_type: vipgo + wp_tests: true + wpcom: skip_provisioning: false repo: https://github.com/hauvong/custom-site-template.git diff --git a/src/srv/www/pmc/wp-config/bootstrap-phpunit.php b/src/srv/www/pmc/wp-config/bootstrap-phpunit.php index 35eb3bc..9fcc68b 100644 --- a/src/srv/www/pmc/wp-config/bootstrap-phpunit.php +++ b/src/srv/www/pmc/wp-config/bootstrap-phpunit.php @@ -46,20 +46,46 @@ protected function __construct() { } } - $phpunit_dir = getenv( 'WP_TESTS_DIR' ); + if ( ! empty( $this->site_info->wp_tests_folder ) ) { + $phpunit_dir = $this->site_info->wp_tests_folder; + } + if ( empty( $phpunit_dir ) || ! file_exists( $phpunit_dir ) ) { - $phpunit_dir = false; - if ( preg_match( '#(.*)/[^/]+/wp-content/#', $theme_folder, $matches ) ) { - if ( file_exists( $matches[1] . '/wp-tests/phpunit' ) ) { - $phpunit_dir = $matches[1] . '/wp-tests/phpunit'; + + $phpunit_dir = getenv( 'WP_TESTS_DIR' ); + if ( empty( $phpunit_dir ) || !file_exists( $phpunit_dir ) ) { + $phpunit_dir = false; + if ( preg_match( '#(.*)/[^/]+/wp-content/#', $theme_folder, $matches ) ) { + if ( file_exists( $matches[1] . '/wp-tests/phpunit' ) ) { + $phpunit_dir = $matches[1] . '/wp-tests/phpunit'; + } + } + $check_dir = $theme_folder; + $check_level = 10; + while ( $check_level > 0 && !$phpunit_dir && !empty( $check_dir ) && ! in_array( $check_dir, [ '.', '/' ], true ) ) { + $check_level -= 1; + $check_dir = dirname( $check_dir ); + if ( in_array( $check_dir, [ '.', '/' ], true ) ) { + break; + } + if ( file_exists( $check_dir . '/wp-tests/phpunit' ) ) { + $phpunit_dir = $check_dir . '/wp-tests/phpunit'; + } } + } + } + if ( empty( $phpunit_dir ) || ! file_exists( $phpunit_dir ) ) { throw new \Error( 'Cannot auto detect location for wp-tests folder' ); } putenv( 'WP_TESTS_DIR=' . $phpunit_dir ); - if ( file_exists( $phpunit_dir . '/../wp-tests-config.php' ) ) { + + if ( file_exists( $phpunit_dir . '/wp-tests-config.php' ) ) { + ifndef( 'WP_TESTS_CONFIG_FILE_PATH', realpath( $phpunit_dir . '/wp-tests-config.php' ) ); + } + elseif ( file_exists( $phpunit_dir . '/../wp-tests-config.php' ) ) { ifndef( 'WP_TESTS_CONFIG_FILE_PATH', realpath( $phpunit_dir . '/../wp-tests-config.php' ) ); } From 9060aa70cd1ca4a45566fed5c1b418e759367f85 Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Thu, 14 May 2020 11:45:01 -0700 Subject: [PATCH 05/15] add support to provision vipgo & vip classic sites --- Customfile | 117 ++++++++++++++++-- Vagrantfile | 7 ++ config-tests.yml | 20 ++- config.yml | 1 + lib/functions.rb | 53 +++++++- provision/provision-bind-mount.sh | 74 +++++++++++ src/etc/environment | 6 +- vvv | 2 +- .../wp-config/bootstrap-phpunit.php | 0 .../pmc => wp-core}/wp-config/bootstrap.php | 0 .../pmc => wp-core}/wp-config/functions.php | 0 11 files changed, 257 insertions(+), 23 deletions(-) create mode 100644 provision/provision-bind-mount.sh rename {src/srv/www/pmc => wp-core}/wp-config/bootstrap-phpunit.php (100%) rename {src/srv/www/pmc => wp-core}/wp-config/bootstrap.php (100%) rename {src/srv/www/pmc => wp-core}/wp-config/functions.php (100%) diff --git a/Customfile b/Customfile index 0a5bf8d..45b107f 100644 --- a/Customfile +++ b/Customfile @@ -2,30 +2,123 @@ pmc_vvv=File.realdirpath( '..' ); pmc_src=File.realdirpath( 'src', '..' ); pmc_provision_dir=File.realdirpath( 'provision', '..' ); +require File.join( pmc_vvv,'lib','functions.rb' ) + +# custom mapping for pmc specific improvement +config.vm.synced_folder File.join(pmc_vvv, 'wp-core'), '/srv/wp-core', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true +config.vm.synced_folder File.join(pmc_vvv, 'wp-themes'), '/srv/wp-themes', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true +config.vm.synced_folder pmc_vvv, '/srv/pmc-vvv', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true + +# we want to override some default from VVV to settings we know work properly from pmc-qs7 config.vm.provider :virtualbox do |v| - v.name = "pmc-vvv_" + (Digest::SHA256.hexdigest vagrant_dir)[0..10] + + # rename the VM since we are customized the setting to PMC specificiation + v.name = "pmc-vvv_" + (Digest::SHA256.hexdigest pmc_vvv)[0..10] + + # Allow the VM to utilize up to 1/2 of the host cpu cores + v.cpus = detect_max_cpus 2, 0.5 + + # Allow the VM to utilize up to 3/4 of the host system memory + v.memory = detect_max_mem 4096, 0.75 + + # Only allow the VM to use up-to 50% of the host system cpu + # Windows OS, the server may hang if cpu allow to reach 100% + v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"] + + # Instruct Vagrant to utilize all the cpu cores we've provided above + # Without this, only 1 core will be used + v.customize ["modifyvm", :id, "--ioapic", "on"] + + # Plug in the virtual network adapter as if it were a real cat-5 cable + # plugged into a real network card. This corrects an error presented with + # Ubuntu 16 where boot hangs on: "A start job is running for Raise network interfaces" + # This error occurs because Ubuntu tries to raise all the network interfaces, + # but the 'cable' isn't connected, so it waits until the timeout. + # Note, this is the same as selecting 'Cable Connect' for the network adapter + # in the VirtualBox app settings for this box. + # https://github.com/hashicorp/vagrant/issues/8056#issuecomment-267600935 + v.customize ["modifyvm", :id, "--cableconnected1", "on"] + + # Turn off un-use devices + v.customize ["modifyvm", :id, "--usb", "off"] + v.customize ["modifyvm", :id, "--usbehci", "off"] + v.customize ["modifyvm", :id, "--usbxhci", "off"] + v.customize ["modifyvm", :id, "--accelerate3d", "off"] + v.customize ["modifyvm", :id, "--accelerate2dvideo", "off"] + v.customize ["modifyvm", :id, "--audio", "none"] + v.customize ["modifyvm", :id, "--vrde", "off"] + end -config.vm.provision "file", before: "pmc-src", source: File.join(pmc_src, '.'), destination: "/tmp/pmc-src/" +# In order to add files to /etc folder, we need to access the privileged script to do the copy +# First we need to add the source to a temporarly folder +config.vm.provision "file", + before: "pmc-src", + source: File.join(pmc_src, '.'), + destination: "/tmp/pmc-src/" +# We then execute a shell script inside VM with admin privilege to copy the files config.vm.provision "pmc-src", type: 'shell' do |s| s.inline = "rsync -r /tmp/pmc-src/ / && rm -rf /tmp/pmc-src" s.privileged = true end -# These are added for local development testing for custom site template provision scripts +# Implementing PMC specific provision for each site that can't be done by common provision template +$vvv_config['sites'].each do |site, args| + next if args['skip_provisioning'] -if Dir.exist?(File.join(pmc_vvv, 'git', 'custom-site-template')) + # @TODO: optionally change www folder to our pmc_vvv folder, maybe add a flag to turn on/off + # args['local_dir'] = File.join(pmc_vvv, 'www', site) + # $vvv_config['sites'][site]['local_dir'] = args['local_dir'] - $vvv_config['sites'].each do |site, args| - next if args['skip_provisioning'] + # In order to properly develop and test provision script directly on local, + # we need to override and map the custom-site-template folder + if Dir.exist?(File.join(pmc_vvv, 'git', 'custom-site-template')) + # override and disable remote repo since we want use our local template $vvv_config['sites'][site]['repo'] = false - config.vm.provision "dev-file-#{site}", - before: "site-#{site}", - type: 'file', - source: File.join(pmc_vvv, 'git', 'custom-site-template','provision'), - destination: args['vm_dir'] + '/' - end + # map the custom provision script directly into the folder so we can develop the scripts without copying between the folders + config.vm.synced_folder File.join(pmc_vvv, 'git', 'custom-site-template','provision'), '/srv/www/' + site + '/provision', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true + end + + # VIP GO/Classic + if args['custom']['wp_vip'] && File.exist?(File.join(pmc_vvv, 'provision', 'provision-bind-mount.sh')) + + # We could let's vagrant auto map the shared folder, + # however the VVV site provision script doesn't support remote git repo checkout into non-empty folder + + config.vm.provision "bind-mount-#{site}", + after: "site-#{site}", + run: 'always', + type: 'shell', + keep_color: true, + path: File.join(pmc_vvv, 'provision', 'provision-bind-mount.sh'), + args: [ + site, + args['vm_dir'], + args['custom']['wp_vip'], + args['custom']['share_code'].to_s + ], + env: { "VVV_LOG" => "bind-mount-#{site}" } + + # These code would be preferred if VVV site provision script support git repo checkout into non-empty folder + # These codes are commented out for knowledge sharing and potential future improvement + <<~END_COMMENT + + if args['custom']['wp_vip'].include? "go" + # Prepare local folders mapping: wp-content/plugins/pmc-plugins -> pmc-vvv/wp-themes/pmc-plugins, wp-content/themes -> pmc-vvv/wp-themes + Dir.mkdir( File.join( wp_content_dir, 'plugins' ) ) unless Dir.exist?( File.join( wp_content_dir, 'plugins' ) ) + Dir.mkdir( File.join( wp_content_dir, 'plugins', 'pmc-plugins' ) ) unless Dir.exist?( File.join( wp_content_dir, 'plugins', 'pmc-plugins' ) ) + config.vm.synced_folder File.join( pmc_vvv, 'wp-themes' ), '/srv/www/' + site + '/wp-content/themes', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true + config.vm.synced_folder File.join( pmc_vvv, 'wp-themes/pmc-plugins' ), '/srv/www/' + site + '/wp-content/plugins/pmc-plugins', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true + elseif args['custom']['wp_vip'].include? "classic" + # Prepare local folders mapping: wp-content/themes/vip -> pmc-vvv/wp-themes + Dir.mkdir( File.join( wp_content_dir, 'themes', 'vip' ) ) unless Dir.exist?( File.join( wp_content_dir, 'themes', 'vip' ) ) + config.vm.synced_folder File.join( pmc_vvv, 'wp-themes' ), '/srv/www/' + site + '/wp-content/themes/vip', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true + end + + END_COMMENT + + end end diff --git a/Vagrantfile b/Vagrantfile index ee34284..4228936 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -17,12 +17,19 @@ require File.join( __dir__,'lib','functions.rb' ) # Auto install all required plugins install_required_plugins() +Dir.mkdir("./www") unless Dir.exist?("./www") +Dir.mkdir("./wp-themes") unless Dir.exist?("./wp-themes") +Dir.mkdir("./wp-themes/plugins") unless Dir.exist?("./wp-themes/plugins") +Dir.mkdir("./wp-themes/pmc-plugins") unless Dir.exist?("./wp-themes/pmc-plugins") +Dir.mkdir("./wp-themes/pmc-core-v2") unless Dir.exist?("./wp-themes/pmc-core-v2") + # Copy our config.yml to vvv folder, currently there is no way for us to use a different config file from different location # development testing for now FileUtils.cp( 'config-tests.yml', File.join( 'vvv', 'config', 'config.yml' ) ); FileUtils.cp( 'Customfile', File.join( 'vvv', 'Customfile' ) ); +ENV['VVV_SKIP_LOGO'] = 'true' Dir.chdir 'vvv' exec "vagrant #{ARGV.join(' ')}" Kernel.exit!(0) diff --git a/config-tests.yml b/config-tests.yml index de81beb..2f74d89 100644 --- a/config-tests.yml +++ b/config-tests.yml @@ -6,8 +6,10 @@ sites: hosts: - pmc.test custom: - wp_type: vipgo +# share_code: true + wp_type: single wp_tests: true + wp_version: 5.4 wpcom: skip_provisioning: false @@ -30,8 +32,11 @@ sites: - pmc-wwd-2016.wpcom.test - pmc-variety-2020.wpcom.test custom: - wp_type: subdomain +# share_code: true + wp_type: single + wp_vip: classic wp_tests: true + wp_version: 5.4 vipgo: skip_provisioning: false @@ -44,17 +49,20 @@ sites: - sheknows.vipgo.test - soaps.vipgo.test custom: - wp_type: vipgo +# share_code: true + wp_type: single + wp_vip: vipgo wp_tests: true + wp_version: 5.4 utilities: core: - memcached-admin - - mongodb +# - mongodb - opcache-status - - php74 + - php73 - phpmyadmin - - tideways +# - tideways - tls-ca - webgrind diff --git a/config.yml b/config.yml index 49192a2..ce0490f 100644 --- a/config.yml +++ b/config.yml @@ -24,6 +24,7 @@ sites: wp_type: subdomain wp_tests: true + # VIPGO sites: # @NOTE: name === theme-name && host # diff --git a/lib/functions.rb b/lib/functions.rb index b161a6b..d07af5a 100644 --- a/lib/functions.rb +++ b/lib/functions.rb @@ -2,7 +2,11 @@ def install_required_plugins() - required_plugins = %w( rb-readline vagrant-ghost vagrant-vbguest vagrant-persistent-storage vagrant-git vagrant-docker-compose vagrant-hostsupdater vagrant-disksize ) + # vagrant-persistent-storage + # vagrant-git + # vagrant-docker-compose + + required_plugins = %w( rb-readline vagrant-ghost vagrant-vbguest vagrant-hostsupdater vagrant-disksize ) missing_plugins = [] required_plugins.each do |plugin| missing_plugins.push(plugin) unless Vagrant.has_plugin? plugin @@ -21,3 +25,50 @@ def install_required_plugins() end end + +# @see https://github.com/psudug/nittany-vagrant/blob/master/Vagrantfile +def detect_max_cpus( default = 1, multiplier = 1 ) + host_os = RbConfig::CONFIG['host_os'] + cpus = 0 + + # Give VM 1/4 system memory & access to all cpu cores on the host + if host_os =~ /darwin/ + cpus = `sysctl -n hw.ncpu`.to_i + elsif host_os =~ /linux/ + cpus = `nproc`.to_i + elsif host_os =~ /mingw32/ + cpus = `wmic cpu get NumberOfLogicalProcessors | grep '^[0-9]'`.to_i + end + + if cpus <= 0 + return default + end + + return (cpus * multiplier).round +end + +# @see https://github.com/psudug/nittany-vagrant/blob/master/Vagrantfile +def detect_max_mem( default = 1024, multiplier = 1 ) + host_os = RbConfig::CONFIG['host_os'] + mem = 0 + + # Give VM 1/4 system memory & access to all cpu cores on the host + if host_os =~ /darwin/ + # sysctl returns Bytes and we need to convert to MB + mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 + elsif host_os =~ /linux/ + # meminfo shows KB and we need to convert to MB + mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 + elsif host_os =~ /mingw32/ + mem = `wmic os get TotalVisibleMemorySize | grep '^[0-9]'`.to_i / 1024 + if mem < 1024 + mem = 1024 + end + end + + if mem <= 0 + return default + end + + return (mem * multiplier).round +end diff --git a/provision/provision-bind-mount.sh b/provision/provision-bind-mount.sh new file mode 100644 index 0000000..90911ce --- /dev/null +++ b/provision/provision-bind-mount.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +# We need this script to bind mount various folder +# avoid using symlink where wordpress may not work properly with symlink. +# +# VIP Go +# wp-content/plugins/pmc-plugins -> /srv/www/pmc/coretech/pmc-plugins +# wp-content/themes/pmc-core-v2 -> /srv/www/pmc/coretech/pmc-core-v2 +# +# VIP Classic +# wp-content/themes/vip/pmc-plugins -> /srv/www/pmc/coretech/pmc-plugins +# wp-content/themes/vip/pmc-core-v2 -> /srv/www/pmc/coretech/pmc-core-v2 +# +# If share code is enabled, the following structures are used +# +# VIP Go +# wp-content/plugins/pmc-plugins -> /srv/wp-themes/pmc-plugins +# wp-content/themes -> /srv/wp-themes +# wp-content/themes/vip -> /srv/wp-themes +# +# VIP Classic +# wp-content/themes/vip -> /srv/wp-themes +# +# @TODO +# public_html/wordpress -> /srv/wp-core/wordpress-[version] +# public_html/wp-tests/phpunit/includes -> /srv/wp-core/wp-tests-[version]/phpunit/includes +# + +SITE=$1 +VM_DIR=$2 +WP_VIP=$3 +SHARE_CODE=$4 + +echo "Setup bind mount for site ${SITE}: ${WP_VIP}" + +WP_CORE_DIR="${VM_DIR}/public_html" +WP_CONTENT_DIR="${WP_CORE_DIR}/wp-content" +WP_PLUGINS_DIR="${WP_CONTENT_DIR}/plugins" +WP_MU_PLUGINS_DIR="${WP_CONTENT_DIR}/mu-plugins" + +function bind_mount() { + local SOURCE=$1 + local TARGET=$2 + if [[ -n "$(mount | grep ${TARGET})" ]]; then + umount ${TARGET} + fi + mkdir -p ${SOURCE} ${TARGET} + mount --bind ${SOURCE} ${TARGET} +} + +if [[ "true" == "${SHARE_CODE}" ]]; then + + SOURCE_THEMES_DIR=/srv/wp-themes + + if [[ "${WP_VIP}" =~ go ]]; then + mount --bind ${SOURCE_THEMES_DIR}/pmc-plugins ${WP_PLUGINS_DIR}/pmc-plugins + mount --bind ${SOURCE_THEMES_DIR} ${WP_CONTENT_DIR}/themes + mount --bind ${SOURCE_THEMES_DIR} ${WP_CONTENT_DIR}/themes/vip + elif [[ "${WP_VIP}" =~ classic ]]; then + mount --bind ${SOURCE_THEMES_DIR} ${WP_CONTENT_DIR}/themes/vip + fi + +else + + SOURCE_PMC_CORETECH=/srv/www/pmc/coretech + mount --bind ${SOURCE_PMC_CORETECH}/pmc-core-v2 ${WP_CONTENT_DIR}/themes/pmc-core-v2 + + if [[ "${WP_VIP}" =~ go ]]; then + mount --bind ${SOURCE_PMC_CORETECH}/pmc-plugins ${WP_PLUGINS_DIR}/pmc-plugins + elif [[ "${WP_VIP}" =~ classic ]]; then + mount --bind ${SOURCE_PMC_CORETECH}/pmc-plugins ${WP_CONTENT_DIR}/themes/vip/pmc-plugins + fi + +fi diff --git a/src/etc/environment b/src/etc/environment index faedd18..3a7b641 100644 --- a/src/etc/environment +++ b/src/etc/environment @@ -1,5 +1,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/srv/config/homebin XDEBUG_REMOTE_HOST=10.0.2.2 -PMC_PHPUNIT_BOOTSTRAP=/srv/www/pmc/wp-config/bootstrap-phpunit.php -WP_TESTS_DIR=/srv/www/wp-core/wp-tests/tests/phpunit/ -WP_CONFIG_BOOTSTRAP=true \ No newline at end of file +PMC_PHPUNIT_BOOTSTRAP=/srv/wp-core/wp-config/bootstrap-phpunit.php +WP_TESTS_DIR=/srv/wp-core/wp-tests/tests/phpunit/ +WP_CONFIG_BOOTSTRAP=true diff --git a/vvv b/vvv index 5f26935..8311142 160000 --- a/vvv +++ b/vvv @@ -1 +1 @@ -Subproject commit 5f269359cb6aaef0df438447d62197a923aaf645 +Subproject commit 83111426b29b5b7aaf0e8f696651e1bf24860b92 diff --git a/src/srv/www/pmc/wp-config/bootstrap-phpunit.php b/wp-core/wp-config/bootstrap-phpunit.php similarity index 100% rename from src/srv/www/pmc/wp-config/bootstrap-phpunit.php rename to wp-core/wp-config/bootstrap-phpunit.php diff --git a/src/srv/www/pmc/wp-config/bootstrap.php b/wp-core/wp-config/bootstrap.php similarity index 100% rename from src/srv/www/pmc/wp-config/bootstrap.php rename to wp-core/wp-config/bootstrap.php diff --git a/src/srv/www/pmc/wp-config/functions.php b/wp-core/wp-config/functions.php similarity index 100% rename from src/srv/www/pmc/wp-config/functions.php rename to wp-core/wp-config/functions.php From 3ad3f8126b8d79e7cbe11985cb259bf9f26a5aef Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Fri, 15 May 2020 09:04:24 -0700 Subject: [PATCH 06/15] Add ability to checkout wp plugins & themes from a git repository --- .gitignore | 4 + Customfile | 70 ++++++++--------- Vagrantfile | 7 +- config-tests.yml | 28 +++---- config/.ssh/config | 5 ++ config/.ssh/pmc-readonly | 27 +++++++ config/.ssh/pmc-readonly.pub | 1 + {src => config}/etc/environment | 4 +- log/README.md | 5 -- provision/provision-bind-mount.sh | 78 ++++++++++++------- provision/provision-coretech.sh | 66 ++++++++++++++++ .../wp-core}/wp-config/bootstrap-phpunit.php | 0 .../wp-core}/wp-config/bootstrap.php | 0 .../wp-core}/wp-config/functions.php | 0 14 files changed, 204 insertions(+), 91 deletions(-) create mode 100644 config/.ssh/config create mode 100644 config/.ssh/pmc-readonly create mode 100644 config/.ssh/pmc-readonly.pub rename {src => config}/etc/environment (52%) delete mode 100644 log/README.md create mode 100644 provision/provision-coretech.sh rename {wp-core => src/wp-core}/wp-config/bootstrap-phpunit.php (100%) rename {wp-core => src/wp-core}/wp-config/bootstrap.php (100%) rename {wp-core => src/wp-core}/wp-config/functions.php (100%) diff --git a/.gitignore b/.gitignore index 65b448d..153454d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ VVV /log /www /git +/src/coretech +/src/wp-themes +/config/.ssh/bitbucket-id_rsa +/config/.ssh/github-id_rsa diff --git a/Customfile b/Customfile index 45b107f..b97d84a 100644 --- a/Customfile +++ b/Customfile @@ -1,12 +1,10 @@ pmc_vvv=File.realdirpath( '..' ); -pmc_src=File.realdirpath( 'src', '..' ); -pmc_provision_dir=File.realdirpath( 'provision', '..' ); require File.join( pmc_vvv,'lib','functions.rb' ) # custom mapping for pmc specific improvement -config.vm.synced_folder File.join(pmc_vvv, 'wp-core'), '/srv/wp-core', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true -config.vm.synced_folder File.join(pmc_vvv, 'wp-themes'), '/srv/wp-themes', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true +config.vm.synced_folder File.join(pmc_vvv, 'config/.ssh'), '/srv/.ssh', owner: 'vagrant', group: 'root', mount_options: ['dmode=775', 'fmode=600'], automount: true, SharedFoldersEnableSymlinksCreate: true +config.vm.synced_folder File.join(pmc_vvv, 'src'), '/srv/src', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true config.vm.synced_folder pmc_vvv, '/srv/pmc-vvv', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true # we want to override some default from VVV to settings we know work properly from pmc-qs7 @@ -52,37 +50,55 @@ end # In order to add files to /etc folder, we need to access the privileged script to do the copy # First we need to add the source to a temporarly folder -config.vm.provision "file", - before: "pmc-src", - source: File.join(pmc_src, '.'), - destination: "/tmp/pmc-src/" +config.vm.provision "pmc-file", + run: 'always', + before: "pmc-etc", + type: "file", + source: File.join(pmc_vvv, 'config/etc/.'), + destination: "/tmp/pmc-etc/" # We then execute a shell script inside VM with admin privilege to copy the files -config.vm.provision "pmc-src", type: 'shell' do |s| - s.inline = "rsync -r /tmp/pmc-src/ / && rm -rf /tmp/pmc-src" - s.privileged = true +config.vm.provision "pmc-etc", + run: 'always', + after: "file", + type: "shell", + privileged: true, + inline: <<-SHELL + rsync -r /tmp/pmc-etc/ /etc/ + rm -rf /tmp/pmc-etc + cp /srv/.ssh/config /root/.ssh/config + cp /srv/.ssh/config /home/vagrant/.ssh/config + cp /srv/config/config.yml /vagrant/config.yml + chmod 600 /root/.ssh/config /home/vagrant/.ssh/config + chown root:root /root/.ssh/config + chown vagrant:vagrant /home/vagrant/.ssh/config + SHELL + +if File.exist?(File.join(pmc_vvv, 'provision/provision-coretech.sh')) + config.vm.provision "coretech", + after: "pmc-etc", + type: 'shell', + keep_color: true, + path: File.join(pmc_vvv, 'provision', 'provision-coretech.sh'), + env: { "VVV_LOG" => "coretech" } end # Implementing PMC specific provision for each site that can't be done by common provision template $vvv_config['sites'].each do |site, args| next if args['skip_provisioning'] - # @TODO: optionally change www folder to our pmc_vvv folder, maybe add a flag to turn on/off - # args['local_dir'] = File.join(pmc_vvv, 'www', site) - # $vvv_config['sites'][site]['local_dir'] = args['local_dir'] - # In order to properly develop and test provision script directly on local, # we need to override and map the custom-site-template folder - if Dir.exist?(File.join(pmc_vvv, 'git', 'custom-site-template')) + if Dir.exist?(File.join(pmc_vvv, 'git/custom-site-template')) # override and disable remote repo since we want use our local template $vvv_config['sites'][site]['repo'] = false # map the custom provision script directly into the folder so we can develop the scripts without copying between the folders - config.vm.synced_folder File.join(pmc_vvv, 'git', 'custom-site-template','provision'), '/srv/www/' + site + '/provision', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true + config.vm.synced_folder File.join(pmc_vvv, 'git/custom-site-template/provision'), '/srv/www/' + site + '/provision', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true end # VIP GO/Classic - if args['custom']['wp_vip'] && File.exist?(File.join(pmc_vvv, 'provision', 'provision-bind-mount.sh')) + if args['custom']['wp_vip'] && File.exist?(File.join(pmc_vvv, 'provision/provision-bind-mount.sh')) # We could let's vagrant auto map the shared folder, # however the VVV site provision script doesn't support remote git repo checkout into non-empty folder @@ -101,24 +117,6 @@ $vvv_config['sites'].each do |site, args| ], env: { "VVV_LOG" => "bind-mount-#{site}" } - # These code would be preferred if VVV site provision script support git repo checkout into non-empty folder - # These codes are commented out for knowledge sharing and potential future improvement - <<~END_COMMENT - - if args['custom']['wp_vip'].include? "go" - # Prepare local folders mapping: wp-content/plugins/pmc-plugins -> pmc-vvv/wp-themes/pmc-plugins, wp-content/themes -> pmc-vvv/wp-themes - Dir.mkdir( File.join( wp_content_dir, 'plugins' ) ) unless Dir.exist?( File.join( wp_content_dir, 'plugins' ) ) - Dir.mkdir( File.join( wp_content_dir, 'plugins', 'pmc-plugins' ) ) unless Dir.exist?( File.join( wp_content_dir, 'plugins', 'pmc-plugins' ) ) - config.vm.synced_folder File.join( pmc_vvv, 'wp-themes' ), '/srv/www/' + site + '/wp-content/themes', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true - config.vm.synced_folder File.join( pmc_vvv, 'wp-themes/pmc-plugins' ), '/srv/www/' + site + '/wp-content/plugins/pmc-plugins', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true - elseif args['custom']['wp_vip'].include? "classic" - # Prepare local folders mapping: wp-content/themes/vip -> pmc-vvv/wp-themes - Dir.mkdir( File.join( wp_content_dir, 'themes', 'vip' ) ) unless Dir.exist?( File.join( wp_content_dir, 'themes', 'vip' ) ) - config.vm.synced_folder File.join( pmc_vvv, 'wp-themes' ), '/srv/www/' + site + '/wp-content/themes/vip', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true - end - - END_COMMENT - end end diff --git a/Vagrantfile b/Vagrantfile index 4228936..2d47e7b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -17,11 +17,8 @@ require File.join( __dir__,'lib','functions.rb' ) # Auto install all required plugins install_required_plugins() -Dir.mkdir("./www") unless Dir.exist?("./www") -Dir.mkdir("./wp-themes") unless Dir.exist?("./wp-themes") -Dir.mkdir("./wp-themes/plugins") unless Dir.exist?("./wp-themes/plugins") -Dir.mkdir("./wp-themes/pmc-plugins") unless Dir.exist?("./wp-themes/pmc-plugins") -Dir.mkdir("./wp-themes/pmc-core-v2") unless Dir.exist?("./wp-themes/pmc-core-v2") +FileUtils.mkdir_p("./src/coretech/pmc-plugins") unless Dir.exist?("./src/coretech/pmc-plugins") +FileUtils.mkdir_p("./src/coretech/pmc-core-v2") unless Dir.exist?("./src/coretech/pmc-core-v2") # Copy our config.yml to vvv folder, currently there is no way for us to use a different config file from different location diff --git a/config-tests.yml b/config-tests.yml index 2f74d89..e7a890d 100644 --- a/config-tests.yml +++ b/config-tests.yml @@ -1,15 +1,12 @@ --- +pmc: + share: + php_version: 7.3 + wp_version: 5.4 + coretech_dir: /srv/src/coretech + wp_themes_dir: /srv/src/wp-themes + sites: - pmc: - skip_provisioning: false - repo: https://github.com/hauvong/custom-site-template.git - hosts: - - pmc.test - custom: -# share_code: true - wp_type: single - wp_tests: true - wp_version: 5.4 wpcom: skip_provisioning: false @@ -32,11 +29,13 @@ sites: - pmc-wwd-2016.wpcom.test - pmc-variety-2020.wpcom.test custom: -# share_code: true wp_type: single wp_vip: classic wp_tests: true wp_version: 5.4 + wp_themes: + vip/plugins: + repo: https://bitbucket.org/penskemediacorp/wordpress-vip-plugins.git vipgo: skip_provisioning: false @@ -49,11 +48,12 @@ sites: - sheknows.vipgo.test - soaps.vipgo.test custom: -# share_code: true wp_type: single wp_vip: vipgo wp_tests: true wp_version: 5.4 + wp_plugins: + repo: git@bitbucket.org:penskemediacorp/pmc-vip-go-plugins.git utilities: core: @@ -71,8 +71,8 @@ vm_config: memory: 4096 general: - db_backup: true - db_restore: true +# db_backup: true +# db_restore: true db_share_type: false vagrant-plugins: diff --git a/config/.ssh/config b/config/.ssh/config new file mode 100644 index 0000000..a47a7f6 --- /dev/null +++ b/config/.ssh/config @@ -0,0 +1,5 @@ +StrictHostKeyChecking no +UserKnownHostsFile=/dev/null +IdentityFile /srv/.ssh/pmc-readonly +IdentityFile /srv/.ssh/bitbucket-id_rsa +IdentityFile /srv/.ssh/github-id_rsa \ No newline at end of file diff --git a/config/.ssh/pmc-readonly b/config/.ssh/pmc-readonly new file mode 100644 index 0000000..667a183 --- /dev/null +++ b/config/.ssh/pmc-readonly @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAzUCFyIPDUEhjkvDH18MiDIvhDEjsEinsDXFBnNCJD8oo35LA +PcuiA5P75RqnSxz7uF/pyYf63vYArwTRP4jc30BPRGSEO7qjOyd4iOjlEzn5KLZG +Daex2Kp4lZ05afDRKcnRvsNtVZFWDZUvtjPpuZLHGAPuszmlAQFiRzeBaZa8TVaz +z8Wb3NCalj3sRRpdU/J/Su6PbhMRAbzkwAlPK0C3FMaGWaXEh8gQssAONL4yjXx5 +4bQurD+L28NsMBq++BRQam4BYx+b6eC6YpbXJIFFyBO5yfCsdRZjHxHvSD8u0ISW +Ywa1NHXOlaZY8mTeEqHgtvJuINyHIeweLfBpJwIDAQABAoIBAGseYHPMaHOOxADd +Dr8JRMzdd78sk5/LJznAwOhxYQbPj9NWyGO30b8iTVU9OtAVuT15OQ8Hm6MfKi4t +SnNpHzSYYIYmG2j8t9HYgKybN2p4WBOqRRc9TLDyDuquWldy6gZwILn5TidZKVr/ +YB4sK6/A7Y0YCEybKgVDTqIyUqTiqcUDczoaJjwfbfbavXgVdxQkyswj/cHNmbvI +6WBXc30suAhG+VaCORxcfO5aV0FmOUHtgJQa3boSAYkENvxTEUMe9wiLjfxO4jgi +dTCPuNn4f/b4p9MioVLi2EU8fMKCGo9F4VwBywh6bZDk8wzGyxMM6+36f0A9neTI +WF1ensECgYEA7iqhIEseMZEw206QdurAy89Ze9P3IIDSmokgajtnFZOT0KRu7MMi +IIOCU0/QswVciYIg64LDR7JMhjcqsb0Z32ePG1AY1WsVgh2gt85H8TsDyg4r2BS4 +WhBCrSrteUIdlBBpjdpymvOY4QjJoxdUmGvNAlQGiGjggbs9loCt+WECgYEA3J72 +JxNLhdJ6keXiZyXzJ1uJmG8E85R+yqJL3AMgdq2Yui6DlUQBg55Rin+/x1szcdnT +Vn4r4/93sRST0X2b3rt5NVDr//tyLAIPZPVZKf7TlJ/U9E8aPqrxT8leeaOcYiXq +wIvZJC7+VuNIzh+Myf9rtV7xoutj+bT8MqcIR4cCgYAJfgF1/Ah0CUldNEBlvO16 +MgVq/gO3c+rw5c447a0qGvulMSiKnyxZB2TGVUQIHoqVoG4XdNq7nMuX/dLhypuh +X8tAV2zl9KKi0PN63+nWH3gDMZVlw02lqUg/Bpr4Xj43jH/oe3Bd5J+POH5w1Zk1 +ifZdxWONREDOatwFh5NngQKBgQDazZipNlyvcwj2y7yXui6GOSWklW6euQZqpz1/ +DWbT7OVMuTbtAc5Sn+CU8I/eAphp8LPF00pqTAKEEDluChpdcycJ9qCodtNLzBtC +cIYmvUFP5JiKWC1aO6UqETdughJl0N8aaVhIp4a925poOyghaf2Dmo8hmjzD+Xgq +MDho3wKBgQCSfXarusNJSE8GA/NgDT/tztIBAOe1vtnDZ8G1GT1/t4924qqDcACU +iO1xfa//2meYKWaaoV2yIDO9QtyPFKLjySC8QhuLeBJv7+kAaortPsY+1jimqGQb +Er6kkxIFDthVsS9bb8odZP0SVc3H0vBmGndfQY8DRf+siFYMo7y/fw== +-----END RSA PRIVATE KEY----- diff --git a/config/.ssh/pmc-readonly.pub b/config/.ssh/pmc-readonly.pub new file mode 100644 index 0000000..f7253b6 --- /dev/null +++ b/config/.ssh/pmc-readonly.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNQIXIg8NQSGOS8MfXwyIMi+EMSOwSKewNcUGc0IkPyijfksA9y6IDk/vlGqdLHPu4X+nJh/re9gCvBNE/iNzfQE9EZIQ7uqM7J3iI6OUTOfkotkYNp7HYqniVnTlp8NEpydG+w21VkVYNlS+2M+m5kscYA+6zOaUBAWJHN4FplrxNVrPPxZvc0JqWPexFGl1T8n9K7o9uExEBvOTACU8rQLcUxoZZpcSHyBCywA40vjKNfHnhtC6sP4vbw2wwGr74FFBqbgFjH5vp4LpiltckgUXIE7nJ8Kx1FmMfEe9IPy7QhJZjBrU0dc6VpljyZN4SoeC28m4g3Ich7B4t8Gkn pmc-readonly@pmc-vvv diff --git a/src/etc/environment b/config/etc/environment similarity index 52% rename from src/etc/environment rename to config/etc/environment index 3a7b641..fea949e 100644 --- a/src/etc/environment +++ b/config/etc/environment @@ -1,5 +1,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/srv/config/homebin XDEBUG_REMOTE_HOST=10.0.2.2 -PMC_PHPUNIT_BOOTSTRAP=/srv/wp-core/wp-config/bootstrap-phpunit.php -WP_TESTS_DIR=/srv/wp-core/wp-tests/tests/phpunit/ +PMC_PHPUNIT_BOOTSTRAP=/srv/src/wp-core/wp-config/bootstrap-phpunit.php +WP_TESTS_DIR=/srv/src/wp-core/wp-tests/tests/phpunit/ WP_CONFIG_BOOTSTRAP=true diff --git a/log/README.md b/log/README.md deleted file mode 100644 index 2613f4a..0000000 --- a/log/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# VVV Log Files - -This directory will remain empty until log files are written to by services within the virtual machine. - -By default, PHP errors will be logged here in a `php_errors.log` file. \ No newline at end of file diff --git a/provision/provision-bind-mount.sh b/provision/provision-bind-mount.sh index 90911ce..e35a66b 100644 --- a/provision/provision-bind-mount.sh +++ b/provision/provision-bind-mount.sh @@ -1,35 +1,45 @@ #!/usr/bin/env bash +set -eo pipefail + # We need this script to bind mount various folder # avoid using symlink where wordpress may not work properly with symlink. # # VIP Go -# wp-content/plugins/pmc-plugins -> /srv/www/pmc/coretech/pmc-plugins -# wp-content/themes/pmc-core-v2 -> /srv/www/pmc/coretech/pmc-core-v2 +# wp-content/plugins/pmc-plugins -> coretech/pmc-plugins +# wp-content/themes/pmc-core-v2 -> coretech/pmc-core-v2 +# wp-content/themes/vip/pmc-core-v2 -> coretech/pmc-core-v2 # # VIP Classic -# wp-content/themes/vip/pmc-plugins -> /srv/www/pmc/coretech/pmc-plugins -# wp-content/themes/vip/pmc-core-v2 -> /srv/www/pmc/coretech/pmc-core-v2 +# wp-content/themes/vip/pmc-plugins -> coretech/pmc-plugins +# wp-content/themes/vip/pmc-core-v2 -> coretech/pmc-core-v2 # # If share code is enabled, the following structures are used # # VIP Go -# wp-content/plugins/pmc-plugins -> /srv/wp-themes/pmc-plugins -# wp-content/themes -> /srv/wp-themes -# wp-content/themes/vip -> /srv/wp-themes +# wp-content/plugins/pmc-plugins -> coretech/pmc-plugins +# wp-content/themes/pmc-core-v2 -> coretech/pmc-core-v2 +# wp-content/themes/vip/pmc-core-v2 -> coretech/pmc-core-v2 +# wp-content/themes -> pmc_shared/wp-themes # # VIP Classic -# wp-content/themes/vip -> /srv/wp-themes +# wp-content/themes/vip -> pmc_shared/wp-themes +# wp-content/themes/vip/pmc-plugins -> coretech/pmc-plugins +# wp-content/themes/vip/pmc-core-v2 -> coretech/pmc-core-v2 # # @TODO -# public_html/wordpress -> /srv/wp-core/wordpress-[version] -# public_html/wp-tests/phpunit/includes -> /srv/wp-core/wp-tests-[version]/phpunit/includes +# public_html/wordpress -> /srv/src/wp-core/wordpress-[version] +# public_html/wp-tests/phpunit/includes -> /srv/src/wp-core/wp-tests-[version]/phpunit/includes # +. "/srv/provision/provisioners.sh" + SITE=$1 +SITE_ESCAPED="${SITE//./\\.}" VM_DIR=$2 -WP_VIP=$3 -SHARE_CODE=$4 +WP_VIP=$(get_config_value "sites.${SITE_ESCAPED}.custom.wp_vip" false) +PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/www/pmc/coretech") +PMC_SHARE_WP_THEMES_DIR=$(get_config_value "pmc.share.wp_themes_dir" '') echo "Setup bind mount for site ${SITE}: ${WP_VIP}" @@ -41,34 +51,44 @@ WP_MU_PLUGINS_DIR="${WP_CONTENT_DIR}/mu-plugins" function bind_mount() { local SOURCE=$1 local TARGET=$2 + echo "bind mount: ${SOURCE} ${TARGET}" if [[ -n "$(mount | grep ${TARGET})" ]]; then umount ${TARGET} fi - mkdir -p ${SOURCE} ${TARGET} + noroot mkdir -p ${SOURCE} ${TARGET} mount --bind ${SOURCE} ${TARGET} } -if [[ "true" == "${SHARE_CODE}" ]]; then +function bind_mount_folders() { + local SOURCE=$1 + local TARGET=$2 + local FOLDER + for d in ${SOURCE}/*/; { + FOLDER=$(basename "${d%/}") + if [[ -n "${FOLDER}" && "*" != "${FOLDER}" && -d ${SOURCE}/${FOLDER} ]]; then + bind_mount "${SOURCE}/${FOLDER}" "${TARGET}/${FOLDER}" + fi + } +} - SOURCE_THEMES_DIR=/srv/wp-themes +# IMPORTANT: We need to bind the themes folder first, +# otherwise the pmc-core-v2 or pmc-plugins won't bind properly +if [[ -n "${PMC_SHARE_WP_THEMES_DIR}" ]]; then if [[ "${WP_VIP}" =~ go ]]; then - mount --bind ${SOURCE_THEMES_DIR}/pmc-plugins ${WP_PLUGINS_DIR}/pmc-plugins - mount --bind ${SOURCE_THEMES_DIR} ${WP_CONTENT_DIR}/themes - mount --bind ${SOURCE_THEMES_DIR} ${WP_CONTENT_DIR}/themes/vip + bind_mount_folders ${PMC_SHARE_WP_THEMES_DIR} ${WP_CONTENT_DIR}/themes elif [[ "${WP_VIP}" =~ classic ]]; then - mount --bind ${SOURCE_THEMES_DIR} ${WP_CONTENT_DIR}/themes/vip + bind_mount_folders ${PMC_SHARE_WP_THEMES_DIR} ${WP_CONTENT_DIR}/themes/vip fi +fi -else - - SOURCE_PMC_CORETECH=/srv/www/pmc/coretech - mount --bind ${SOURCE_PMC_CORETECH}/pmc-core-v2 ${WP_CONTENT_DIR}/themes/pmc-core-v2 - - if [[ "${WP_VIP}" =~ go ]]; then - mount --bind ${SOURCE_PMC_CORETECH}/pmc-plugins ${WP_PLUGINS_DIR}/pmc-plugins - elif [[ "${WP_VIP}" =~ classic ]]; then - mount --bind ${SOURCE_PMC_CORETECH}/pmc-plugins ${WP_CONTENT_DIR}/themes/vip/pmc-plugins - fi +bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-core-v2 ${WP_CONTENT_DIR}/themes/vip/pmc-core-v2 +if [[ "${WP_VIP}" =~ go ]]; then + bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-plugins ${WP_PLUGINS_DIR}/pmc-plugins + bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-core-v2 ${WP_CONTENT_DIR}/themes/pmc-core-v2 +elif [[ "${WP_VIP}" =~ classic ]]; then + bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-plugins ${WP_CONTENT_DIR}/themes/vip/pmc-plugins fi + +provisioner_success \ No newline at end of file diff --git a/provision/provision-coretech.sh b/provision/provision-coretech.sh new file mode 100644 index 0000000..9a1052f --- /dev/null +++ b/provision/provision-coretech.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +set -eo pipefail + +. "/srv/provision/provisioners.sh" + +PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/www/pmc/coretech") +PMC_SHARE_PHP_VERSION=$(get_config_value "pmc.share.php_version" "7.3") + +function git_checkout { + local TARGET=${1} + local SOURCE=${2} + + if [[ -z "${TARGET}" ]]; then + exit 1 + fi + if [[ -z "${SOURCE}" ]]; then + exit 1 + fi + + if [ ! -d ${TARGET} ] + then + noroot mkdir -p ${TARGET} + fi + + echo "Git checkout: ${SOURCE} ${TARGET}" + + local OLD_PATH="$(pwd)" + cd ${TARGET} + + if [ ! -d ${TARGET}/.git ]; then + noroot git clone ${SOURCE} . + else + noroot git pull + fi + + cd ${OLD_PATH} + +} + +update-alternatives --set php /usr/bin/php${PMC_SHARE_PHP_VERSION} +update-alternatives --set phar /usr/bin/phar${PMC_SHARE_PHP_VERSION} +update-alternatives --set phar.phar /usr/bin/phar.phar${PMC_SHARE_PHP_VERSION} +update-alternatives --set phpize /usr/bin/phpize${PMC_SHARE_PHP_VERSION} +update-alternatives --set php-config /usr/bin/php-config${PMC_SHARE_PHP_VERSION} + +git_checkout ${PMC_SHARE_CORETECH_DIR}/pmc-plugins git@bitbucket.org:penskemediacorp/pmc-plugins.git +git_checkout ${PMC_SHARE_CORETECH_DIR}/pmc-core-v2 git@bitbucket.org:penskemediacorp/pmc-core-v2.git + +git_checkout ${PMC_SHARE_CORETECH_DIR}/pmc-codesniffer git@bitbucket.org:penskemediacorp/pmc-codesniffer.git +cd ${PMC_SHARE_CORETECH_DIR}/pmc-codesniffer +noroot composer install --no-autoloader +noroot composer depends squizlabs/php_codesniffer + +ln -sf ${PMC_SHARE_CORETECH_DIR}/pmc-codesniffer/vendor/squizlabs/php_codesniffer/bin/phpcbf /usr/local/bin/ +ln -sf ${PMC_SHARE_CORETECH_DIR}/pmc-codesniffer/vendor/squizlabs/php_codesniffer/bin/phpcs /usr/local/bin/ +chmod +x /usr/local/bin/* +noroot phpcs --config-set default_standard PmcWpVip + +if [[ -z "$(grep "self::getConfigData('show_sources')" vendor/squizlabs/php_codesniffer/src/Config.php)" ]]; then + sed "/self::getConfigData('show_progress')/i\$showSources=self::getConfigData('show_sources');if(\$showSources!==null){\$this->showSources=(bool)\$showSources;}" -i vendor/squizlabs/php_codesniffer/src/Config.php + echo "Patched phpcs" +fi +phpcs --config-set show_sources 1 + +provisioner_success \ No newline at end of file diff --git a/wp-core/wp-config/bootstrap-phpunit.php b/src/wp-core/wp-config/bootstrap-phpunit.php similarity index 100% rename from wp-core/wp-config/bootstrap-phpunit.php rename to src/wp-core/wp-config/bootstrap-phpunit.php diff --git a/wp-core/wp-config/bootstrap.php b/src/wp-core/wp-config/bootstrap.php similarity index 100% rename from wp-core/wp-config/bootstrap.php rename to src/wp-core/wp-config/bootstrap.php diff --git a/wp-core/wp-config/functions.php b/src/wp-core/wp-config/functions.php similarity index 100% rename from wp-core/wp-config/functions.php rename to src/wp-core/wp-config/functions.php From e959991f23673814f7bf110c002c14b7555a9529 Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Tue, 19 May 2020 08:25:15 -0700 Subject: [PATCH 07/15] Add provision pmc shared codes --- .gitignore | 2 + Customfile | 103 +++++++++++--------- config-tests.yml | 2 + config/etc/environment | 2 +- provision/provision-pmc-share.sh | 59 +++++++++++ src/wp-core/wp-config/bootstrap-phpunit.php | 49 ++++++---- 6 files changed, 150 insertions(+), 67 deletions(-) create mode 100644 provision/provision-pmc-share.sh diff --git a/.gitignore b/.gitignore index 153454d..3e6a76e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,7 @@ VVV /git /src/coretech /src/wp-themes +/src/wp-core/wordpress +/src/wp-core/wp-tests /config/.ssh/bitbucket-id_rsa /config/.ssh/github-id_rsa diff --git a/Customfile b/Customfile index b97d84a..3e2d7bf 100644 --- a/Customfile +++ b/Customfile @@ -19,13 +19,13 @@ config.vm.provider :virtualbox do |v| # Allow the VM to utilize up to 3/4 of the host system memory v.memory = detect_max_mem 4096, 0.75 - # Only allow the VM to use up-to 50% of the host system cpu - # Windows OS, the server may hang if cpu allow to reach 100% + # Only allow the VM to use up-to 50% of the host system cpu + # Windows OS, the server may hang if cpu allow to reach 100% v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"] - # Instruct Vagrant to utilize all the cpu cores we've provided above - # Without this, only 1 core will be used - v.customize ["modifyvm", :id, "--ioapic", "on"] + # Instruct Vagrant to utilize all the cpu cores we've provided above + # Without this, only 1 core will be used + v.customize ["modifyvm", :id, "--ioapic", "on"] # Plug in the virtual network adapter as if it were a real cat-5 cable # plugged into a real network card. This corrects an error presented with @@ -51,71 +51,80 @@ end # In order to add files to /etc folder, we need to access the privileged script to do the copy # First we need to add the source to a temporarly folder config.vm.provision "pmc-file", - run: 'always', - before: "pmc-etc", - type: "file", - source: File.join(pmc_vvv, 'config/etc/.'), - destination: "/tmp/pmc-etc/" + run: 'always', + before: "pmc-script", + type: "file", + source: File.join(pmc_vvv, 'config/etc/.'), + destination: "/tmp/etc/" # We then execute a shell script inside VM with admin privilege to copy the files -config.vm.provision "pmc-etc", - run: 'always', - after: "file", - type: "shell", - privileged: true, - inline: <<-SHELL - rsync -r /tmp/pmc-etc/ /etc/ - rm -rf /tmp/pmc-etc - cp /srv/.ssh/config /root/.ssh/config - cp /srv/.ssh/config /home/vagrant/.ssh/config - cp /srv/config/config.yml /vagrant/config.yml - chmod 600 /root/.ssh/config /home/vagrant/.ssh/config - chown root:root /root/.ssh/config - chown vagrant:vagrant /home/vagrant/.ssh/config - SHELL +config.vm.provision "pmc-script", + run: 'always', + after: "pmc-file", + type: "shell", + privileged: true, + inline: <<-SHELL + rsync -r /tmp/etc/ /etc/ + rm -rf /tmp/pmc-etc + cp /srv/.ssh/config /root/.ssh/config + cp /srv/.ssh/config /home/vagrant/.ssh/config + cp /srv/config/config.yml /vagrant/config.yml + chmod 600 /root/.ssh/config /home/vagrant/.ssh/config + chown root:root /root/.ssh/config + chown vagrant:vagrant /home/vagrant/.ssh/config + SHELL if File.exist?(File.join(pmc_vvv, 'provision/provision-coretech.sh')) - config.vm.provision "coretech", - after: "pmc-etc", - type: 'shell', - keep_color: true, - path: File.join(pmc_vvv, 'provision', 'provision-coretech.sh'), - env: { "VVV_LOG" => "coretech" } + config.vm.provision "coretech", + after: "pmc-script", + type: 'shell', + keep_color: true, + path: File.join(pmc_vvv, 'provision', 'provision-coretech.sh'), + env: { "VVV_LOG" => "coretech" } +end + +if File.exist?(File.join(pmc_vvv, 'provision/provision-pmc-share.sh')) && $vvv_config['pmc'] && $vvv_config['pmc']['share'] && ! $vvv_config['pmc']['share']['skip_provisioning'] + config.vm.provision "pmc-share", + after: "pmc-script", + type: 'shell', + keep_color: true, + path: File.join(pmc_vvv, 'provision', 'provision-pmc-share.sh'), + env: { "VVV_LOG" => "wp-core" } end # Implementing PMC specific provision for each site that can't be done by common provision template $vvv_config['sites'].each do |site, args| - next if args['skip_provisioning'] + next if args['skip_provisioning'] # In order to properly develop and test provision script directly on local, # we need to override and map the custom-site-template folder if Dir.exist?(File.join(pmc_vvv, 'git/custom-site-template')) # override and disable remote repo since we want use our local template - $vvv_config['sites'][site]['repo'] = false + $vvv_config['sites'][site]['repo'] = false # map the custom provision script directly into the folder so we can develop the scripts without copying between the folders config.vm.synced_folder File.join(pmc_vvv, 'git/custom-site-template/provision'), '/srv/www/' + site + '/provision', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'], automount: true, SharedFoldersEnableSymlinksCreate: true end # VIP GO/Classic - if args['custom']['wp_vip'] && File.exist?(File.join(pmc_vvv, 'provision/provision-bind-mount.sh')) + if args['custom'] && args['custom']['wp_vip'] && File.exist?(File.join(pmc_vvv, 'provision/provision-bind-mount.sh')) # We could let's vagrant auto map the shared folder, # however the VVV site provision script doesn't support remote git repo checkout into non-empty folder - config.vm.provision "bind-mount-#{site}", - after: "site-#{site}", - run: 'always', - type: 'shell', - keep_color: true, - path: File.join(pmc_vvv, 'provision', 'provision-bind-mount.sh'), - args: [ - site, - args['vm_dir'], - args['custom']['wp_vip'], - args['custom']['share_code'].to_s - ], - env: { "VVV_LOG" => "bind-mount-#{site}" } + config.vm.provision "bind-mount-#{site}", + after: "site-#{site}", + run: 'always', + type: 'shell', + keep_color: true, + path: File.join(pmc_vvv, 'provision', 'provision-bind-mount.sh'), + args: [ + site, + args['vm_dir'], + args['custom']['wp_vip'], + args['custom']['share_code'].to_s + ], + env: { "VVV_LOG" => "bind-mount-#{site}" } end diff --git a/config-tests.yml b/config-tests.yml index e7a890d..2d5d44d 100644 --- a/config-tests.yml +++ b/config-tests.yml @@ -1,9 +1,11 @@ --- pmc: share: + skip_provisioning: true php_version: 7.3 wp_version: 5.4 coretech_dir: /srv/src/coretech + wp_core_dir: /srv/src/wp-core wp_themes_dir: /srv/src/wp-themes sites: diff --git a/config/etc/environment b/config/etc/environment index fea949e..fe097c5 100644 --- a/config/etc/environment +++ b/config/etc/environment @@ -1,5 +1,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/srv/config/homebin XDEBUG_REMOTE_HOST=10.0.2.2 PMC_PHPUNIT_BOOTSTRAP=/srv/src/wp-core/wp-config/bootstrap-phpunit.php -WP_TESTS_DIR=/srv/src/wp-core/wp-tests/tests/phpunit/ +WP_TESTS_DIR=/srv/src/wp-core/wp-tests/phpunit/ WP_CONFIG_BOOTSTRAP=true diff --git a/provision/provision-pmc-share.sh b/provision/provision-pmc-share.sh new file mode 100644 index 0000000..c6e0c39 --- /dev/null +++ b/provision/provision-pmc-share.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +set -eo pipefail + +. "/srv/provision/provisioners.sh" + +SKIP_PROVISION=$(get_config_value "pmc.share.skip_provisioning") +if [[ -n "${SKIP_PROVISION}" && "true" == "${SKIP_PROVISION}" ]]; then + exit +fi + +PMC_SHARE_WP_CORE_DIR=$(get_config_value "pmc.share.wp_core_dir" "/srv/src/wp-core") +PMC_SHARE_WP_VERSION=$(get_config_value "pmc.share.wp_version" "5.4") + +WP_CORE_DIR="${PMC_SHARE_WP_CORE_DIR}/wordpress" +WP_CONTENT_DIR="${WP_CORE_DIR}/wp-content" +WP_PLUGINS_DIR="${WP_CONTENT_DIR}/plugins" +WP_MU_PLUGINS_DIR="${WP_CONTENT_DIR}/mu-plugins" +WP_TESTS_DIR="${PMC_SHARE_WP_CORE_DIR}/wp-tests" +WP_TESTS_CONFIG="${WP_TESTS_DIR}/phpunit/wp-tests-config.php" +WP_TESTS_DB_NAME="wp_tests" + +if [[ "latest" == "${PMC_SHARE_WP_VERSION}" ]]; then + WP_VERSION=$( curl -s http://api.wordpress.org/core/version-check/1.7/ | awk 'match($0, /"version":"([^"]+)"/, v) { print v[1]}' ) +else + WP_VERSION="${PMC_SHARE_WP_VERSION}" +fi + +if [[ ! -d ${WP_CORE_DIR} ]]; then + echo " * Installing Wordpress ${WP_VERSION} ${WP_CORE_DIR}" + curl -sL https://wordpress.org/wordpress-${WP_VERSION}.tar.gz | noroot tar -zx --directory ${PMC_SHARE_WP_CORE_DIR} + if [[ "${PMC_SHARE_WP_CORE_DIR}/wordpress" != "${WP_CORE_DIR}" ]]; then + noroot mv ${PMC_SHARE_WP_CORE_DIR}/wordpress ${WP_CORE_DIR} + fi + echo " * Wordpress installed" +fi + +if [[ ! -d ${WP_TESTS_DIR}/phpunit/includes ]]; then + echo " * Installing Wordpress Tests ${WP_VERSION} ${WP_TESTS_DIR}" + noroot svn co --quiet https://develop.svn.wordpress.org/tags/${WP_VERSION}/tests/phpunit/includes ${WP_TESTS_DIR}/phpunit/includes + noroot svn --force export https://develop.svn.wordpress.org/tags/${WP_VERSION}/wp-tests-config-sample.php ${WP_TESTS_CONFIG} + + sed \ + -e "s|dirname( __FILE__ ) . '/src/'|'${WP_CORE_DIR}/'|" \ + -e "s/youremptytestdbnamehere/${WP_TESTS_DB_NAME}/" \ + -e "s/yourpasswordhere/wp/" \ + -e "s/yourusernamehere/wp/" \ + -i ${WP_TESTS_CONFIG} + + echo -e " * Creating database '${WP_TESTS_DB_NAME}' (if it's not already there)" + mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS \`${WP_TESTS_DB_NAME}\`" + echo -e " * Granting the wp user priviledges to the '${WP_TESTS_DB_NAME}' database" + mysql -u root --password=root -e "GRANT ALL PRIVILEGES ON \`${WP_TESTS_DB_NAME}\`.* TO wp@localhost IDENTIFIED BY 'wp';" + echo -e " * DB operations done." + + echo " * Wordpress Tests installed." +fi + +provisioner_success \ No newline at end of file diff --git a/src/wp-core/wp-config/bootstrap-phpunit.php b/src/wp-core/wp-config/bootstrap-phpunit.php index 9fcc68b..9ceb9ea 100644 --- a/src/wp-core/wp-config/bootstrap-phpunit.php +++ b/src/wp-core/wp-config/bootstrap-phpunit.php @@ -20,6 +20,16 @@ protected function __construct() { ifndef( 'WP_BATCACHE', false ); + preg_match( '@/www/([^/]+)/@', getcwd(), $matches ); + switch( $matches[1] ) { + case 'vipgo': + ifndef( 'IS_VIP_GO', true ); + break; + case 'wpcom': + ifndef( 'IS_VIP_GO', false ); + break; + } + if ( preg_match( '#^.*/pmc-plugins/#', getcwd(), $matches ) ) { ifndef( 'IS_VIP_GO', false ); ifndef( 'SITE_NAME', 'pmc-plugins' ); @@ -52,29 +62,30 @@ protected function __construct() { if ( empty( $phpunit_dir ) || ! file_exists( $phpunit_dir ) ) { - $phpunit_dir = getenv( 'WP_TESTS_DIR' ); - if ( empty( $phpunit_dir ) || !file_exists( $phpunit_dir ) ) { - $phpunit_dir = false; - if ( preg_match( '#(.*)/[^/]+/wp-content/#', $theme_folder, $matches ) ) { - if ( file_exists( $matches[1] . '/wp-tests/phpunit' ) ) { - $phpunit_dir = $matches[1] . '/wp-tests/phpunit'; - } + $phpunit_dir = false; + if ( preg_match( '#(.*)/[^/]+/wp-content/#', $theme_folder, $matches ) ) { + if ( file_exists( $matches[1] . '/wp-tests/phpunit' ) ) { + $phpunit_dir = $matches[1] . '/wp-tests/phpunit'; } - $check_dir = $theme_folder; - $check_level = 10; - while ( $check_level > 0 && !$phpunit_dir && !empty( $check_dir ) && ! in_array( $check_dir, [ '.', '/' ], true ) ) { - $check_level -= 1; - $check_dir = dirname( $check_dir ); - if ( in_array( $check_dir, [ '.', '/' ], true ) ) { - break; - } - if ( file_exists( $check_dir . '/wp-tests/phpunit' ) ) { - $phpunit_dir = $check_dir . '/wp-tests/phpunit'; - } + } + $check_dir = $theme_folder; + $check_level = 10; + while ( $check_level > 0 && !$phpunit_dir && !empty( $check_dir ) && ! in_array( $check_dir, [ '.', '/' ], true ) ) { + $check_level -= 1; + $check_dir = dirname( $check_dir ); + if ( in_array( $check_dir, [ '.', '/' ], true ) ) { + break; + } + if ( file_exists( $check_dir . '/wp-tests/phpunit' ) ) { + $phpunit_dir = $check_dir . '/wp-tests/phpunit'; } - } + + } + + if ( empty( $phpunit_dir ) || ! file_exists( $phpunit_dir ) ) { + $phpunit_dir = getenv( 'WP_TESTS_DIR' ); } if ( empty( $phpunit_dir ) || ! file_exists( $phpunit_dir ) ) { From e2bd7cbd489489ce329383fa3bd55233a133e980 Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Tue, 26 May 2020 08:36:11 -0700 Subject: [PATCH 08/15] remove key from repo --- .gitignore | 3 +-- config/.ssh/pmc-readonly | 27 --------------------------- config/.ssh/pmc-readonly.pub | 1 - 3 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 config/.ssh/pmc-readonly delete mode 100644 config/.ssh/pmc-readonly.pub diff --git a/.gitignore b/.gitignore index 3e6a76e..59ba901 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,4 @@ VVV /src/wp-themes /src/wp-core/wordpress /src/wp-core/wp-tests -/config/.ssh/bitbucket-id_rsa -/config/.ssh/github-id_rsa +/config/.ssh \ No newline at end of file diff --git a/config/.ssh/pmc-readonly b/config/.ssh/pmc-readonly deleted file mode 100644 index 667a183..0000000 --- a/config/.ssh/pmc-readonly +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAzUCFyIPDUEhjkvDH18MiDIvhDEjsEinsDXFBnNCJD8oo35LA -PcuiA5P75RqnSxz7uF/pyYf63vYArwTRP4jc30BPRGSEO7qjOyd4iOjlEzn5KLZG -Daex2Kp4lZ05afDRKcnRvsNtVZFWDZUvtjPpuZLHGAPuszmlAQFiRzeBaZa8TVaz -z8Wb3NCalj3sRRpdU/J/Su6PbhMRAbzkwAlPK0C3FMaGWaXEh8gQssAONL4yjXx5 -4bQurD+L28NsMBq++BRQam4BYx+b6eC6YpbXJIFFyBO5yfCsdRZjHxHvSD8u0ISW -Ywa1NHXOlaZY8mTeEqHgtvJuINyHIeweLfBpJwIDAQABAoIBAGseYHPMaHOOxADd -Dr8JRMzdd78sk5/LJznAwOhxYQbPj9NWyGO30b8iTVU9OtAVuT15OQ8Hm6MfKi4t -SnNpHzSYYIYmG2j8t9HYgKybN2p4WBOqRRc9TLDyDuquWldy6gZwILn5TidZKVr/ -YB4sK6/A7Y0YCEybKgVDTqIyUqTiqcUDczoaJjwfbfbavXgVdxQkyswj/cHNmbvI -6WBXc30suAhG+VaCORxcfO5aV0FmOUHtgJQa3boSAYkENvxTEUMe9wiLjfxO4jgi -dTCPuNn4f/b4p9MioVLi2EU8fMKCGo9F4VwBywh6bZDk8wzGyxMM6+36f0A9neTI -WF1ensECgYEA7iqhIEseMZEw206QdurAy89Ze9P3IIDSmokgajtnFZOT0KRu7MMi -IIOCU0/QswVciYIg64LDR7JMhjcqsb0Z32ePG1AY1WsVgh2gt85H8TsDyg4r2BS4 -WhBCrSrteUIdlBBpjdpymvOY4QjJoxdUmGvNAlQGiGjggbs9loCt+WECgYEA3J72 -JxNLhdJ6keXiZyXzJ1uJmG8E85R+yqJL3AMgdq2Yui6DlUQBg55Rin+/x1szcdnT -Vn4r4/93sRST0X2b3rt5NVDr//tyLAIPZPVZKf7TlJ/U9E8aPqrxT8leeaOcYiXq -wIvZJC7+VuNIzh+Myf9rtV7xoutj+bT8MqcIR4cCgYAJfgF1/Ah0CUldNEBlvO16 -MgVq/gO3c+rw5c447a0qGvulMSiKnyxZB2TGVUQIHoqVoG4XdNq7nMuX/dLhypuh -X8tAV2zl9KKi0PN63+nWH3gDMZVlw02lqUg/Bpr4Xj43jH/oe3Bd5J+POH5w1Zk1 -ifZdxWONREDOatwFh5NngQKBgQDazZipNlyvcwj2y7yXui6GOSWklW6euQZqpz1/ -DWbT7OVMuTbtAc5Sn+CU8I/eAphp8LPF00pqTAKEEDluChpdcycJ9qCodtNLzBtC -cIYmvUFP5JiKWC1aO6UqETdughJl0N8aaVhIp4a925poOyghaf2Dmo8hmjzD+Xgq -MDho3wKBgQCSfXarusNJSE8GA/NgDT/tztIBAOe1vtnDZ8G1GT1/t4924qqDcACU -iO1xfa//2meYKWaaoV2yIDO9QtyPFKLjySC8QhuLeBJv7+kAaortPsY+1jimqGQb -Er6kkxIFDthVsS9bb8odZP0SVc3H0vBmGndfQY8DRf+siFYMo7y/fw== ------END RSA PRIVATE KEY----- diff --git a/config/.ssh/pmc-readonly.pub b/config/.ssh/pmc-readonly.pub deleted file mode 100644 index f7253b6..0000000 --- a/config/.ssh/pmc-readonly.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNQIXIg8NQSGOS8MfXwyIMi+EMSOwSKewNcUGc0IkPyijfksA9y6IDk/vlGqdLHPu4X+nJh/re9gCvBNE/iNzfQE9EZIQ7uqM7J3iI6OUTOfkotkYNp7HYqniVnTlp8NEpydG+w21VkVYNlS+2M+m5kscYA+6zOaUBAWJHN4FplrxNVrPPxZvc0JqWPexFGl1T8n9K7o9uExEBvOTACU8rQLcUxoZZpcSHyBCywA40vjKNfHnhtC6sP4vbw2wwGr74FFBqbgFjH5vp4LpiltckgUXIE7nJ8Kx1FmMfEe9IPy7QhJZjBrU0dc6VpljyZN4SoeC28m4g3Ich7B4t8Gkn pmc-readonly@pmc-vvv From 1494917e657a6c9b64887ede25aa14d49d6b1b8a Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Wed, 30 Sep 2020 12:46:32 -0700 Subject: [PATCH 09/15] Fix pmc-script provision --- Customfile | 2 ++ config/.ssh/config | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Customfile b/Customfile index 3e2d7bf..794ee05 100644 --- a/Customfile +++ b/Customfile @@ -65,6 +65,8 @@ config.vm.provision "pmc-script", inline: <<-SHELL rsync -r /tmp/etc/ /etc/ rm -rf /tmp/pmc-etc + mkdir -p /vagrant + mkdir -p /vagrant/failed_provisioners cp /srv/.ssh/config /root/.ssh/config cp /srv/.ssh/config /home/vagrant/.ssh/config cp /srv/config/config.yml /vagrant/config.yml diff --git a/config/.ssh/config b/config/.ssh/config index a47a7f6..2d9a990 100644 --- a/config/.ssh/config +++ b/config/.ssh/config @@ -1,5 +1,4 @@ StrictHostKeyChecking no UserKnownHostsFile=/dev/null -IdentityFile /srv/.ssh/pmc-readonly IdentityFile /srv/.ssh/bitbucket-id_rsa IdentityFile /srv/.ssh/github-id_rsa \ No newline at end of file From e9520b805d264de0d17b40e97d3e0436ae954e89 Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Wed, 30 Sep 2020 13:28:27 -0700 Subject: [PATCH 10/15] Add provision script dependencies --- Customfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Customfile b/Customfile index 794ee05..dd09377 100644 --- a/Customfile +++ b/Customfile @@ -53,6 +53,7 @@ end config.vm.provision "pmc-file", run: 'always', before: "pmc-script", + after: :all type: "file", source: File.join(pmc_vvv, 'config/etc/.'), destination: "/tmp/etc/" From d5cd737de18a60b93979542be3ea47a260e97135 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Thu, 1 Oct 2020 02:10:20 +0530 Subject: [PATCH 11/15] fixed typo, added missing comma --- Customfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Customfile b/Customfile index dd09377..e891ee5 100644 --- a/Customfile +++ b/Customfile @@ -53,7 +53,7 @@ end config.vm.provision "pmc-file", run: 'always', before: "pmc-script", - after: :all + after: :all, type: "file", source: File.join(pmc_vvv, 'config/etc/.'), destination: "/tmp/etc/" From 2098fe41188675229dd4adc5e412b45d2607db45 Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Fri, 2 Oct 2020 12:32:00 -0700 Subject: [PATCH 12/15] Fix provision script dependencies --- Customfile | 20 ------- Vagrantfile | 1 + config.yml | 10 ++++ lib/functions.rb | 3 + provision/provision-bind-mount.sh | 52 ++++++++-------- provision/provision-coretech.sh | 16 +++-- provision/provision-pmc-share.sh | 15 ++--- provision/provision-post.sh | 7 +++ provision/provision-tests.sh | 99 +++++++++++++++++++++++++++++++ 9 files changed, 164 insertions(+), 59 deletions(-) create mode 100644 provision/provision-post.sh create mode 100644 provision/provision-tests.sh diff --git a/Customfile b/Customfile index dd09377..67fb2e5 100644 --- a/Customfile +++ b/Customfile @@ -52,8 +52,6 @@ end # First we need to add the source to a temporarly folder config.vm.provision "pmc-file", run: 'always', - before: "pmc-script", - after: :all type: "file", source: File.join(pmc_vvv, 'config/etc/.'), destination: "/tmp/etc/" @@ -76,24 +74,6 @@ config.vm.provision "pmc-script", chown vagrant:vagrant /home/vagrant/.ssh/config SHELL -if File.exist?(File.join(pmc_vvv, 'provision/provision-coretech.sh')) - config.vm.provision "coretech", - after: "pmc-script", - type: 'shell', - keep_color: true, - path: File.join(pmc_vvv, 'provision', 'provision-coretech.sh'), - env: { "VVV_LOG" => "coretech" } -end - -if File.exist?(File.join(pmc_vvv, 'provision/provision-pmc-share.sh')) && $vvv_config['pmc'] && $vvv_config['pmc']['share'] && ! $vvv_config['pmc']['share']['skip_provisioning'] - config.vm.provision "pmc-share", - after: "pmc-script", - type: 'shell', - keep_color: true, - path: File.join(pmc_vvv, 'provision', 'provision-pmc-share.sh'), - env: { "VVV_LOG" => "wp-core" } -end - # Implementing PMC specific provision for each site that can't be done by common provision template $vvv_config['sites'].each do |site, args| next if args['skip_provisioning'] diff --git a/Vagrantfile b/Vagrantfile index 2d47e7b..9a37f20 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -19,6 +19,7 @@ install_required_plugins() FileUtils.mkdir_p("./src/coretech/pmc-plugins") unless Dir.exist?("./src/coretech/pmc-plugins") FileUtils.mkdir_p("./src/coretech/pmc-core-v2") unless Dir.exist?("./src/coretech/pmc-core-v2") +FileUtils.cp( File.join( 'provision', 'provision-post.sh' ), File.join( 'vvv', 'provision', 'provision-post.sh' ) ); # Copy our config.yml to vvv folder, currently there is no way for us to use a different config file from different location diff --git a/config.yml b/config.yml index ce0490f..7d070d0 100644 --- a/config.yml +++ b/config.yml @@ -1,4 +1,13 @@ --- +pmc: + share: + skip_provisioning: true + php_version: 7.3 + wp_version: 5.4 + coretech_dir: /srv/src/coretech + wp_core_dir: /srv/src/wp-core + wp_themes_dir: /srv/src/wp-themes + sites: wpcom: skip_provisioning: false @@ -372,6 +381,7 @@ utilities: - mongodb - opcache-status - php74 + - php73 - phpmyadmin - tideways - tls-ca diff --git a/lib/functions.rb b/lib/functions.rb index d07af5a..6578dec 100644 --- a/lib/functions.rb +++ b/lib/functions.rb @@ -1,5 +1,7 @@ $logger = Vagrant::UI::Colored.new +#require File.join( __dir__,'functions-git.rb' ) + def install_required_plugins() # vagrant-persistent-storage @@ -72,3 +74,4 @@ def detect_max_mem( default = 1024, multiplier = 1 ) return (mem * multiplier).round end + diff --git a/provision/provision-bind-mount.sh b/provision/provision-bind-mount.sh index e35a66b..895341f 100644 --- a/provision/provision-bind-mount.sh +++ b/provision/provision-bind-mount.sh @@ -38,7 +38,7 @@ SITE=$1 SITE_ESCAPED="${SITE//./\\.}" VM_DIR=$2 WP_VIP=$(get_config_value "sites.${SITE_ESCAPED}.custom.wp_vip" false) -PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/www/pmc/coretech") +PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/src/coretech") PMC_SHARE_WP_THEMES_DIR=$(get_config_value "pmc.share.wp_themes_dir" '') echo "Setup bind mount for site ${SITE}: ${WP_VIP}" @@ -49,46 +49,46 @@ WP_PLUGINS_DIR="${WP_CONTENT_DIR}/plugins" WP_MU_PLUGINS_DIR="${WP_CONTENT_DIR}/mu-plugins" function bind_mount() { - local SOURCE=$1 - local TARGET=$2 - echo "bind mount: ${SOURCE} ${TARGET}" - if [[ -n "$(mount | grep ${TARGET})" ]]; then - umount ${TARGET} - fi - noroot mkdir -p ${SOURCE} ${TARGET} - mount --bind ${SOURCE} ${TARGET} + local SOURCE=$1 + local TARGET=$2 + echo "bind mount: ${SOURCE} ${TARGET}" + if [[ -n "$(mount | grep ${TARGET})" ]]; then + umount ${TARGET} + fi + noroot mkdir -p ${SOURCE} ${TARGET} + mount --bind ${SOURCE} ${TARGET} } function bind_mount_folders() { - local SOURCE=$1 - local TARGET=$2 - local FOLDER - for d in ${SOURCE}/*/; { - FOLDER=$(basename "${d%/}") - if [[ -n "${FOLDER}" && "*" != "${FOLDER}" && -d ${SOURCE}/${FOLDER} ]]; then - bind_mount "${SOURCE}/${FOLDER}" "${TARGET}/${FOLDER}" - fi - } + local SOURCE=$1 + local TARGET=$2 + local FOLDER + for d in ${SOURCE}/*/; { + FOLDER=$(basename "${d%/}") + if [[ -n "${FOLDER}" && "*" != "${FOLDER}" && -d ${SOURCE}/${FOLDER} ]]; then + bind_mount "${SOURCE}/${FOLDER}" "${TARGET}/${FOLDER}" + fi + } } # IMPORTANT: We need to bind the themes folder first, # otherwise the pmc-core-v2 or pmc-plugins won't bind properly if [[ -n "${PMC_SHARE_WP_THEMES_DIR}" ]]; then - if [[ "${WP_VIP}" =~ go ]]; then - bind_mount_folders ${PMC_SHARE_WP_THEMES_DIR} ${WP_CONTENT_DIR}/themes - elif [[ "${WP_VIP}" =~ classic ]]; then - bind_mount_folders ${PMC_SHARE_WP_THEMES_DIR} ${WP_CONTENT_DIR}/themes/vip - fi + if [[ "${WP_VIP}" =~ go ]]; then + bind_mount_folders ${PMC_SHARE_WP_THEMES_DIR} ${WP_CONTENT_DIR}/themes + elif [[ "${WP_VIP}" =~ classic ]]; then + bind_mount_folders ${PMC_SHARE_WP_THEMES_DIR} ${WP_CONTENT_DIR}/themes/vip + fi fi bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-core-v2 ${WP_CONTENT_DIR}/themes/vip/pmc-core-v2 if [[ "${WP_VIP}" =~ go ]]; then - bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-plugins ${WP_PLUGINS_DIR}/pmc-plugins - bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-core-v2 ${WP_CONTENT_DIR}/themes/pmc-core-v2 + bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-plugins ${WP_PLUGINS_DIR}/pmc-plugins + bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-core-v2 ${WP_CONTENT_DIR}/themes/pmc-core-v2 elif [[ "${WP_VIP}" =~ classic ]]; then - bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-plugins ${WP_CONTENT_DIR}/themes/vip/pmc-plugins + bind_mount ${PMC_SHARE_CORETECH_DIR}/pmc-plugins ${WP_CONTENT_DIR}/themes/vip/pmc-plugins fi provisioner_success \ No newline at end of file diff --git a/provision/provision-coretech.sh b/provision/provision-coretech.sh index 9a1052f..da29b6c 100644 --- a/provision/provision-coretech.sh +++ b/provision/provision-coretech.sh @@ -4,7 +4,9 @@ set -eo pipefail . "/srv/provision/provisioners.sh" -PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/www/pmc/coretech") +provisioner_begin "coretech" + +PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/src/coretech") PMC_SHARE_PHP_VERSION=$(get_config_value "pmc.share.php_version" "7.3") function git_checkout { @@ -38,11 +40,13 @@ function git_checkout { } -update-alternatives --set php /usr/bin/php${PMC_SHARE_PHP_VERSION} -update-alternatives --set phar /usr/bin/phar${PMC_SHARE_PHP_VERSION} -update-alternatives --set phar.phar /usr/bin/phar.phar${PMC_SHARE_PHP_VERSION} -update-alternatives --set phpize /usr/bin/phpize${PMC_SHARE_PHP_VERSION} -update-alternatives --set php-config /usr/bin/php-config${PMC_SHARE_PHP_VERSION} +if [ -f /usr/bin/php${PMC_SHARE_PHP_VERSION} ]; then + update-alternatives --set php /usr/bin/php${PMC_SHARE_PHP_VERSION} + update-alternatives --set phar /usr/bin/phar${PMC_SHARE_PHP_VERSION} + update-alternatives --set phar.phar /usr/bin/phar.phar${PMC_SHARE_PHP_VERSION} + update-alternatives --set phpize /usr/bin/phpize${PMC_SHARE_PHP_VERSION} + update-alternatives --set php-config /usr/bin/php-config${PMC_SHARE_PHP_VERSION} +fi git_checkout ${PMC_SHARE_CORETECH_DIR}/pmc-plugins git@bitbucket.org:penskemediacorp/pmc-plugins.git git_checkout ${PMC_SHARE_CORETECH_DIR}/pmc-core-v2 git@bitbucket.org:penskemediacorp/pmc-core-v2.git diff --git a/provision/provision-pmc-share.sh b/provision/provision-pmc-share.sh index c6e0c39..568020c 100644 --- a/provision/provision-pmc-share.sh +++ b/provision/provision-pmc-share.sh @@ -3,10 +3,11 @@ set -eo pipefail . "/srv/provision/provisioners.sh" +provisioner_begin "pmc-share" SKIP_PROVISION=$(get_config_value "pmc.share.skip_provisioning") if [[ -n "${SKIP_PROVISION}" && "true" == "${SKIP_PROVISION}" ]]; then - exit + exit fi PMC_SHARE_WP_CORE_DIR=$(get_config_value "pmc.share.wp_core_dir" "/srv/src/wp-core") @@ -27,12 +28,12 @@ else fi if [[ ! -d ${WP_CORE_DIR} ]]; then - echo " * Installing Wordpress ${WP_VERSION} ${WP_CORE_DIR}" - curl -sL https://wordpress.org/wordpress-${WP_VERSION}.tar.gz | noroot tar -zx --directory ${PMC_SHARE_WP_CORE_DIR} - if [[ "${PMC_SHARE_WP_CORE_DIR}/wordpress" != "${WP_CORE_DIR}" ]]; then - noroot mv ${PMC_SHARE_WP_CORE_DIR}/wordpress ${WP_CORE_DIR} - fi - echo " * Wordpress installed" + echo " * Installing Wordpress ${WP_VERSION} ${WP_CORE_DIR}" + curl -sL https://wordpress.org/wordpress-${WP_VERSION}.tar.gz | noroot tar -zx --directory ${PMC_SHARE_WP_CORE_DIR} + if [[ "${PMC_SHARE_WP_CORE_DIR}/wordpress" != "${WP_CORE_DIR}" ]]; then + noroot mv ${PMC_SHARE_WP_CORE_DIR}/wordpress ${WP_CORE_DIR} + fi + echo " * Wordpress installed" fi if [[ ! -d ${WP_TESTS_DIR}/phpunit/includes ]]; then diff --git a/provision/provision-post.sh b/provision/provision-post.sh new file mode 100644 index 0000000..916468f --- /dev/null +++ b/provision/provision-post.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +. /srv/pmc-vvv/provision/provision-coretech.sh +. /srv/pmc-vvv/provision/provision-pmc-share.sh + +VVV_PROVISIONER_RUNNING=post +provisioner_success diff --git a/provision/provision-tests.sh b/provision/provision-tests.sh new file mode 100644 index 0000000..7463cd9 --- /dev/null +++ b/provision/provision-tests.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +set -eo pipefail + +. "/srv/provision/provisioners.sh" +function get_config_value() { + local value=$(shyaml get-value "sites.${SITE_ESCAPED}.custom.${1}" 2> /dev/null < ${VVV_CONFIG}) + echo "${value:-$2}" +} +function get_primary_host() { + local value=$(shyaml get-value "sites.${SITE_ESCAPED}.hosts.0" 2> /dev/null < ${VVV_CONFIG}) + echo "${value:-$1}" +} + +SITE=$1 +SITE_ESCAPED="${SITE//./\\.}" +VM_DIR=$2 +VVV_PATH_TO_SITE=${VM_DIR} # used in site templates +VVV_SITE_NAME=${SITE} + +echo " * Test Suite provisioner ${VVV_SITE_NAME}" + +DOMAIN=$(get_primary_host "${VVV_SITE_NAME}".test) +SITE_TITLE=$(get_config_value 'site_title' "${DOMAIN}") +WP_VERSION=$(get_config_value 'wp_version' 'latest') +DB_NAME=$(get_config_value 'db_name' "${VVV_SITE_NAME}") +DB_NAME="${DB_NAME//[\\\/\.\<\>\:\"\'\|\?\!\*]/}" + +WP_CORE_DIR="${VVV_PATH_TO_SITE}/public_html" + +install_test_suite() { + + WP_TESTS=$(get_config_value 'wp_tests.provision' false | awk '{print tolower($0)}') + if [ "${WP_TESTS}" != "true" ]; then + WP_TESTS=$(get_config_value 'wp_tests' false | awk '{print tolower($0)}') + if [ "${WP_TESTS}" != "true" ]; then + return 0 + fi + fi + WP_TESTS_VERSION=${WP_VERSION} + WP_TESTS_DATA=$(get_config_value 'wp_tests.data' false | awk '{print tolower($0)}') + WP_TESTS_DB_NAME=$(get_config_value 'wp_tests.db_name' "${DB_NAME}_tests") + WP_TESTS_DIR=$(get_config_value 'wp_tests.dir' "${VVV_PATH_TO_SITE}/wp-tests") + WP_TESTS_CONFIG="${WP_TESTS_DIR}/wp-tests-config.php" + + if [[ "nightly" == "${VERSION}" || "trunk" == "${WP_TESTS_VERSION}" ]]; then + WP_TESTS_TAG="trunk" + elif [[ "latest" == "${WP_TESTS_VERSION}" ]]; then + WP_TESTS_VERSION=$( curl -s http://api.wordpress.org/core/version-check/1.7/ | awk 'match($0, /"version":"([^"]+)"/, v) { print v[1]}' ) + if [[ -n "${WP_TESTS_VERSION}" ]]; then + WP_TESTS_TAG="tags/${WP_TESTS_VERSION}" + fi + else + WP_TESTS_TAG="tags/${WP_TESTS_VERSION}" + fi + + if [[ -n "${WP_TESTS_TAG}" ]]; then + + if [[ ! -d ${WP_TESTS_DIR}/phpunit/includes ]]; then + echo " * Installing Wordpress Tests ${WP_TESTS_VERSION} ${WP_TESTS_DIR}" + noroot svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes ${WP_TESTS_DIR}/phpunit/includes + if [[ "true" == "${WP_TESTS_DATA}" ]]; then + noroot svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ ${WP_TESTS_DIR}/phpunit/data + fi + else + echo " * Updating Wordpress Tests ${WP_TESTS_VERSION} ${WP_TESTS_DIR}" + noroot svn up ${WP_TESTS_DIR}/phpunit/includes + if [[ "true" == "${WP_TESTS_DATA}" ]]; then + noroot svn up ${WP_TESTS_DIR}/phpunit/data + fi + fi + + noroot svn --force export https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php ${WP_TESTS_DIR}/wp-tests-config.php + + sed \ + -e "s|dirname( __FILE__ ) . '/src/'|'${WP_DIR}/'|" \ + -e "s|Test\ Blog|${SITE_TITLE}|" \ + -e "s|admins@example\.org|${ADMIN_EMAIL}|" \ + -e "s|example\.org|${DOMAIN}|" \ + -e "s/youremptytestdbnamehere/${WP_TESTS_DB_NAME}/" \ + -e "s/yourpasswordhere/wp/" \ + -e "s/yourusernamehere/wp/" \ + -i ${WP_TESTS_CONFIG} + + echo -e " * Creating database '${WP_TESTS_DB_NAME}' (if it's not already there)" + mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS \`${WP_TESTS_DB_NAME}\`" + echo -e " * Granting the wp user privileges to the '${WP_TESTS_DB_NAME}' database" + mysql -u root --password=root -e "GRANT ALL PRIVILEGES ON \`${WP_TESTS_DB_NAME}\`.* TO wp@localhost IDENTIFIED BY 'wp';" + echo -e " * DB operations done." + + fi + +} + +install_test_suite + +echo " * Test Suite provisioner script completed for ${VVV_SITE_NAME}" + +provisioner_success \ No newline at end of file From 44643859abffc4e1ec5cafe489f52875685d5afc Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Fri, 2 Oct 2020 12:53:05 -0700 Subject: [PATCH 13/15] . --- provision/provision-coretech.sh | 2 +- src/wp-core/wp-config/bootstrap-phpunit.php | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/provision/provision-coretech.sh b/provision/provision-coretech.sh index da29b6c..53b2346 100644 --- a/provision/provision-coretech.sh +++ b/provision/provision-coretech.sh @@ -6,7 +6,7 @@ set -eo pipefail provisioner_begin "coretech" -PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/src/coretech") +PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/www/pmc/coretech") PMC_SHARE_PHP_VERSION=$(get_config_value "pmc.share.php_version" "7.3") function git_checkout { diff --git a/src/wp-core/wp-config/bootstrap-phpunit.php b/src/wp-core/wp-config/bootstrap-phpunit.php index 9ceb9ea..c41e708 100644 --- a/src/wp-core/wp-config/bootstrap-phpunit.php +++ b/src/wp-core/wp-config/bootstrap-phpunit.php @@ -20,14 +20,15 @@ protected function __construct() { ifndef( 'WP_BATCACHE', false ); - preg_match( '@/www/([^/]+)/@', getcwd(), $matches ); - switch( $matches[1] ) { - case 'vipgo': - ifndef( 'IS_VIP_GO', true ); - break; - case 'wpcom': - ifndef( 'IS_VIP_GO', false ); - break; + if ( preg_match( '@/www/([^/]+)/@', getcwd(), $matches ) ) { + switch( $matches[1] ) { + case 'vipgo': + ifndef( 'IS_VIP_GO', true ); + break; + case 'wpcom': + ifndef( 'IS_VIP_GO', false ); + break; + } } if ( preg_match( '#^.*/pmc-plugins/#', getcwd(), $matches ) ) { From 5ae75cb9d4c283d22a4858f177101e275de89470 Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Fri, 2 Oct 2020 13:06:18 -0700 Subject: [PATCH 14/15] . --- provision/provision-bind-mount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provision/provision-bind-mount.sh b/provision/provision-bind-mount.sh index 895341f..6ebee62 100644 --- a/provision/provision-bind-mount.sh +++ b/provision/provision-bind-mount.sh @@ -38,7 +38,7 @@ SITE=$1 SITE_ESCAPED="${SITE//./\\.}" VM_DIR=$2 WP_VIP=$(get_config_value "sites.${SITE_ESCAPED}.custom.wp_vip" false) -PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/src/coretech") +PMC_SHARE_CORETECH_DIR=$(get_config_value "pmc.share.coretech_dir" "/srv/www/pmc/coretech") PMC_SHARE_WP_THEMES_DIR=$(get_config_value "pmc.share.wp_themes_dir" '') echo "Setup bind mount for site ${SITE}: ${WP_VIP}" From f104677661d096f4dd278e7f8add4d04c3a49482 Mon Sep 17 00:00:00 2001 From: Hau Vong Date: Tue, 10 Nov 2020 10:17:38 -0800 Subject: [PATCH 15/15] Fix provision conflict --- Customfile | 19 +++++++++++++++++++ config-tests.yml | 2 +- config/.ssh/config | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Customfile b/Customfile index 67fb2e5..ba07b78 100644 --- a/Customfile +++ b/Customfile @@ -95,6 +95,23 @@ $vvv_config['sites'].each do |site, args| # We could let's vagrant auto map the shared folder, # however the VVV site provision script doesn't support remote git repo checkout into non-empty folder + # provision after dependencies doesn't work :( + # let's work some magic to bypass vvv's site provision + $vvv_config['sites'][site]['skip_provisioning'] = true + config.vm.provision "site-#{site}", + type: 'shell', + keep_color: true, + path: File.join('provision', 'provision-site.sh'), + args: [ + site, + args['repo'].to_s, + args['branch'], + args['vm_dir'], + args['skip_provisioning'].to_s, + args['nginx_upstream'] + ], + env: { "VVV_LOG" => "site-#{site}" } + config.vm.provision "bind-mount-#{site}", after: "site-#{site}", run: 'always', @@ -112,3 +129,5 @@ $vvv_config['sites'].each do |site, args| end end + + diff --git a/config-tests.yml b/config-tests.yml index 2d5d44d..404e07d 100644 --- a/config-tests.yml +++ b/config-tests.yml @@ -11,7 +11,7 @@ pmc: sites: wpcom: - skip_provisioning: false + skip_provisioning: true repo: https://github.com/hauvong/custom-site-template.git hosts: - wpcom.test diff --git a/config/.ssh/config b/config/.ssh/config index 2d9a990..0ad8b66 100644 --- a/config/.ssh/config +++ b/config/.ssh/config @@ -1,4 +1,4 @@ StrictHostKeyChecking no UserKnownHostsFile=/dev/null IdentityFile /srv/.ssh/bitbucket-id_rsa -IdentityFile /srv/.ssh/github-id_rsa \ No newline at end of file +IdentityFile /srv/.ssh/github-id_rsa