Beispiel #1
0
def create_virtualenv(srcdir, datadir, preload_image, get_container_name):
    """
    Populate venv from preloaded image
    """
    try:
        if docker.is_boot2docker():
            docker.data_only_container(get_container_name("venv"), ["/usr/lib/ckan"])
            img_id = docker.web_command(
                "/bin/mv /usr/lib/ckan/ /usr/lib/ckan_original", image=preload_image, commit=True
            )
            docker.web_command(
                command="/bin/cp -a /usr/lib/ckan_original/. /usr/lib/ckan/.",
                volumes_from=get_container_name("venv"),
                image=img_id,
            )
            docker.remove_image(img_id)
            return

        docker.web_command(
            command="/bin/cp -a /usr/lib/ckan/. /usr/lib/ckan_target/.",
            rw={datadir + "/venv": "/usr/lib/ckan_target"},
            image=preload_image,
        )
    finally:
        rw = {datadir + "/venv": "/usr/lib/ckan"} if not docker.is_boot2docker() else {}
        volumes_from = get_container_name("venv") if docker.is_boot2docker() else None
        # fix venv permissions
        docker.web_command(
            command="/bin/chown -R --reference=/project /usr/lib/ckan",
            rw=rw,
            volumes_from=volumes_from,
            ro={srcdir: "/project"},
        )
Beispiel #2
0
    def start_postgres_and_solr(self):
        """
        run the DB and search containers
        """
        # complicated because postgres needs hard links to
        # work on its data volume. see issue #5
        if is_boot2docker():
            data_only_container('datacats_pgdata_' + self.name,
                ['/var/lib/postgresql/data'])
            rw = {}
            volumes_from = 'datacats_pgdata_' + self.name
        else:
            rw = {self.datadir + '/postgres': '/var/lib/postgresql/data'}
            volumes_from = None

        # users are created when data dir is blank so we must pass
        # all the user passwords as environment vars
        run_container(
            name='datacats_postgres_' + self.name,
            image='datacats/postgres',
            environment=self.passwords,
            rw=rw,
            volumes_from=volumes_from)
        run_container(
            name='datacats_solr_' + self.name,
            image='datacats/solr',
            rw={self.datadir + '/solr': '/var/lib/solr'},
            ro={self.target + '/schema.xml': '/etc/solr/conf/schema.xml'})
Beispiel #3
0
    def start_postgres_and_solr(self):
        """
        run the DB and search containers
        """
        # complicated because postgres needs hard links to
        # work on its data volume. see issue #5
        if is_boot2docker():
            data_only_container('datacats_pgdata_' + self.name,
                                ['/var/lib/postgresql/data'])
            rw = {}
            volumes_from = 'datacats_pgdata_' + self.name
        else:
            rw = {self.datadir + '/postgres': '/var/lib/postgresql/data'}
            volumes_from = None

        # users are created when data dir is blank so we must pass
        # all the user passwords as environment vars
        run_container(name='datacats_postgres_' + self.name,
                      image='datacats/postgres',
                      environment=self.passwords,
                      rw=rw,
                      volumes_from=volumes_from)
        run_container(
            name='datacats_solr_' + self.name,
            image='datacats/solr',
            rw={self.datadir + '/solr': '/var/lib/solr'},
            ro={self.target + '/schema.xml': '/etc/solr/conf/schema.xml'})
Beispiel #4
0
def start_supporting_containers(sitedir,
                                srcdir,
                                passwords,
                                get_container_name,
                                extra_containers,
                                log_syslog=False):
    """
    Start all supporting containers (containers required for CKAN to
    operate) if they aren't already running, along with some extra
    containers specified by the user
    """
    if docker.is_boot2docker():
        docker.data_only_container(get_container_name('pgdata'),
                                   ['/var/lib/postgresql/data'])
        rw = {}
        volumes_from = get_container_name('pgdata')
    else:
        rw = {sitedir + '/postgres': '/var/lib/postgresql/data'}
        volumes_from = None

    running = set(containers_running(get_container_name))

    needed = set(extra_containers).union({'postgres', 'solr'})

    if not needed.issubset(running):
        stop_supporting_containers(get_container_name, extra_containers)

        # users are created when data dir is blank so we must pass
        # all the user passwords as environment vars
        # XXX: postgres entrypoint magic
        docker.run_container(name=get_container_name('postgres'),
                             image='datacats/postgres',
                             environment=passwords,
                             rw=rw,
                             volumes_from=volumes_from,
                             log_syslog=log_syslog)

        docker.run_container(
            name=get_container_name('solr'),
            image='datacats/solr',
            rw={sitedir + '/solr': '/var/lib/solr'},
            ro={srcdir + '/schema.xml': '/etc/solr/conf/schema.xml'},
            log_syslog=log_syslog)

        for container in extra_containers:
            # We don't know a whole lot about the extra containers so we're just gonna have to
            # mount /project and /datadir r/o even if they're not needed for ease of
            # implementation.
            docker.run_container(name=get_container_name(container),
                                 image=EXTRA_IMAGE_MAPPING[container],
                                 ro={
                                     sitedir: '/datadir',
                                     srcdir: '/project'
                                 },
                                 log_syslog=log_syslog)
Beispiel #5
0
def start_supporting_containers(sitedir, srcdir, passwords,
        get_container_name, extra_containers, log_syslog=False):
    """
    Start all supporting containers (containers required for CKAN to
    operate) if they aren't already running, along with some extra
    containers specified by the user
    """
    if docker.is_boot2docker():
        docker.data_only_container(get_container_name('pgdata'),
            ['/var/lib/postgresql/data'])
        rw = {}
        volumes_from = get_container_name('pgdata')
    else:
        rw = {sitedir + '/postgres': '/var/lib/postgresql/data'}
        volumes_from = None

    running = set(containers_running(get_container_name))

    needed = set(extra_containers).union({'postgres', 'solr'})

    if not needed.issubset(running):
        stop_supporting_containers(get_container_name, extra_containers)

        # users are created when data dir is blank so we must pass
        # all the user passwords as environment vars
        # XXX: postgres entrypoint magic
        docker.run_container(
            name=get_container_name('postgres'),
            image='datacats/postgres',
            environment=passwords,
            rw=rw,
            volumes_from=volumes_from,
            log_syslog=log_syslog)

        docker.run_container(
            name=get_container_name('solr'),
            image='datacats/solr',
            rw={sitedir + '/solr': '/var/lib/solr'},
            ro={srcdir + '/schema.xml': '/etc/solr/conf/schema.xml'},
            log_syslog=log_syslog)

        for container in extra_containers:
            # We don't know a whole lot about the extra containers so we're just gonna have to
            # mount /project and /datadir r/o even if they're not needed for ease of
            # implementation.
            docker.run_container(
                name=get_container_name(container),
                image=EXTRA_IMAGE_MAPPING[container],
                ro={
                    sitedir: '/datadir',
                    srcdir: '/project'
                },
                log_syslog=log_syslog
            )
Beispiel #6
0
def create_virtualenv(srcdir, datadir, preload_image, get_container_name):
    """
    Populate venv from preloaded image
    """
    try:
        if docker.is_boot2docker():
            docker.data_only_container(
                get_container_name('venv'),
                ['/usr/lib/ckan'],
            )
            img_id = docker.web_command(
                '/bin/mv /usr/lib/ckan/ /usr/lib/ckan_original',
                image=preload_image,
                commit=True,
            )
            docker.web_command(
                command='/bin/cp -a /usr/lib/ckan_original/. /usr/lib/ckan/.',
                volumes_from=get_container_name('venv'),
                image=img_id,
            )
            docker.remove_image(img_id)
            return

        docker.web_command(
            command='/bin/cp -a /usr/lib/ckan/. /usr/lib/ckan_target/.',
            rw={datadir + '/venv': '/usr/lib/ckan_target'},
            image=preload_image,
        )
    finally:
        rw = {
            datadir + '/venv': '/usr/lib/ckan'
        } if not docker.is_boot2docker() else {}
        volumes_from = get_container_name(
            'venv') if docker.is_boot2docker() else None
        # fix venv permissions
        docker.web_command(
            command='/bin/chown -R --reference=/project /usr/lib/ckan',
            rw=rw,
            volumes_from=volumes_from,
            ro={srcdir: '/project'},
        )
Beispiel #7
0
 def create_virtualenv(self):
     """
     Populate venv directory from preloaded image
     """
     if is_boot2docker():
         data_only_container('datacats_venv_' + self.name,
             ['/usr/lib/ckan'])
         img_id = web_command(
             '/bin/mv /usr/lib/ckan/ /usr/lib/ckan_original',
             image=self._preload_image(),
             commit=True,
             )
         web_command(
             command='/bin/cp -a /usr/lib/ckan_original/. /usr/lib/ckan/.',
             volumes_from='datacats_venv_' + self.name,
             image=img_id,
             )
         remove_image(img_id)
     else:
         web_command(
             command='/bin/cp -a /usr/lib/ckan/. /usr/lib/ckan_target/.',
             rw={self.datadir + '/venv': '/usr/lib/ckan_target'},
             image=self._preload_image())
Beispiel #8
0
 def create_virtualenv(self):
     """
     Populate venv directory from preloaded image
     """
     if is_boot2docker():
         data_only_container('datacats_venv_' + self.name,
                             ['/usr/lib/ckan'])
         img_id = web_command(
             '/bin/mv /usr/lib/ckan/ /usr/lib/ckan_original',
             image=self._preload_image(),
             commit=True,
         )
         web_command(
             command='/bin/cp -a /usr/lib/ckan_original/. /usr/lib/ckan/.',
             volumes_from='datacats_venv_' + self.name,
             image=img_id,
         )
         remove_image(img_id)
     else:
         web_command(
             command='/bin/cp -a /usr/lib/ckan/. /usr/lib/ckan_target/.',
             rw={self.datadir + '/venv': '/usr/lib/ckan_target'},
             image=self._preload_image())