This repository has been archived by the owner on Jun 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
DropdockRoboFile.php
127 lines (115 loc) · 3.71 KB
/
DropdockRoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
use Symfony\Component\Finder\Finder as Finder;
use Symfony\Component\Yaml\Parser as Parser;
/**
* This is project's console commands configuration for the Dropdock cli tool.
*/
class RoboFile extends \Robo\Tasks
{
/**
* Get internal base path.
*/
private function getBasePath()
{
$base_path = getcwd();
if (strpos(__DIR__, 'phar://') !== FALSE) {
$base_path = 'phar://dropdock.phar';
}
return $base_path;
}
/**
* Init dropdock project.
*/
public function init()
{
$this->yell("Dropdock init.");
$base_path = $this->getBasePath();
// Create directory structure.
$this->taskFileSystemStack()
->mkdir('data')
->mkdir('bin')
->run();
// Create static binaries.
$this->createBinaries();
// Make binaries executables.
$this->taskExec('chmod -R +x bin')->run();
// Rename fig.yml.dist to docker-compose.yml
$this->taskFileSystemStack()
->copy($base_path . '/docker-compose.yml.dist', 'docker-compose.yml')
->run();
$uid = trim($this->taskExec('id -u')->run()->getMessage());
$gid = trim($this->taskExec('id -g')->run()->getMessage());
$this->taskReplaceInFile('docker-compose.yml')
->from('##LOCAL_UID##')
->to($uid)
->run();
$this->taskReplaceInFile('docker-compose.yml')
->from('##LOCAL_GID##')
->to($gid)
->run();
}
/**
* Recreate containers binaries.
*/
public function createBinaries()
{
$yaml = new Parser();
$base_path = $this->getBasePath();
$cwd = getcwd();
$files = Finder::create()->ignoreVCS(true)
->files()
->name('binaries.yml')
->in(__DIR__);
foreach ($files as $file) {
$binaries = $yaml->parse(file_get_contents($base_path . '/' . $file->getRelativePathname()));
foreach ($binaries as $container => $binaries) {
foreach ($binaries as $bin => $opts) {
$this->taskWriteToFile("bin/{$bin}")
->line(isset($opts['env']) ? $opts['env'] : '#!/usr/bin/env bash')
->line("cd {$cwd} && docker-compose run --rm {$container} {$opts['bin']} {$opts['arguments']}")
->run();
}
}
}
}
/**
* Symlink www and bin folders.
*/
public function symlink()
{
$this->taskFileSystemStack()
->symlink('data/var/www', 'www')
->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.
*
* @todo this task needs to be explained better (fe: howto configure nfs exports locally).
*/
public function boot2dockerNfsSetup()
{
$base_path = $this->getBasePath();
$mount_boot_script = file_get_contents($base_path . '/src/scripts/boot2local.sh');
$this->taskExecStack()
->stopOnFail(FALSE)
->exec('boot2docker ssh "sudo rm -f /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 ssh "sudo chmod +x /var/lib/boot2docker/bootlocal.sh" > /dev/null')
->exec('boot2docker restart')
->run();
}
}