devpi-nginx-vhost-config

Example:

# Create vhost config for devpi.
- devpi-nginx-vhost-config:
    path: /etc/nginx/sites-enabled/vhost_devpi.conf
    owner: devpi
    host: dev.frkl.io
    devpi_root: /home/devpi/.devpi/server
    devpi_host: localhost
    devpi_port: 3141
    devpi_proto: http
    use_https: true

Description

Creates a vhost for devpi on Nginx.

Variables

Name Type Default Description

devpi_host

string localhost

The host where devpi is running.

devpi_port

integer 3141

The port devpi is listening to.

devpi_proto

string http

The devpi server protocol.

devpi_root

string /home/devpi/.devpi/server

The devpi server directory.

hostname

string localhost

The domain-name for the Nginx web-server.

owner

string devpi

The owner of the file.

path

string /etc/nginx/sites-available/vhost_devpi.conf

The path to the config file.

use_https

boolean False

Whether https is used.

Examples

Example 1

Create vhost config for devpi.

Code
- devpi-nginx-vhost-config:
    path: /etc/nginx/sites-enabled/vhost_devpi.conf
    owner: devpi
    host: dev.frkl.io
    devpi_root: /home/devpi/.devpi/server
    devpi_host: localhost
    devpi_port: 3141
    devpi_proto: http
    use_https: true
Description

This here creates a configuration for Nginx to reverse proxy the local devpi service, incl. redirecting all http traffic to https.

Code

doc:
  short_help: Creates a vhost for devpi on Nginx.
  examples:
  - title: Create vhost config for devpi.
    desc: |
      This here creates a configuration for Nginx to reverse proxy the local devpi service, incl. redirecting all http traffic to https.
    vars:
      path: /etc/nginx/sites-enabled/vhost_devpi.conf
      owner: devpi
      host: dev.frkl.io
      devpi_root: /home/devpi/.devpi/server
      devpi_host: localhost
      devpi_port: 3141
      devpi_proto: http
      use_https: true

args:
  path:
    doc:
      short_help: The path to the config file.
    required: false
    default: /etc/nginx/sites-available/vhost_devpi.conf
    type: string
  owner:
    doc:
      short_help: The owner of the file.
    required: false
    default: devpi
    type: string
  hostname:
    doc:
      short_help: The domain-name for the Nginx web-server.
    required: false
    default: localhost
    type: string
  devpi_host:
    doc:
      short_help: The host where devpi is running.
    required: false
    default: localhost
    type: string
    cli:
      show_default: true
  devpi_port:
    doc:
      short_help: The port devpi is listening to.
    default: 3141
    required: false
    type: integer
    cli:
      show_default: true
  devpi_proto:
    doc:
      short_help: The devpi server protocol.
    type: string
    allowed:
    - http
    - https
    required: false
    default: http
    cli:
      show_default: true
  use_https:
    doc:
      short_help: Whether https is used.
    type: boolean
    default: false
    required: false
    cli:
      is_flag: true
  devpi_root:
    doc:
      short_help: The devpi server directory.
    required: false
    default: /home/devpi/.devpi/server
    type: string
    cli:
      show_default: true

frecklets:
- nginx-server-block-file:
    path: '{{:: path ::}}'
    owner: '{{:: owner ::}}'
    become: true
    server_names:
    - '{{:: hostname ::}}'
    use_https: '{{:: use_https | default(false) ::}}'
    document_root: '{{:: devpi_root ::}}'
    gzip_enabled: true
    gzip:
      gzip_min_length: 2000
      gzip_proxied: any
      gzip_types: text/html application/json
    proxy_read_timeout: 60s
    client_max_body_size: 64M
    location_blocks:
    - location_match: /\+f/
      location_modifier: '~'
      properties: |
        error_page 418 = @proxy_to_app;
        if ($request_method !~ (GET)|(HEAD)) {
          return 418;
        }

        expires max;
        try_files /+files$uri @proxy_to_app;
    - location_match: /\+doc/
      location_modifier: '~'
      properties: |
        try_files $uri @proxy_to_app;
    - location_match: /
      properties: |
        error_page 418 = @proxy_to_app;
        return 418;
    - location_match: '@proxy_to_app'
      properties: |
        proxy_pass {{:: devpi_proto ::}}://{{:: devpi_host ::}}:{{:: devpi_port ::}};
        proxy_set_header X-outside-url $scheme://$host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
frecklecute devpi-nginx-vhost-config --help

Usage: frecklecute devpi-nginx-vhost-config [OPTIONS]

  Creates a vhost for devpi on Nginx.

Options:
  --devpi-host DEVPI_HOST       The host where devpi is running.
  --devpi-port DEVPI_PORT       The port devpi is listening to.
  --devpi-proto DEVPI_PROTO     The devpi server protocol.
  --devpi-root DEVPI_ROOT       The devpi server directory.
  --hostname HOSTNAME           The domain-name for the Nginx web-server.
  --owner OWNER                 The owner of the file.
  --path PATH                   The path to the config file.
  --use-https / --no-use-https  Whether https is used.
  --help                        Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.devpi_nginx_vhost_config.DevpiNginxVhostConfig
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class DevpiNginxVhostConfig(AutoPycklet):
    """Creates a vhost for devpi on Nginx.

       Args:
         devpi_host: The host where devpi is running.
         devpi_port: The port devpi is listening to.
         devpi_proto: The devpi server protocol.
         devpi_root: The devpi server directory.
         hostname: The domain-name for the Nginx web-server.
         owner: The owner of the file.
         path: The path to the config file.
         use_https: Whether https is used.

    """

    FRECKLET_ID = "devpi-nginx-vhost-config"

    devpi_host: str = None
    devpi_port: int = None
    devpi_proto: str = None
    devpi_root: str = None
    hostname: str = None
    owner: str = None
    path: str = None
    use_https: bool = None


    def __post_init__(self):
        super(DevpiNginxVhostConfig, self).__init__(var_names=["devpi_host", "devpi_port", "devpi_proto", "devpi_root", "hostname", "owner", "path", "use_https"])


frecklet_class = DevpiNginxVhostConfig
# -*- coding: utf-8 -*-


#
# module path: pycklets.devpi_nginx_vhost_config.DevpiNginxVhostConfig
#


from pyckles import AutoPycklet

class DevpiNginxVhostConfig(AutoPycklet):
    """Creates a vhost for devpi on Nginx.

       Args:
         devpi_host: The host where devpi is running.
         devpi_port: The port devpi is listening to.
         devpi_proto: The devpi server protocol.
         devpi_root: The devpi server directory.
         hostname: The domain-name for the Nginx web-server.
         owner: The owner of the file.
         path: The path to the config file.
         use_https: Whether https is used.

    """

    FRECKLET_ID = "devpi-nginx-vhost-config"

    def __init__(self, devpi_host="localhost", devpi_port=3141, devpi_proto="http", devpi_root="/home/devpi/.devpi/server", hostname="localhost", owner="devpi", path="/etc/nginx/sites-available/vhost_devpi.conf", use_https=None):

        super(DevpiNginxVhostConfig, self).__init__(var_names=["devpi_host", "devpi_port", "devpi_proto", "devpi_root", "hostname", "owner", "path", "use_https"])
        self._devpi_host = devpi_host
        self._devpi_port = devpi_port
        self._devpi_proto = devpi_proto
        self._devpi_root = devpi_root
        self._hostname = hostname
        self._owner = owner
        self._path = path
        self._use_https = use_https

    @property
    def devpi_host(self):
        return self._devpi_host

    @devpi_host.setter
    def devpi_host(self, devpi_host):
        self._devpi_host = devpi_host

    @property
    def devpi_port(self):
        return self._devpi_port

    @devpi_port.setter
    def devpi_port(self, devpi_port):
        self._devpi_port = devpi_port

    @property
    def devpi_proto(self):
        return self._devpi_proto

    @devpi_proto.setter
    def devpi_proto(self, devpi_proto):
        self._devpi_proto = devpi_proto

    @property
    def devpi_root(self):
        return self._devpi_root

    @devpi_root.setter
    def devpi_root(self, devpi_root):
        self._devpi_root = devpi_root

    @property
    def hostname(self):
        return self._hostname

    @hostname.setter
    def hostname(self, hostname):
        self._hostname = hostname

    @property
    def owner(self):
        return self._owner

    @owner.setter
    def owner(self, owner):
        self._owner = owner

    @property
    def path(self):
        return self._path

    @path.setter
    def path(self, path):
        self._path = path

    @property
    def use_https(self):
        return self._use_https

    @use_https.setter
    def use_https(self, use_https):
        self._use_https = use_https



frecklet_class = DevpiNginxVhostConfig