Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tom Niget
slapos
Commits
7acc2946
Commit
7acc2946
authored
Apr 17, 2012
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apache frontend : Add support for custom domains
parent
de6fc7f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
+20
-15
slapos/recipe/apache_frontend/__init__.py
slapos/recipe/apache_frontend/__init__.py
+20
-15
No files found.
slapos/recipe/apache_frontend/__init__.py
View file @
7acc2946
...
@@ -70,33 +70,40 @@ class Recipe(BaseSlapRecipe):
...
@@ -70,33 +70,40 @@ class Recipe(BaseSlapRecipe):
service_dict
=
{}
service_dict
=
{}
# Check if default port
# Check if default port
if
frontend_port_number
is
443
:
if
frontend_port_number
is
443
or
frontend_port_number
is
80
:
base_url
=
"%s/"
%
frontend_domain_name
port_snippet
=
""
else
:
else
:
base_url
=
"%s:%s/"
%
(
frontend_domain_name
,
frontend_port_number
)
port_snippet
=
":%s"
%
frontend_port_number
for
slave_instance
in
slave_instance_list
:
for
slave_instance
in
slave_instance_list
:
url
=
slave_instance
.
get
(
"url"
,
None
)
backend_
url
=
slave_instance
.
get
(
"url"
,
None
)
reference
=
slave_instance
.
get
(
"slave_reference"
)
reference
=
slave_instance
.
get
(
"slave_reference"
)
# Set scheme (http? https?)
# Future work may allow to choose between http and https (or both?)
scheme
=
'https://'
self
.
logger
.
info
(
'processing slave instance: %s'
%
reference
)
self
.
logger
.
info
(
'processing slave instance: %s'
%
reference
)
# Check for mandatory slave fields
# Check for mandatory slave fields
if
url
is
None
:
if
backend_
url
is
None
:
self
.
logger
.
warn
(
'No "url" parameter is defined for %s slave'
\
self
.
logger
.
warn
(
'No "url" parameter is defined for %s slave'
\
'instance. Ignoring it.'
%
reference
)
'instance. Ignoring it.'
%
reference
)
continue
continue
subdomain
=
reference
.
replace
(
"-"
,
""
).
lower
()
# Check for custom domain (like mypersonaldomain.com)
slave_dict
[
reference
]
=
"https://%s.%s"
%
(
subdomain
,
base_url
)
# If no custom domain, use generated one
domain
=
slave_instance
.
get
(
'custom_domain'
,
"%s.%s"
%
(
reference
.
replace
(
"-"
,
""
).
lower
(),
frontend_domain_name
))
slave_dict
[
reference
]
=
"%s%s%s/"
%
(
scheme
,
domain
,
port_snippet
)
# Check if we want varnish+stunnel cache.
if
slave_instance
.
get
(
"enable_cache"
,
""
).
upper
()
in
(
'1'
,
'TRUE'
):
if
slave_instance
.
get
(
"enable_cache"
,
""
).
upper
()
in
(
'1'
,
'TRUE'
):
# XXX-Cedric : need to refactor to clean code? (to many variables)
# XXX-Cedric : need to refactor to clean code? (to many variables)
rewrite_rule
=
self
.
configureVarnishSlave
(
rewrite_rule
=
self
.
configureVarnishSlave
(
base_varnish_port
,
url
,
slave_instance
,
frontend_domain_name
)
base_varnish_port
,
backend_url
,
reference
,
domain
)
base_varnish_port
+=
2
base_varnish_port
+=
2
else
:
else
:
rewrite_rule
=
"%s
.%s %s"
%
(
subdomain
,
frontend_domain_name
,
url
)
rewrite_rule
=
"%s
%s"
%
(
domain
,
backend_
url
)
# Finally, if successful, we add the rewrite rule to our list of rules
# Finally, if successful, we add the rewrite rule to our list of rules
if
rewrite_rule
:
if
rewrite_rule
:
...
@@ -182,9 +189,8 @@ class Recipe(BaseSlapRecipe):
...
@@ -182,9 +189,8 @@ class Recipe(BaseSlapRecipe):
return
self
.
path_list
return
self
.
path_list
def
configureVarnishSlave
(
self
,
base_varnish_port
,
url
,
slave_instance
,
def
configureVarnishSlave
(
self
,
base_varnish_port
,
url
,
reference
,
service_dict
,
frontend_domain_name
):
service_dict
,
domain
):
reference
=
slave_instance
.
get
(
"slave_reference"
)
# Varnish should use stunnel to connect to the backend
# Varnish should use stunnel to connect to the backend
base_varnish_control_port
=
base_varnish_port
base_varnish_control_port
=
base_varnish_port
base_varnish_port
+=
1
base_varnish_port
+=
1
...
@@ -214,9 +220,8 @@ class Recipe(BaseSlapRecipe):
...
@@ -214,9 +220,8 @@ class Recipe(BaseSlapRecipe):
public_port
=
stunnel_port
,
public_port
=
stunnel_port
,
private_ip
=
slave_host
.
replace
(
"["
,
""
).
replace
(
"]"
,
""
),
private_ip
=
slave_host
.
replace
(
"["
,
""
).
replace
(
"]"
,
""
),
private_port
=
slave_port
)
private_port
=
slave_port
)
return
"%s.%s http://%s:%s"
%
\
return
"%s http://%s:%s"
%
\
(
reference
.
replace
(
"-"
,
""
),
frontend_domain_name
,
(
domain
,
varnish_ip
,
base_varnish_port
)
varnish_ip
,
base_varnish_port
)
def
installLogrotate
(
self
):
def
installLogrotate
(
self
):
"""Installs logortate main configuration file and registers its to cron"""
"""Installs logortate main configuration file and registers its to cron"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment