2014-05-07 17:03:16 -07:00
|
|
|
from bootstrapvz.base import Task
|
|
|
|
from bootstrapvz.common import phases
|
2014-06-22 05:54:44 +00:00
|
|
|
from bootstrapvz.common.tasks import boot
|
2014-05-07 17:03:16 -07:00
|
|
|
from bootstrapvz.common.tasks import initd
|
2014-06-22 05:54:44 +00:00
|
|
|
from bootstrapvz.providers.gce.tasks import boot as gceboot
|
2014-10-31 05:32:15 -07:00
|
|
|
from bootstrapvz.plugins.docker_daemon.pull import pull
|
2014-05-07 17:03:16 -07:00
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
ASSETS_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__), 'assets'))
|
|
|
|
|
|
|
|
|
|
|
|
class AddDockerDeps(Task):
|
|
|
|
description = 'Add packages for docker deps'
|
|
|
|
phase = phases.package_installation
|
|
|
|
DOCKER_DEPS = ['aufs-tools', 'btrfs-tools', 'git', 'iptables',
|
2014-11-19 11:53:23 -08:00
|
|
|
'procps', 'xz-utils', 'ca-certificates']
|
2014-05-07 17:03:16 -07:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
for pkg in cls.DOCKER_DEPS:
|
|
|
|
info.packages.add(pkg)
|
|
|
|
|
|
|
|
|
|
|
|
class AddDockerBinary(Task):
|
|
|
|
description = 'Add docker binary'
|
|
|
|
phase = phases.system_modification
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2014-09-13 15:08:52 -03:00
|
|
|
from bootstrapvz.common.tools import log_check_call
|
|
|
|
docker_version = info.manifest.plugins['docker_daemon'].get('version', False)
|
|
|
|
docker_url = 'https://get.docker.io/builds/Linux/x86_64/docker-'
|
|
|
|
if docker_version:
|
|
|
|
docker_url += docker_version
|
|
|
|
else:
|
|
|
|
docker_url += 'latest'
|
2014-05-07 17:03:16 -07:00
|
|
|
bin_docker = os.path.join(info.root, 'usr/bin/docker')
|
2014-09-13 15:08:52 -03:00
|
|
|
log_check_call(['wget', '-O', bin_docker, docker_url])
|
2014-05-07 17:03:16 -07:00
|
|
|
os.chmod(bin_docker, 0755)
|
|
|
|
|
|
|
|
|
|
|
|
class AddDockerInit(Task):
|
|
|
|
description = 'Add docker init script'
|
|
|
|
phase = phases.system_modification
|
|
|
|
successors = [initd.InstallInitScripts]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
init_src = os.path.join(ASSETS_DIR, 'init.d/docker')
|
|
|
|
info.initd['install']['docker'] = init_src
|
|
|
|
default_src = os.path.join(ASSETS_DIR, 'default/docker')
|
|
|
|
default_dest = os.path.join(info.root, 'etc/default/docker')
|
|
|
|
shutil.copy(default_src, default_dest)
|
2014-06-22 05:54:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EnableMemoryCgroup(Task):
|
|
|
|
description = 'Change grub configuration to enable the memory cgroup'
|
|
|
|
phase = phases.system_modification
|
2014-07-09 21:20:26 +02:00
|
|
|
successors = [boot.InstallGrub_1_99, boot.InstallGrub_2]
|
2014-06-22 05:54:44 +00:00
|
|
|
predecessors = [boot.ConfigureGrub, gceboot.ConfigureGrub]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
from bootstrapvz.common.tools import sed_i
|
|
|
|
grub_config = os.path.join(info.root, 'etc/default/grub')
|
|
|
|
sed_i(grub_config, r'^(GRUB_CMDLINE_LINUX*=".*)"\s*$', r'\1 cgroup_enable=memory"')
|
2014-10-31 05:32:15 -07:00
|
|
|
|
2014-11-19 11:49:17 -08:00
|
|
|
|
2014-10-31 05:32:15 -07:00
|
|
|
class PullDockerImages(Task):
|
|
|
|
description = 'Pull docker images'
|
|
|
|
phase = phases.system_modification
|
|
|
|
predecessors = [AddDockerBinary]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2014-11-19 11:53:23 -08:00
|
|
|
pull_images = info.manifest.plugins['docker_daemon'].get('pull_images', [])
|
|
|
|
if len(pull_images) == 0:
|
|
|
|
return
|
|
|
|
pull_images_retries = info.manifest.plugins['docker_daemon'].get('pull_images_retries', 10)
|
|
|
|
pull(info, pull_images, pull_images_retries)
|