Пример #1
0
 def create(self):
     with settings(**self.server.settings()):
         require = None
         if self.username is None or self.password is None:
             Utils.notice("Username or password missing, discarding password protection.")
         else:
             # Site will be password protected
             # Create password file
             self.htpasswd()
             require = "valid-user"
         context = {
             "name": self.name,
             "full_name": self.full_name,
             "aliases": self.aliases,
             "document_root": self.deployment.drupal_site.path,
             "auth_type": "Basic",
             "auth_name": "Authentication Required",
             "auth_user_file": self.htpasswd_path,
             "require": require
         }
         upload_template('vhost.conf', self.domain_path, context,
                         use_jinja=True,
                         template_dir=env.template_dir,
                         backup=False,
                         mode=0644)
         self.server.symlink(self.domain_path, join('/etc/apache2/sites-available', self.full_name), force=True, sudo=True)
Пример #2
0
 def create(self):
     with settings(**self.server.settings()):
         require = None
         if self.username is None or self.password is None:
             Utils.notice(
                 "Username or password missing, discarding password protection."
             )
         else:
             # Site will be password protected
             # Create password file
             self.htpasswd()
             require = "valid-user"
         context = {
             "name": self.name,
             "full_name": self.full_name,
             "aliases": self.aliases,
             "document_root": self.deployment.drupal_site.path,
             "auth_type": "Basic",
             "auth_name": "Authentication Required",
             "auth_user_file": self.htpasswd_path,
             "require": require
         }
         upload_template('vhost.conf',
                         self.domain_path,
                         context,
                         use_jinja=True,
                         template_dir=env.template_dir,
                         backup=False,
                         mode=0644)
         self.server.symlink(self.domain_path,
                             join('/etc/apache2/sites-available',
                                  self.full_name),
                             force=True,
                             sudo=True)
Пример #3
0
 def load(filename, element):
     config = None
     f = open(filename)
     try:
         config = yaml.safe_load(f)[element]
     except KeyError:
         Utils.error("The '{0}' element was not found in '{1}'.".format(element, filename))
     finally:
         f.close()
     return config
Пример #4
0
def code(url=None, branch='master', revision=None):
    """
    Tell Druploy where to get the code and what branch/revision to deploy
    """
    try:
        with hide(*env.clean):
            env.source_code = CodeDeploymentSource(env.source_deployment, url, branch, revision)
    except AgileProjectError, e:
        Utils.error("Could not configure code, ending")
        raise
Пример #5
0
def project_list(archive=False):
    """
    List all projects on a server
    """
    try:
        with hide(*env.clean):
            Utils.notice("The server has the following projects")
            map(lambda notices: Utils.notice(notices, 4), Project.list(env.server, archive))
    except AgileProjectError, e:
        Utils.error("Could not list projects, ending")
Пример #6
0
def code(url=None, branch='master', revision=None):
    """
    Tell Druploy where to get the code and what branch/revision to deploy
    """
    try:
        with hide(*env.clean):
            env.source_code = CodeDeploymentSource(env.source_deployment, url,
                                                   branch, revision)
    except AgileProjectError, e:
        Utils.error("Could not configure code, ending")
        raise
Пример #7
0
def project_list(archive=False):
    """
    List all projects on a server
    """
    try:
        with hide(*env.clean):
            Utils.notice("The server has the following projects")
            map(lambda notices: Utils.notice(notices, 4),
                Project.list(env.server, archive))
    except AgileProjectError, e:
        Utils.error("Could not list projects, ending")
Пример #8
0
 def load(filename, element):
     config = None
     f = open(filename)
     try:
         config = yaml.safe_load(f)[element]
     except KeyError:
         Utils.error("The '{0}' element was not found in '{1}'.".format(
             element, filename))
     finally:
         f.close()
     return config
Пример #9
0
def source(drupal_root=None):
    """
    When taking the database/files from a project not managed by Druploy, tell it
    where the drupal root is
    """
    try:
        with hide(*env.clean):
            env.source_project = ExternalProject(env.server, drupal_root)
            env.source_deployment = ExternalDeployment(env.source_project)
    except AgileProjectError, e:
        Utils.error("Could not initialize an unmanaged source deployment")
        raise
Пример #10
0
def source(drupal_root=None):
    """
    When taking the database/files from a project not managed by Druploy, tell it
    where the drupal root is
    """
    try:
        with hide(*env.clean):
            env.source_project = ExternalProject(env.server, drupal_root)
            env.source_deployment = ExternalDeployment(env.source_project)
    except AgileProjectError, e:
        Utils.error("Could not initialize an unmanaged source deployment")
        raise
Пример #11
0
def deployment(name=None):
    """
    Tell Druploy what deployment to use.
    """
    try:
        with hide(*env.clean):
            # default name to branch name
            if name is None:
                name = env.source_code.branch
            env.deployment = ManagedDeployment(env.project, name)
            ManagedDeployment.create(env.deployment)
    except AgileProjectError:
        Utils.error("Error")
Пример #12
0
def deployment(name=None):
    """
    Tell Druploy what deployment to use.
    """
    try:
        with hide(*env.clean):
            # default name to branch name
            if name is None:
                name = env.source_code.branch
            env.deployment = ManagedDeployment(env.project, name)
            ManagedDeployment.create(env.deployment)
    except AgileProjectError:
        Utils.error("Error")
Пример #13
0
def deployment_list(project=None):
    """
    List all deployments for a project (optional) on a server
    """
    try:
        with hide(*env.clean):
            if project is None:
                env.project = Project(name, env.server)
            Utils.notice("The project {0} has the following deployments".format(env.project.name))
            map(lambda notices: Utils.notice(notices, 4), Deployment.list(env.project))
    except AgileProjectError, e:
        Utils.error("Could not list deployments, ending")
        raise
Пример #14
0
def project(name=None):
    """
    Set the current project for Druploy
    """
    try:
        env.project = ManagedProject(env.server, name)
        if not env.project.exists():
            if confirm("The project {0} does not exist, would you like to create it?".format(env.project.name)):
                Project.create(env.project)
            else:
                Utils.error("Cannot perform tasks on non existing project")
                abort("Aborting")
    except AgileProjectError, e:
        Utils.error("Could not create project, ending")
Пример #15
0
def database(updating=True, resetting=False, installing=False):
    """
    Tell Druploy what method to use to deploy the database
    """
    try:
        with hide(*env.clean):
            if updating == 'True':
                env.source_database = UpdateFromServerDeploymentDatabaseSource(env.source_deployment)
            elif resetting == 'True':
                env.source_database = ResetToSnapshotDeploymentDatabaseSource(env.source_deployment)
            elif installing == 'True':
                env.source_database = DrupalInstallDeploymentDatabaseSource()
    except AttributeError, e:
        Utils.error("Source deployment not initialized properly, could not collect database")
Пример #16
0
def domain(name=None, aliases=[], username=None, password=None):
    """
    Configure a domain to run on the current deployment
    """
    try:
        with hide(*env.clean):
            print(env.deployment)
            env.domain = Domain(env.deployment, name, aliases, username, password)
            env.domain.create()
            env.domain.enable()
    except AttributeError:
        Utils.error("Source deployment not initialized properly, could not enable")
    except AgileProjectError:
        Utils.error("Could not enable domain")
        abort("Ending")
Пример #17
0
def files(updating=True, resetting=False):
    """
    Tell Druploy what method to use to deploy the files
    """
    try:
        with hide(*env.clean):
            if updating == 'True':
                env.source_files = UpdateFromServerFilesSource(env.source_deployment)
            elif resetting == 'True':
                env.source_files = ResetToSnapshotFilesSource(env.source_deployment)
    except AttributeError:
        Utils.error("Source deployment not initialized properly, could not collect files")
    except AgileProjectError:
        Utils.error("Could not collect files")
        abort("Ending")
Пример #18
0
def project(name=None):
    """
    Set the current project for Druploy
    """
    try:
        env.project = ManagedProject(env.server, name)
        if not env.project.exists():
            if confirm(
                    "The project {0} does not exist, would you like to create it?"
                    .format(env.project.name)):
                Project.create(env.project)
            else:
                Utils.error("Cannot perform tasks on non existing project")
                abort("Aborting")
    except AgileProjectError, e:
        Utils.error("Could not create project, ending")
Пример #19
0
def deployment_list(project=None):
    """
    List all deployments for a project (optional) on a server
    """
    try:
        with hide(*env.clean):
            if project is None:
                env.project = Project(name, env.server)
            Utils.notice(
                "The project {0} has the following deployments".format(
                    env.project.name))
            map(lambda notices: Utils.notice(notices, 4),
                Deployment.list(env.project))
    except AgileProjectError, e:
        Utils.error("Could not list deployments, ending")
        raise
Пример #20
0
def domain(name=None, aliases=[], username=None, password=None):
    """
    Configure a domain to run on the current deployment
    """
    try:
        with hide(*env.clean):
            print(env.deployment)
            env.domain = Domain(env.deployment, name, aliases, username,
                                password)
            env.domain.create()
            env.domain.enable()
    except AttributeError:
        Utils.error(
            "Source deployment not initialized properly, could not enable")
    except AgileProjectError:
        Utils.error("Could not enable domain")
        abort("Ending")
Пример #21
0
def database(updating=True, resetting=False, installing=False):
    """
    Tell Druploy what method to use to deploy the database
    """
    try:
        with hide(*env.clean):
            if updating == 'True':
                env.source_database = UpdateFromServerDeploymentDatabaseSource(
                    env.source_deployment)
            elif resetting == 'True':
                env.source_database = ResetToSnapshotDeploymentDatabaseSource(
                    env.source_deployment)
            elif installing == 'True':
                env.source_database = DrupalInstallDeploymentDatabaseSource()
    except AttributeError, e:
        Utils.error(
            "Source deployment not initialized properly, could not collect database"
        )
Пример #22
0
def deploy():
    """
    Deploy using the configured code, files, database, and deployment.
    """
    try:
        with hide(*env.clean):
            if env.deployment is None:
                deployment(None)
            env.deployment.code.source = env.source_code
            env.deployment.code.destination = CodeDeploymentDestination(env.deployment)
            env.deployment.files.source = env.source_files
            env.deployment.files.destination = FilesDestination(env.deployment)
            env.deployment.database.source = env.source_database
            env.deployment.database.destination = DatabaseDeploymentDestination(env.deployment)
            env.deployment.run()
    except AgileProjectError:
        Utils.error("Could not deploy, ending")
        raise
Пример #23
0
def files(updating=True, resetting=False):
    """
    Tell Druploy what method to use to deploy the files
    """
    try:
        with hide(*env.clean):
            if updating == 'True':
                env.source_files = UpdateFromServerFilesSource(
                    env.source_deployment)
            elif resetting == 'True':
                env.source_files = ResetToSnapshotFilesSource(
                    env.source_deployment)
    except AttributeError:
        Utils.error(
            "Source deployment not initialized properly, could not collect files"
        )
    except AgileProjectError:
        Utils.error("Could not collect files")
        abort("Ending")
Пример #24
0
def deploy():
    """
    Deploy using the configured code, files, database, and deployment.
    """
    try:
        with hide(*env.clean):
            if env.deployment is None:
                deployment(None)
            env.deployment.code.source = env.source_code
            env.deployment.code.destination = CodeDeploymentDestination(
                env.deployment)
            env.deployment.files.source = env.source_files
            env.deployment.files.destination = FilesDestination(env.deployment)
            env.deployment.database.source = env.source_database
            env.deployment.database.destination = DatabaseDeploymentDestination(
                env.deployment)
            env.deployment.run()
    except AgileProjectError:
        Utils.error("Could not deploy, ending")
        raise
Пример #25
0
def drush_alias_create():
    """
    Create drush aliases for each deployment in each project
    """
    try:
        with hide(*env.clean):
            drupal_roots = DrupalRoot.list(env.project)

            Utils.notice("The project has the following Drupal roots")
            [Utils.notice(drupal_root, 4) for drupal_root in drupal_roots]

            Utils.notice("Creating Drush aliases")
            for drupal_root in drupal_roots:
                drush_alias = DrushAlias(drupal_root)
                DrushAlias.create(drush_alias)

    except AgileProjectError:
        Utils.error("Could not sync aliases")
        raise
Пример #26
0
def drush_alias_create():
    """
    Create drush aliases for each deployment in each project
    """
    try:
        with hide(*env.clean):
            drupal_roots = DrupalRoot.list(env.project)

            Utils.notice("The project has the following Drupal roots")
            [Utils.notice(drupal_root, 4) for drupal_root in drupal_roots]

            Utils.notice("Creating Drush aliases")
            for drupal_root in drupal_roots:
                drush_alias = DrushAlias(drupal_root)
                DrushAlias.create(drush_alias)

    except AgileProjectError:
        Utils.error("Could not sync aliases")
        raise
Пример #27
0
 def htpasswd(self):
     Utils.notice("Generating htpasswd file...")
     self.server.sudo_or_run("htpasswd -bc " + self.htpasswd_path
                     + " " + self.username
                     + " " + self.password)
Пример #28
0
from druploy.core import *
from druploy.utils import Utils
from druploy.config import Config
from druploy.exceptions import *
from druploy.server import *
from druploy.project import *
from druploy.deployment import *
from druploy.drupal import *
from druploy.code import *
from druploy.database import *
from druploy.files import *
from druploy.domain import *

# Initialization
try:
    Utils.notice("Run initialisation code.")
    env.use_ssh_config = True
    env.forward_agent = True
    env.local_path = os.path.dirname(os.path.realpath(__file__))
    env.template_dir = os.path.join(env.local_path, "templates")
    env.server = None
    env.project = None
    env.source_project = None
    env.source_deployment = None
    env.source_code = None
    env.source_files = None
    env.source_database = None
    env.deployment = None
    env.domain = None
    env.clean = ()
except AgileProjectError:
Пример #29
0
from druploy.core import *
from druploy.utils import Utils
from druploy.config import Config
from druploy.exceptions import *
from druploy.server import *
from druploy.project import *
from druploy.deployment import *
from druploy.drupal import *
from druploy.code import *
from druploy.database import *
from druploy.files import *
from druploy.domain import *

# Initialization
try:
    Utils.notice("Run initialisation code.")
    env.use_ssh_config = True
    env.forward_agent = True
    env.local_path = os.path.dirname(os.path.realpath(__file__))
    env.template_dir = os.path.join(env.local_path, "templates")
    env.server = None
    env.project = None
    env.source_project = None
    env.source_deployment = None
    env.source_code = None
    env.source_files = None
    env.source_database = None
    env.deployment = None
    env.domain = None
    env.clean = ()
except AgileProjectError:
Пример #30
0
 def htpasswd(self):
     Utils.notice("Generating htpasswd file...")
     self.server.sudo_or_run("htpasswd -bc " + self.htpasswd_path + " " +
                             self.username + " " + self.password)