From 65931a102236e0ec8b90a03804138596384c6299 Mon Sep 17 00:00:00 2001 From: Paolo Mainardi Date: Tue, 30 Dec 2014 02:01:39 +0100 Subject: [PATCH] drocker.phar: boot2docker configurations --- DrockerRoboFile.php | 47 ++++++++++++++++++++++++++++++++++----- Robofile.php | 5 +++++ src/scripts/boot2local.sh | 4 ++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/scripts/boot2local.sh diff --git a/DrockerRoboFile.php b/DrockerRoboFile.php index 627718d..fbfc183 100644 --- a/DrockerRoboFile.php +++ b/DrockerRoboFile.php @@ -7,17 +7,24 @@ class RoboFile extends \Robo\Tasks { /** - * Init drocker project. + * Get internal base path. */ - public function init() - { - $this->yell("Drocker init."); + private function getBasePath() { $base_path = __DIR__; - $phar = FALSE; if (strpos(__FILE__, 'phar://') !== FALSE) { $base_path = 'phar://drocker.phar'; - $phar = TRUE; } + return $base_path; + } + + /** + * Init drocker project. + */ + public function init() + { + $this->yell("Drocker init."); + $base_path = $this->getBasePath(); + // Create directory structure. $this->taskFileSystemStack() ->mkdir('data') @@ -44,4 +51,32 @@ public function init() ->to($gid) ->run(); } + + /** + * Reconfigure boot2docker cpu/memory. + */ + public function boot2dockerOptimize($opts = ['cpu' => '1', 'memory' => '8192']) { + $memory = $opts['memory']; + $cpu = $opts['cpu']; + $this->taskExecStack() + ->stopOnFail(TRUE) + ->exec('boot2docker stop') + ->exec('VBoxManage modifyvm "boot2docker-vm" --memory ' . $memory . ' --cpus ' . $cpu) + ->exec('boot2docker up') + ->run(); + } + + /** + * Configure NFS mount boot script. + */ + public function boot2dockerNfsSetup() { + $base_path = $this->getBasePath(); + $mount_boot_script = file_get_contents($base_path . '/src/scripts/boot2local.sh'); + $this->taskExecStack() + ->stopOnFail(TRUE) + ->exec('boot2docker ssh "sudo rm /var/lib/boot2docker/bootlocal.sh && sudo touch /var/lib/boot2docker/bootlocal.sh"') + ->exec('boot2docker ssh "echo \'' . $mount_boot_script . '\' | sudo tee -a /var/lib/boot2docker/bootlocal.sh" >/dev/null') + ->exec('boot2docker restart') + ->run(); + } } diff --git a/Robofile.php b/Robofile.php index 14f0abd..3ebbbf4 100644 --- a/Robofile.php +++ b/Robofile.php @@ -60,7 +60,12 @@ public function pharBuild() { // Add drocker binary and make it as executable. $packer->addFile('DrockerRoboFile.php', 'DrockerRoboFile.php'); + // Add fig.yml. $packer->addFile('fig.yml.dist', 'fig.yml.dist'); + + // Add boot2local.sh script. + $packer->addFile('src/scripts/boot2local.sh', 'src/scripts/boot2local.sh'); + $packer->addFile('drocker', 'drocker') ->executable('drocker') ->run(); diff --git a/src/scripts/boot2local.sh b/src/scripts/boot2local.sh new file mode 100644 index 0000000..4fd71db --- /dev/null +++ b/src/scripts/boot2local.sh @@ -0,0 +1,4 @@ +#|/bin/bash +sudo umount /Users +sudo /usr/local/etc/init.d/nfs-client start +sudo mount 192.168.59.3:/Users /Users -o rw,async,noatime,rsize=32768,wsize=32768,proto=tcp