Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #5 from eugene-manuilov/release/2.0-beta3
Browse files Browse the repository at this point in the history
Release 2.0-beta3
  • Loading branch information
eugene-manuilov authored Dec 6, 2016
2 parents 5848b9c + 811edc1 commit d76be8b
Show file tree
Hide file tree
Showing 21 changed files with 216 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Phalcon VM (2.0-beta2)
# Phalcon VM (2.0-beta3)

Phalcon VM is an open source [Vagrant](https://www.vagrantup.com/) configuration which contains wide range of tools required in modern web development. Like a Swiss Army Knife, Phalcon VM allows you to easily activate and use tools required for you project.

Expand Down
32 changes: 16 additions & 16 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ end
require 'json'

class ::Hash
def deep_merge(second)
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
self.merge(second, &merger)
end
def deep_merge(second)
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
self.merge(second, &merger)
end
end

vagrant_dir = File.expand_path(File.dirname(__FILE__))
Expand All @@ -38,19 +38,19 @@ Vagrant.configure(2) do |config|
config.ssh.forward_agent = true

config.vm.network "private_network", ip: "192.168.50.99"
# if settings['varnish']['enabled'] === true
# config.vm.network "forwarded_port", guest: settings['varnish']['port'], host: settings['varnish']['port']
# end
if settings['mysql']['enabled'] === true
if settings['varnish']['enabled'] === true
config.vm.network "forwarded_port", guest: settings['varnish']['port'], host: settings['varnish']['port']
end
if settings['mysql']['enabled'] === true and settings['mysql']['forward_port'] === true
config.vm.network "forwarded_port", guest: settings['mysql']['port'], host: settings['mysql']['port']
end
if settings['redis']['enabled'] === true
if settings['redis']['enabled'] === true and settings['redis']['forward_port'] === true
config.vm.network "forwarded_port", guest: settings['redis']['port'], host: settings['redis']['port']
end
if settings['memcached']['enabled'] === true
if settings['memcached']['enabled'] === true and settings['memcached']['forward_port'] === true
config.vm.network "forwarded_port", guest: settings['memcached']['port'], host: settings['memcached']['port']
end
if settings['elasticsearch']['enabled'] === true
if settings['elasticsearch']['enabled'] === true and settings['elasticsearch']['forward_port'] === true
config.vm.network "forwarded_port", guest: settings['elasticsearch']['port'], host: settings['elasticsearch']['port']
end

Expand All @@ -71,11 +71,11 @@ Vagrant.configure(2) do |config|
config.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ]

config.vm.synced_folders.each do |id, options|
# Make sure we use Samba for file mounts on Windows
if ! options[:type] && Vagrant::Util::Platform.windows?
options[:type] = "smb"
end
end
# Make sure we use Samba for file mounts on Windows
if ! options[:type] && Vagrant::Util::Platform.windows?
options[:type] = "smb"
end
end

if defined?(VagrantPlugins::HostsUpdater)
hosts = settings['sites'].map do |site|
Expand Down
6 changes: 0 additions & 6 deletions provision/puppet/modules.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,3 @@
'redis' => '1.2.3',
}
}

phalconvm::utils::puppet_modules { 'maxchk':
modules => {
'varnish' => '1.0.0',
}
}
7 changes: 4 additions & 3 deletions provision/puppet/modules/phalconvm/manifests/elasticsearch.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class phalconvm::elasticsearch(
$enabled = false,
$port = '9200',
# $xpack = false,
$enabled = false,
$port = '9200',
$forward_port = false,
# $xpack = false,
) {
if $enabled == true {
class { 'elasticsearch':
Expand Down
2 changes: 1 addition & 1 deletion provision/puppet/modules/phalconvm/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

# services
class { 'phalconvm::nginx': * => $settings[nginx] }
# class { 'phalconvm::varnish': * => $settings[varnish] }
class { 'phalconvm::varnish': * => $settings[varnish] }
class { 'phalconvm::mysql': * => $settings[mysql] }
class { 'phalconvm::mysql::phpmyadmin': * => $settings[phpMyAdmin] }
class { 'phalconvm::postgres': * => $settings[postgres] }
Expand Down
7 changes: 4 additions & 3 deletions provision/puppet/modules/phalconvm/manifests/memcached.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class phalconvm::memcached(
$enabled = false,
$max_memory = 64,
$port = 11211
$enabled = false,
$max_memory = 64,
$port = 11211,
$forward_port = false,
) {
if $enabled == true {
class { 'memcached':
Expand Down
1 change: 1 addition & 0 deletions provision/puppet/modules/phalconvm/manifests/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$enabled = false,
$password = 'root',
$port = '3306',
$forward_port = false,
$general_log = false,
$slow_query_log = true,
$log_queries_not_using_indexes = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
require => Archive['/tmp/phpmyadmin.tar.gz']
}

$fqdn_rand = fqdn_rand( 9999 )
$blowfish_secret = pw_hash( "${fqdn_rand}", 'SHA-512', 'JXXdi4G0Nl9xlh0emuoHZNSuPvZ0qcfGx1hF4cUfOkf3jS' )

file { '/srv/www/default/public/phpmyadmin/config.inc.php':
ensure => 'present',
content => template( 'phalconvm/phpmyadmin/config.inc.php.erb' ),
Expand Down
2 changes: 1 addition & 1 deletion provision/puppet/modules/phalconvm/manifests/php.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$track_errors = false,
$html_errors = true,
$xdebug_idekey = 'PVMDBG',
$xdebug_remote_port = '9000',
$xdebug_remote_port = '9000',
$xdebug_var_display_max_children = '-1',
$xdebug_var_display_max_data = '-1',
$xdebug_var_display_max_depth = '-1',
Expand Down
1 change: 1 addition & 0 deletions provision/puppet/modules/phalconvm/manifests/redis.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class phalconvm::redis(
$enabled = false,
$port = 6379,
$forward_port = false,
$maxmemory = 64,
$save_db_to_disk = true,
$slowlog_log_slower_than = 100,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
define phalconvm::utils::puppet_modules( $modules ) {
$modules.each |$module, $version| {
$command = $version ? {
false => "puppet module install ${name}-${module}",
default => "puppet module install ${name}-${module} --version ${version}",
}

exec { "${name}-${module}":
command => "/opt/puppetlabs/bin/puppet module install ${name}-${module} --version ${version}",
command => $command,
creates => "/etc/puppetlabs/code/environments/production/modules/${module}/",
path => '/opt/puppetlabs/bin',
}
}
}
53 changes: 44 additions & 9 deletions provision/puppet/modules/phalconvm/manifests/varnish.pp
Original file line number Diff line number Diff line change
@@ -1,28 +1,63 @@
class phalconvm::varnish (
$enabled = false,
$port = '8080',
$storage_size = '64M',
$port = '6081',
$storage_size = '64m',
$ttl = '120',
) {
if $enabled == true {
class { 'varnish':
# varnish_listen_address => '0.0.0.0',
varnish_listen_port => $port,
varnish_storage_size => $storage_size,
add_repo => false,
package { 'varnish':
ensure => 'installed',
}

service { 'varnish':
ensure => 'running',
require => Package['varnish'],
}

$varnish_service = {
'Service' => {
'ExecStart' => "/usr/sbin/varnishd -j unix,user=vcache -F -a :${port} -T localhost:6082 -f /etc/varnish/default.vcl -t ${ttl} -S /etc/varnish/secret -s malloc,${storage_size}",
},
}

create_ini_settings( $varnish_service, {
path => '/lib/systemd/system/varnish.service',
require => Package['varnish'],
notify => Exec['varnish-daemon-reload'],
} )

file { '/etc/varnish/default.vcl':
ensure => 'present',
content => template( 'phalconvm/varnish/default.vcl.erb' ),
require => Package['varnish'],
notify => Service['varnish'],
}

exec { 'varnish-daemon-reload':
command => '/bin/systemctl daemon-reload',
refreshonly => true,
notify => Service['varnish'],
}
} else {
service { 'varnish':
ensure => 'stopped',
}

exec { 'varnish-unmount':
command => 'umount /var/lib/varnish',
path => '/bin:/usr/bin',
unless => "test -n `mount | grep varnish`",
}

package { 'varnish':
ensure => 'purged',
require => Service['varnish'],
require => [ Service['varnish'], Exec['varnish-unmount'] ],
}

exec { 'varnish-remove':
command => '/usr/bin/apt-get autoremove --purge -y',
command => 'apt-get autoremove --purge -y',
refreshonly => true,
path => '/bin:/usr/bin',
subscribe => Package['varnish'],
}
}
Expand Down
8 changes: 4 additions & 4 deletions provision/puppet/modules/phalconvm/manifests/website.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
www_root => "/srv/www/${site[directory]}/htdocs/public",
index_files => ['index.php'],
try_files => ['$uri', '$uri/', '/index.php?$args'],
access_log => "/srv/log/nginx/${site[directory]}.access.log",
error_log => "/srv/log/nginx/${site[directory]}.error.log",
access_log => "/srv/log/nginx/${site[directory]}.access.log",
error_log => "/srv/log/nginx/${site[directory]}.error.log",
locations => {
"${site[label]}-php-loc" => {
ensure => present,
Expand All @@ -34,14 +34,14 @@
exec { "${site[label]} Installation":
command => "phalcon project ${site[directory]} --directory=/tmp && mv /tmp/${site[directory]}/* /srv/www/${site[directory]}/htdocs",
creates => "/srv/www/${site[directory]}/htdocs/public/index.php",
path => '/bin:/usr/bin',
path => '/bin:/usr/bin',
}
} else {
vcsrepo { "/srv/www/${site[directory]}/htdocs":
ensure => 'present',
provider => $site[provider],
source => $site[repository],
require => [Phalconvm::Utils::Known_host['github.com'], Phalconvm::Utils::Known_host['bitbucket.org']],
require => [Phalconvm::Utils::Known_host['github.com'], Phalconvm::Utils::Known_host['bitbucket.org']],
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @see: https://docs.phpmyadmin.net/en/latest/config.html
*/

$cfg['blowfish_secret'] = 'JXXdi-/4G) {#0Nl9xl&h0-em(uoH,ZN$}SuPvZ0q*. c%?fGx1hF4cUfOkf=3jS';
$cfg['blowfish_secret'] = '<%= @blowfish_secret %>';

$i = 1;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.

# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "80";
}

sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.

# unset cookies for images, stylesheets and javascript files to be able to cache it
if (req.url ~ "\.(css|js|png|gif|jp(e)?g)") {
unset req.http.cookie;
}

# bypass audio and video files and not cache it
if (req.url ~ "\.(mp4|mp3|avi)") {
return (pass);
}

return (hash);
}

sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
}

sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}
1 change: 1 addition & 0 deletions provision/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ restart() {
}

restart nginx
restart varnish
restart php7.0-fpm
restart mysql
restart postgresql
Expand Down
17 changes: 16 additions & 1 deletion www/default/app/config/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ php:
varnish:
Varnish Server:
key: varnish
disabled: true
fields:
enabled:
type: switch
description: Defines whether Varnish should be activated on provision or disabled.
port:
type: text
description: The port to listen on for TCP connections.
ttl:
type: text
label: TTL
description: The time in seconds after which cache will be expired.
storage_size:
type: text
description: The malloc storage size for cache data.
Expand All @@ -129,6 +132,9 @@ mysql:
port:
type: text
description: The port to listen on for TCP connections.
forward_port:
type: checkbox
description: Defines whether Vagrant should forward MySQL port or not.
Logs:
key: mysql
fields:
Expand Down Expand Up @@ -213,6 +219,9 @@ redis:
port:
type: text
description: The port to listen on for TCP connections.
forward_port:
type: checkbox
description: Defines whether Vagrant should forward Redis port or not.
maxmemory:
label: Max Memory
type: text
Expand Down Expand Up @@ -240,6 +249,9 @@ memcached:
type: input
label: TCP port
description: The port to listen on for TCP connections.
forward_port:
type: checkbox
description: Defines whether Vagrant should forward Memcached port or not.
phpMemcacheAdmin:
key: phpMemcacheAdmin
fields:
Expand Down Expand Up @@ -273,6 +285,9 @@ elasticsearch:
port:
type: text
description: The port to listen on for TCP connections.
forward_port:
type: checkbox
description: Defines whether Vagrant should forward Elasticsearch port or not.
# Plugins:
# key: elasticsearch
# fields:
Expand Down
Loading

0 comments on commit d76be8b

Please sign in to comment.