Gergő Tisza has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377683 )

Change subject: Create puppet resource for service domain alias pattern
......................................................................

Create puppet resource for service domain alias pattern

Change-Id: I079c22e3922f4047622dc496d7e5740877faf60d
---
A puppet/modules/apache/manifests/port_alias.pp
R puppet/modules/apache/templates/port_alias.erb
M puppet/modules/electron/manifests/init.pp
D puppet/modules/electron/templates/apache-site.erb
M puppet/modules/ores/manifests/init.pp
M puppet/modules/sentry/manifests/init.pp
D puppet/modules/sentry/templates/apache-site.erb
M puppet/modules/wikilabels/manifests/init.pp
D puppet/modules/wikilabels/templates/apache-site-wikilabels.erb
9 files changed, 55 insertions(+), 62 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/83/377683/1

diff --git a/puppet/modules/apache/manifests/port_alias.pp 
b/puppet/modules/apache/manifests/port_alias.pp
new file mode 100644
index 0000000..6a0d3f1
--- /dev/null
+++ b/puppet/modules/apache/manifests/port_alias.pp
@@ -0,0 +1,46 @@
+# == Define: apache::port_alias
+#
+# Creates a domain alias for an internal port. Using domain aliases
+# avoids conflicts when multiple vagrant boxes with the same service role
+# are running. So e.g. if the service listens on port 1234, instead of
+# using localhost:1234 or dev.wiki.local.wmftest.net:1234 on the host
+# machine (would result in a port redirection conflict) or using
+# <guest ip>:1234 (inconvenient) one can just use
+# <alias>.local.wmftest.net:<standard vagrant port>, with different boxes
+# using different ports.
+#
+# === Parameters
+#
+# [*alias*]
+#   Domain name prefix. E.g. 'restbase' will result in the service being
+#   reachable at restbase.local.wmftest.net:<port> (where <port> is
+#   whatever was set via `vagrant config http_port`). Defaults to the
+#   resource name.
+#
+# [*port*]
+#   Internal port used by the service. All requests sent to the domain
+#   alias will be redirected here,
+#
+# === Examples
+#
+#  apache::port_alias { 'restbase':
+#    port => 8888,
+#  }
+#
+define apache::port_alias(
+    $domain_prefix = $title,
+    $port,
+) {
+    include ::mwv
+    $base_domain = $::mwv::tld
+
+    apache::site { $domain_prefix:
+        ensure  => present,
+        content => template('apache/port_alias.erb'),
+        require => [
+          Class['::apache::mod::proxy'],
+          Class['::apache::mod::proxy_http'],
+          Class['::apache::mod::headers'],
+        ],
+    }
+}
diff --git a/puppet/modules/ores/templates/apache-site-ores.erb 
b/puppet/modules/apache/templates/port_alias.erb
similarity index 86%
rename from puppet/modules/ores/templates/apache-site-ores.erb
rename to puppet/modules/apache/templates/port_alias.erb
index ba10199..76eb54a 100644
--- a/puppet/modules/ores/templates/apache-site-ores.erb
+++ b/puppet/modules/apache/templates/port_alias.erb
@@ -2,7 +2,7 @@
 ### THIS FILE IS MANAGED BY PUPPET
 #####################################################################
 
-ServerName <%= @vhost_name %>
+ServerName <%= @domain_prefix %><%= @base_domain %>
 
 ProxyPass / http://localhost:<%= @port %>/
 ProxyPassReverse / http://localhost:<%= @port %>/
diff --git a/puppet/modules/electron/manifests/init.pp 
b/puppet/modules/electron/manifests/init.pp
index 4fbc6c9..4cf3749 100644
--- a/puppet/modules/electron/manifests/init.pp
+++ b/puppet/modules/electron/manifests/init.pp
@@ -75,13 +75,7 @@
         ],
     }
 
-    # set up nice URL
-    apache::site { 'electron':
-        ensure  => present,
-        content => template('electron/apache-site.erb'),
-        require => [
-          Class['::apache::mod::proxy'],
-          Class['::apache::mod::proxy_http'],
-        ],
+    apache::port_alias { 'electron':
+        port => $port,
     }
 }
diff --git a/puppet/modules/electron/templates/apache-site.erb 
b/puppet/modules/electron/templates/apache-site.erb
deleted file mode 100644
index 599bd4b..0000000
--- a/puppet/modules/electron/templates/apache-site.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-#####################################################################
-### THIS FILE IS MANAGED BY PUPPET
-#####################################################################
-
-ServerName <%= @vhost_name %>
-
-ProxyPass / http://localhost:<%= @port %>/
-ProxyPassReverse / http://localhost:<%= @port %>/
-ProxyPreserveHost On
diff --git a/puppet/modules/ores/manifests/init.pp 
b/puppet/modules/ores/manifests/init.pp
index 08f247e..a4b3e7f 100644
--- a/puppet/modules/ores/manifests/init.pp
+++ b/puppet/modules/ores/manifests/init.pp
@@ -49,14 +49,8 @@
     }
     $repo_dir = "${deploy_dir}/src/ores"
 
-    apache::site { 'ores':
-        ensure  => present,
-        content => template('ores/apache-site-ores.erb'),
-        require => [
-          Class['::apache::mod::proxy'],
-          Class['::apache::mod::proxy_http'],
-          Class['::apache::mod::headers'],
-        ],
+    apache::port_alias { 'ores':
+        port => $port,
     }
 
     $cfg_file = "${repo_dir}/config/999-vagrant.yaml"
diff --git a/puppet/modules/sentry/manifests/init.pp 
b/puppet/modules/sentry/manifests/init.pp
index 283f1f4..3907698 100644
--- a/puppet/modules/sentry/manifests/init.pp
+++ b/puppet/modules/sentry/manifests/init.pp
@@ -102,14 +102,8 @@
         require  => Mysql::Db[$db_name],
     }
 
-    apache::site { 'sentry':
-        ensure  => present,
-        content => template('sentry/apache-site.erb'),
-        require => [
-          Class['::apache::mod::proxy'],
-          Class['::apache::mod::proxy_http'],
-          Class['::apache::mod::headers'],
-        ],
+    apache::port_alias { 'sentry':
+        port => 9002,
     }
 
     file { $cfg_file:
diff --git a/puppet/modules/sentry/templates/apache-site.erb 
b/puppet/modules/sentry/templates/apache-site.erb
deleted file mode 100644
index ea9fef2..0000000
--- a/puppet/modules/sentry/templates/apache-site.erb
+++ /dev/null
@@ -1,10 +0,0 @@
-#####################################################################
-### THIS FILE IS MANAGED BY PUPPET
-#####################################################################
-
-ServerName <%= @vhost_name %>
-
-ProxyPass / http://localhost:9002/
-ProxyPassReverse / http://localhost:9002/
-ProxyPreserveHost On
-RequestHeader set X-Forwarded-Proto "https" env=HTTPS
diff --git a/puppet/modules/wikilabels/manifests/init.pp 
b/puppet/modules/wikilabels/manifests/init.pp
index e5642f3..2861f1e 100644
--- a/puppet/modules/wikilabels/manifests/init.pp
+++ b/puppet/modules/wikilabels/manifests/init.pp
@@ -82,14 +82,8 @@
         ],
     }
 
-    apache::site { 'wikilabels':
-        ensure  => present,
-        content => template('wikilabels/apache-site-wikilabels.erb'),
-        require => [
-          Class['::apache::mod::proxy'],
-          Class['::apache::mod::proxy_http'],
-          Class['::apache::mod::headers'],
-        ],
+    apache::port_alias { 'wikilabels':
+        port => $port,
     }
 
     $cfg_file = "${repo_dir}/config/999-vagrant.yaml"
diff --git a/puppet/modules/wikilabels/templates/apache-site-wikilabels.erb 
b/puppet/modules/wikilabels/templates/apache-site-wikilabels.erb
deleted file mode 100644
index ba10199..0000000
--- a/puppet/modules/wikilabels/templates/apache-site-wikilabels.erb
+++ /dev/null
@@ -1,10 +0,0 @@
-#####################################################################
-### THIS FILE IS MANAGED BY PUPPET
-#####################################################################
-
-ServerName <%= @vhost_name %>
-
-ProxyPass / http://localhost:<%= @port %>/
-ProxyPassReverse / http://localhost:<%= @port %>/
-ProxyPreserveHost On
-RequestHeader set X-Forwarded-Proto "https" env=HTTPS

-- 
To view, visit https://gerrit.wikimedia.org/r/377683
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I079c22e3922f4047622dc496d7e5740877faf60d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to