python-gunicorn-service

Description

Setup a service executing an application from within a virtualenv.

NOTE: Currently, this frecklet will only work if the user that is specified has their home directory under '/home/'.

Variables

Name Type Default Description

app_module

string --

The app entry point. Required

group

string --

The name of the group to own the service.

If not provided, the project name will be used, and a user with that name will be created if necessary. If the project name contains a whitespace or other invalid character, this will fail. Required

project_name

n/a --

n/a Required

user

string --

The name of the user to own the service.

If not provided, the project name will be used, and a user with that name will be created if necessary. Required

pip_extra_args

string --

Extra arguments forwarded to 'pip'.

project_config

dict ordereddict()

Environment variables to configure app.

python_packages

list []

All necessary Python packages.

python_version

string latest

The version of python.

Code

doc:
  short_help: Setup a service executing an application from within a virtualenv.
  help: |
    Setup a service executing an application from within a virtualenv.

    **NOTE**: Currently, this frecklet will only work if the user that is specified has their home directory under '/home/<username>'.

args:
  _import:
  - python-virtualenv
  app_module:
    doc:
      short_help: The app entry point.
    type: string
  project_config:
    doc:
      short_help: Environment variables to configure app.
    type: dict
    keyschema:
      type: string
    empty: true
    required: false
    default: {}
  user:
    doc:
      short_help: The name of the user to own the service (defaults to project name).
      help: |
        The name of the user to own the service.

        If not provided, the project name will be used, and a user with that name will be created if necessary.
    type: string
    required: true
#    default: "::value_from_project_name::"
  group:
    doc:
      short_help: The name of the group to own the service (defaults to project name).
      help: |
        The name of the group to own the service.

        If not provided, the project name will be used, and a user with that name will be created if necessary. If the project name
        contains a whitespace or other invalid character, this will fail.
    type: string
    required: true
#    default: "::value_from_project_name::"

frecklets:
- python-virtualenv:
    venv_name: '{{:: project_name | slugify ::}}'
      #pip_extra_args: "-U"
    python_packages: "{{:: python_packages | and_items('gunicorn', 'gevent') ::}}"
    python_type: pyenv
    python_version: '{{:: python_version ::}}'
    pip_extra_args: '{{:: pip_extra_args ::}}'
    user: '{{:: user ::}}'
    group: '{{:: group ::}}'
- pyenv-gunicorn-systemd-service-unit-file:
    venv_name: '{{:: project_name | slugify ::}}'
    project_config: '{{:: project_config ::}}'
    app_module: '{{:: app_module ::}}'
    user: '{{:: user ::}}'
    group: '{{:: group ::}}'
frecklecute python-gunicorn-service --help

Usage: frecklecute python-gunicorn-service [OPTIONS]

  Setup a service executing an application from within a virtualenv.

  **NOTE**: Currently, this frecklet will only work if the user that is
  specified has their home directory under '/home/<username>'.

Options:
  --app-module APP_MODULE         The app entry point.  [required]
  --group GROUP                   The name of the group to own the service
                                  (defaults to project name).  [required]
  --project-name PROJECT_NAME     n/a  [required]
  --user USER                     The name of the user to own the service
                                  (defaults to project name).  [required]
  --pip-extra-args PIP_EXTRA_ARGS
                                  Extra arguments forwarded to 'pip'.
  --project-config PROJECT_CONFIG
                                  Environment variables to configure app.
  -p, --python-pkg PYTHON_PACKAGES
                                  All necessary Python packages.
  --python-version PYTHON_VERSION
                                  The version of python.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.python_gunicorn_service.PythonGunicornService
#


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

@dataclass
class PythonGunicornService(AutoPycklet):
    """Setup a service executing an application from within a virtualenv.

     **NOTE**: Currently, this frecklet will only work if the user that is specified has their home directory under '/home/<username>'.

       Args:
         app_module: The app entry point.
         group: The name of the group to own the service (defaults to project name).
         pip_extra_args: Extra arguments forwarded to 'pip'.
         project_config: Environment variables to configure app.
         project_name: n/a
         python_packages: All necessary Python packages.
         python_version: The version of python.
         user: The name of the user to own the service (defaults to project name).

    """

    FRECKLET_ID = "python-gunicorn-service"

    app_module: str = None
    group: str = None
    pip_extra_args: str = None
    project_config: Dict = None
    project_name: str = None
    python_packages: List = None
    python_version: str = None
    user: str = None


    def __post_init__(self):
        super(PythonGunicornService, self).__init__(var_names=["app_module", "group", "pip_extra_args", "project_config", "project_name", "python_packages", "python_version", "user"])


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


#
# module path: pycklets.python_gunicorn_service.PythonGunicornService
#


from pyckles import AutoPycklet

class PythonGunicornService(AutoPycklet):
    """Setup a service executing an application from within a virtualenv.

     **NOTE**: Currently, this frecklet will only work if the user that is specified has their home directory under '/home/<username>'.

       Args:
         app_module: The app entry point.
         group: The name of the group to own the service (defaults to project name).
         pip_extra_args: Extra arguments forwarded to 'pip'.
         project_config: Environment variables to configure app.
         project_name: n/a
         python_packages: All necessary Python packages.
         python_version: The version of python.
         user: The name of the user to own the service (defaults to project name).

    """

    FRECKLET_ID = "python-gunicorn-service"

    def __init__(self, app_module=None, group=None, pip_extra_args=None, project_config=None, project_name=None, python_packages=None, python_version="latest", user=None):

        super(PythonGunicornService, self).__init__(var_names=["app_module", "group", "pip_extra_args", "project_config", "project_name", "python_packages", "python_version", "user"])
        self._app_module = app_module
        self._group = group
        self._pip_extra_args = pip_extra_args
        self._project_config = project_config
        self._project_name = project_name
        self._python_packages = python_packages
        self._python_version = python_version
        self._user = user

    @property
    def app_module(self):
        return self._app_module

    @app_module.setter
    def app_module(self, app_module):
        self._app_module = app_module

    @property
    def group(self):
        return self._group

    @group.setter
    def group(self, group):
        self._group = group

    @property
    def pip_extra_args(self):
        return self._pip_extra_args

    @pip_extra_args.setter
    def pip_extra_args(self, pip_extra_args):
        self._pip_extra_args = pip_extra_args

    @property
    def project_config(self):
        return self._project_config

    @project_config.setter
    def project_config(self, project_config):
        self._project_config = project_config

    @property
    def project_name(self):
        return self._project_name

    @project_name.setter
    def project_name(self, project_name):
        self._project_name = project_name

    @property
    def python_packages(self):
        return self._python_packages

    @python_packages.setter
    def python_packages(self, python_packages):
        self._python_packages = python_packages

    @property
    def python_version(self):
        return self._python_version

    @python_version.setter
    def python_version(self, python_version):
        self._python_version = python_version

    @property
    def user(self):
        return self._user

    @user.setter
    def user(self, user):
        self._user = user



frecklet_class = PythonGunicornService