Changeset f2215d09 in darkpeak-services


Ignore:
Timestamp:
Sep 28, 2018, 12:54:43 AM (2 years ago)
Author:
Mat Booth <mat.booth@…>
Branches:
keycloak, master, pleroma
Children:
f97b97d9
Parents:
04cf77d5
Message:

Fix CNAME functionality for static page hosting

Fixes #9

Location:
roles
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • roles/apache2/defaults/main.yml

    r04cf77d5 rf2215d09  
    11service_name: default
    2 domain: "{{ domain_name }}"
     2
     3# Not specifying a domain makes this the default vhost
     4domain: ""
    35domain_alias: ""
    46
    5 # The name of the service that is providing our home page,
    6 # apache2 will redirect the default bare domain to this service
    7 redirect_to_service: wiki
     7web_root: "{{ default_web_root }}/{{ service_name }}"
  • roles/apache2/tasks/main.yml

    r04cf77d5 rf2215d09  
    6969- name: Configure apache for default site
    7070  include: configure-apache-site.yml
     71
     72- name: Install placeholder index for default site
     73  copy:
     74    src: index.html
     75    dest: "{{ web_root }}/index.html"
     76    group: www-data
     77    owner: root
     78    mode: 0640
     79
     80- name: TODO - Add users to the www-data group instead of setting 777 here
     81  file:
     82    state: directory
     83    path:  "{{ web_root }}"
     84    group: www-data
     85    owner: root
     86    mode:  0777
  • roles/apache2/templates/apache.incl.conf.j2

    r04cf77d5 rf2215d09  
    1 # This file is for service-specific apache configuration
     1# This is the default, catch-all vhost, so we probably want to
     2# do something based on the hostname of incoming requests
     3
     4# Use of rewrite engine is necessary in order to interrogate
     5# the server variables like HTTP_HOST
     6RewriteEngine on
     7RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9-.]+)$
     8
     9# If there is a sub-directory that matches the hostname, then
     10# serve pages from that directory
     11RewriteCond {{ web_root }}/%1 -d
     12RewriteRule ^(.*) {{ web_root }}/%1$1 [L]
     13
     14# Otherwise, just serve the placeholder page because the service
     15# doesn't exist yet
     16RewriteRule ^(.*) {{ web_root }}/index.html [L]
     17
     18# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  • roles/apache2/templates/apache.vhost.conf.j2

    r04cf77d5 rf2215d09  
    11<VirtualHost *:80>
    22        ServerAdmin webmaster@{{ domain_name }}
     3{% if domain != '' %}
    34        ServerName {{ domain }}
     5{% endif %}
    46{% if domain_alias != '' %}
    57        ServerAlias {{ domain_alias }}
     
    1416        AliasMatch "^/(.well-known/acme-challenge/.*)" "/usr/share/certbot/$1"
    1517
    16 {% if service_name == 'pages' %}
     18{% if service_name == 'default' or service_name == 'pages' %}
    1719        # Special case for static pages; don't use HTTPS due to having no certificates for user sites
    1820        # So just include the site config here and don't redirect to HTTPS equivilents
     
    2830        <VirtualHost _default_:443>
    2931                ServerAdmin webmaster@{{ domain_name }}
     32{% if domain != '' %}
    3033                ServerName {{ domain }}
     34{% endif %}
    3135{% if domain_alias != '' %}
    3236                ServerAlias {{ domain_alias }}
    3337{% endif %}
    3438
    35 {% if service_name == 'default' %}
    36                 # Redirect the bare domain name to the service providing the home page
    37                 Redirect / https://{{ redirect_to_service }}.{{ domain_name }}/
    38 {% else %}
    3939                DocumentRoot {{ web_root }}
    40 {% endif %}
    4140
    4241                ErrorLog ${APACHE_LOG_DIR}/{{ service_name }}/error.log
  • roles/mediawiki/defaults/main.yml

    r04cf77d5 rf2215d09  
    22subdomain: wiki
    33domain: "{{ subdomain }}.{{ domain_name }}"
    4 domain_alias: ""
     4# Since we are using the wiki as our homepage, both the bare domain and the
     5# www domain should also serve the wiki - set aliases accordingly
     6domain_alias: "{{ domain_name }} www.{{ domain_name }}"
    57web_root: /var/lib/mediawiki
    68
  • roles/pages/files/repo-specific/pages

    r04cf77d5 rf2215d09  
    6767
    6868    pages_dir=$HOME/pages/$GL_REPO
    69     log_dir=$HOME/pages-log
    70     cname_link=/cnames/$cname
    71     cname_log_link=/cnames-log/$cname
     69    cname_dir=/var/www/default
    7270
    7371    # check if file already exists at symlink location
    74     if [ -L $cname_link ]; then
     72    if [ -L "$cname_dir/$cname" ]; then
    7573        # already exists
    7674        # check if the symlink points the target we want
    77         if ! [ "$(readlink $cname_link)" = "$pages_dir" ]; then
     75        if ! [ "$(readlink $cname_dir/$cname)" = "$pages_dir" ]; then
    7876            # CNAME already in use
    7977            echo "======================"
     
    8987        # new CNAME
    9088        # remove any old CNAME symlinks for this repository
    91         for file in /cnames/*; do
    92             if [ "$(readlink $file)" == $pages_dir ]; then
     89        for file in $cname_dir/*; do
     90            if [ "$(readlink $file)" = "$pages_dir" ]; then
    9391                # points to current pages repo
    9492                rm $file
    95                 # we shouldn't need to clean up the access log link as if the
    96                 # root is missing then nginx docs say it won't write to access
    97                 # log, but lets remove it anyway
    98                 rm /cnames-log/$(basename $file)
    9993            fi
    10094        done
    10195        # add symlinks for new CNAME
    102         ln -s $pages_dir $cname_link
    103         ln -f -s $log_dir $cname_log_link
     96        ln -s $pages_dir $cname_dir/$cname
    10497    fi
    10598fi
  • roles/pages/tasks/main.yml

    r04cf77d5 rf2215d09  
    1313  with_items:
    1414    - "repo-specific/pages"
    15 
    16 # The pages hook needs a user-agnostic place to add symlinks if the
    17 # user wants to use a custom domain for their site
    18 - name: Create directories for pages CNAME support
    19   file:
    20     path: "{{ item }}"
    21     state: directory
    22     owner: root
    23     group: root
    24     mode: 0777
    25   with_items:
    26     - "/cnames"
    27     - "/cnames-log"
Note: See TracChangeset for help on using the changeset viewer.