summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootstrap.php3
-rw-r--r--composer.json13
-rw-r--r--composer.lock332
-rw-r--r--new-site.php23
-rw-r--r--scripts/run.php95
-rw-r--r--scripts/test.php13
-rw-r--r--src/Filesystem/Create.php20
-rw-r--r--src/Filesystem/CreateDirectory.php25
-rw-r--r--src/Filesystem/CreateFile.php25
-rw-r--r--src/Script/Command/Site.php80
-rw-r--r--src/Script/Console.php16
11 files changed, 633 insertions, 12 deletions
diff --git a/bootstrap.php b/bootstrap.php
new file mode 100644
index 0000000..b696801
--- /dev/null
+++ b/bootstrap.php
@@ -0,0 +1,3 @@
+<?php
+
+require('vendor/autoload.php');
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..cb17615
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,13 @@
+{
+ "name": "Dipper",
+ "description": "Deployment tool",
+ "autoload": {
+ "psr-4": {
+ "App\\": "./src"
+ }
+ },
+ "require": {
+ "league/flysystem": "^1.0",
+ "symfony/console": "^3.3"
+ }
+}
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..7a8302f
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,332 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "99b28084e628dd3572ed238a5d4b3975",
+ "packages": [
+ {
+ "name": "league/flysystem",
+ "version": "1.0.41",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/thephpleague/flysystem.git",
+ "reference": "f400aa98912c561ba625ea4065031b7a41e5a155"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/f400aa98912c561ba625ea4065031b7a41e5a155",
+ "reference": "f400aa98912c561ba625ea4065031b7a41e5a155",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9"
+ },
+ "conflict": {
+ "league/flysystem-sftp": "<1.0.6"
+ },
+ "require-dev": {
+ "ext-fileinfo": "*",
+ "mockery/mockery": "~0.9",
+ "phpspec/phpspec": "^2.2",
+ "phpunit/phpunit": "~4.8"
+ },
+ "suggest": {
+ "ext-fileinfo": "Required for MimeType",
+ "league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2",
+ "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3",
+ "league/flysystem-azure": "Allows you to use Windows Azure Blob storage",
+ "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching",
+ "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem",
+ "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files",
+ "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib",
+ "league/flysystem-webdav": "Allows you to use WebDAV storage",
+ "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter",
+ "spatie/flysystem-dropbox": "Allows you to use Dropbox storage",
+ "srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.1-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "League\\Flysystem\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Frank de Jonge",
+ "email": "info@frenky.net"
+ }
+ ],
+ "description": "Filesystem abstraction: Many filesystems, one API.",
+ "keywords": [
+ "Cloud Files",
+ "WebDAV",
+ "abstraction",
+ "aws",
+ "cloud",
+ "copy.com",
+ "dropbox",
+ "file systems",
+ "files",
+ "filesystem",
+ "filesystems",
+ "ftp",
+ "rackspace",
+ "remote",
+ "s3",
+ "sftp",
+ "storage"
+ ],
+ "time": "2017-08-06T17:41:04+00:00"
+ },
+ {
+ "name": "psr/log",
+ "version": "1.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/log.git",
+ "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
+ "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Psr\\Log\\": "Psr/Log/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
+ }
+ ],
+ "description": "Common interface for logging libraries",
+ "homepage": "https://github.com/php-fig/log",
+ "keywords": [
+ "log",
+ "psr",
+ "psr-3"
+ ],
+ "time": "2016-10-10T12:19:37+00:00"
+ },
+ {
+ "name": "symfony/console",
+ "version": "v3.3.6",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/console.git",
+ "reference": "b0878233cb5c4391347e5495089c7af11b8e6201"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/console/zipball/b0878233cb5c4391347e5495089c7af11b8e6201",
+ "reference": "b0878233cb5c4391347e5495089c7af11b8e6201",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9",
+ "symfony/debug": "~2.8|~3.0",
+ "symfony/polyfill-mbstring": "~1.0"
+ },
+ "conflict": {
+ "symfony/dependency-injection": "<3.3"
+ },
+ "require-dev": {
+ "psr/log": "~1.0",
+ "symfony/config": "~3.3",
+ "symfony/dependency-injection": "~3.3",
+ "symfony/event-dispatcher": "~2.8|~3.0",
+ "symfony/filesystem": "~2.8|~3.0",
+ "symfony/http-kernel": "~2.8|~3.0",
+ "symfony/process": "~2.8|~3.0"
+ },
+ "suggest": {
+ "psr/log": "For using the console logger",
+ "symfony/event-dispatcher": "",
+ "symfony/filesystem": "",
+ "symfony/process": ""
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Console\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Console Component",
+ "homepage": "https://symfony.com",
+ "time": "2017-07-29T21:27:59+00:00"
+ },
+ {
+ "name": "symfony/debug",
+ "version": "v3.3.6",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/debug.git",
+ "reference": "7c13ae8ce1e2adbbd574fc39de7be498e1284e13"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/debug/zipball/7c13ae8ce1e2adbbd574fc39de7be498e1284e13",
+ "reference": "7c13ae8ce1e2adbbd574fc39de7be498e1284e13",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9",
+ "psr/log": "~1.0"
+ },
+ "conflict": {
+ "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
+ },
+ "require-dev": {
+ "symfony/http-kernel": "~2.8|~3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Debug\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Debug Component",
+ "homepage": "https://symfony.com",
+ "time": "2017-07-28T15:27:31+00:00"
+ },
+ {
+ "name": "symfony/polyfill-mbstring",
+ "version": "v1.5.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/polyfill-mbstring.git",
+ "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7c8fae0ac1d216eb54349e6a8baa57d515fe8803",
+ "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "suggest": {
+ "ext-mbstring": "For best performance"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.5-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Polyfill\\Mbstring\\": ""
+ },
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony polyfill for the Mbstring extension",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "compatibility",
+ "mbstring",
+ "polyfill",
+ "portable",
+ "shim"
+ ],
+ "time": "2017-06-14T15:44:48+00:00"
+ }
+ ],
+ "packages-dev": [],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": []
+}
diff --git a/new-site.php b/new-site.php
index 0568f8a..53e593d 100644
--- a/new-site.php
+++ b/new-site.php
@@ -5,18 +5,17 @@
// Nginx conf
// Git repo
// Directory structure
-
// Handle options
$options = getopt('d:n:');
if (!array_key_exists('d', $options)) {
- echo "please provide a domain (-d)\n";
- exit(1);
+ echo "please provide a domain (-d)\n";
+ exit(1);
}
if (!array_key_exists('n', $options)) {
- echo "please provide a name (-n)\n";
- exit(1);
+ echo "please provide a name (-n)\n";
+ exit(1);
}
$domain = $options['d'];
@@ -29,23 +28,23 @@ $conf = sprintf($conf[0], $domain, $name, $name, $name, $name, $name);
echo "Making directory structure\n";
if (!mkdir('/web/sites/' . $name)) {
- echo "Failed to create '/web/sites/'" . $name . "\n";
- exit(1);
+ echo "Failed to create '/web/sites/'" . $name . "\n";
+ exit(1);
}
chown('/web/sites/' . $name, "nginx");
if (!mkdir('/web/sites/' . $name . '/logs')) {
- echo "Failed to create '/web/sites/'" . $name . "/logs\n";
- exit(1);
+ echo "Failed to create '/web/sites/'" . $name . "/logs\n";
+ exit(1);
}
chown('/web/sites/' . $name . '/logs', "nginx");
if (!mkdir('/web/sites/' . $name . '/web')) {
- echo "Failed to create '/web/sites/'" . $name . "/web\n";
- exit(1);
+ echo "Failed to create '/web/sites/'" . $name . "/web\n";
+ exit(1);
}
chown('/web/sites/' . $name . '/logs', "nginx");
@@ -53,7 +52,7 @@ chown('/web/sites/' . $name . '/logs', "nginx");
echo "Complete\n";
if (!file_put_contents("/web/etc/nginx/" . $name . ".conf", $conf)) {
- echo "Failed to write nginx conf\n";
+ echo "Failed to write nginx conf\n";
}
chown('/web/etc/nginx/' . $name . ".conf", "nginx");
diff --git a/scripts/run.php b/scripts/run.php
new file mode 100644
index 0000000..3b4de6e
--- /dev/null
+++ b/scripts/run.php
@@ -0,0 +1,95 @@
+<?php
+
+ini_set("display_errors", 1);
+ini_set("display_startup_errors", 1);
+error_reporting(E_ALL);
+
+// Pull in bootstrap
+require(realpath(dirname(__FILE__) . "/../bootstrap.php"));
+
+// Set up siteroot
+define('DIPPER_ROOT', realpath(dirname(__FILE__) . "/../"));
+
+// Handle options
+$options = getopt('d:n:');
+
+if (!array_key_exists('d', $options)) {
+ finish("please provide a domain (-d)");
+}
+
+if (!array_key_exists('n', $options)) {
+ finish("please provide a name (-n)");
+}
+
+/**
+ * Exit application with optional mesage
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $message [description]
+ */
+function finish($message)
+{
+ if ($message) {
+ message($message);
+ exit();
+ }
+}
+
+/**
+ * Echo a message
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $message [description]
+ */
+function message($message)
+{
+ echo $message . PHP_EOL;
+}
+//
+// $domain = $options['d'];
+// $name = $options['n'];
+//
+// $conf = include_once('nginx.php');
+//
+// $conf = sprintf($conf[0], $domain, $name, $name, $name, $name, $name);
+//
+// echo "Making directory structure\n";
+//
+// if (!mkdir('/web/sites/' . $name)) {
+// echo "Failed to create '/web/sites/'" . $name . "\n";
+// exit(1);
+// }
+//
+// chown('/web/sites/' . $name, "nginx");
+//
+// if (!mkdir('/web/sites/' . $name . '/logs')) {
+// echo "Failed to create '/web/sites/'" . $name . "/logs\n";
+// exit(1);
+// }
+//
+// chown('/web/sites/' . $name . '/logs', "nginx");
+//
+//
+// if (!mkdir('/web/sites/' . $name . '/web')) {
+// echo "Failed to create '/web/sites/'" . $name . "/web\n";
+// exit(1);
+// }
+//
+// chown('/web/sites/' . $name . '/logs', "nginx");
+//
+// echo "Complete\n";
+//
+// if (!file_put_contents("/web/etc/nginx/" . $name . ".conf", $conf)) {
+// echo "Failed to write nginx conf\n";
+// }
+//
+// chown('/web/etc/nginx/' . $name . ".conf", "nginx");
+//
+// touch('/web/sites/' . $name . '/logs/' . $name . '.access_log');
+// chown('/web/sites/' . $name . '/logs/' . $name . '.access_log', "nginx");
+//
+// touch('/web/sites/' . $name . '/logs/' . $name . '.error_log');
+// chown('/web/sites/' . $name . '/logs/' . $name . '.error_log', "nginx");
+//
+// touch('/web/sites/' . $name . '/web/index.php');
+// chown('/web/sites/' . $name . '/web/index.php', "nginx");
diff --git a/scripts/test.php b/scripts/test.php
new file mode 100644
index 0000000..83d8c5a
--- /dev/null
+++ b/scripts/test.php
@@ -0,0 +1,13 @@
+<?php
+
+ini_set("display_errors", 1);
+ini_set("display_startup_errors", 1);
+error_reporting(E_ALL);
+
+// Pull in bootstrap
+require(realpath(dirname(__FILE__) . "/../bootstrap.php"));
+
+// Set up siteroot
+define('DIPPER_ROOT', realpath(dirname(__FILE__) . "/../"));
+
+new App\Script\Console;
diff --git a/src/Filesystem/Create.php b/src/Filesystem/Create.php
new file mode 100644
index 0000000..a1891db
--- /dev/null
+++ b/src/Filesystem/Create.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Filesystem;
+
+abstract class Create
+{
+ protected $filename;
+ protected $thing;
+
+ public function __construct(string $filename)
+ {
+ $this->filename = $filename;
+
+ if (!is_writable(dirname($filename))) {
+ throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $filename);
+ }
+ }
+
+ abstract public function excecute();
+}
diff --git a/src/Filesystem/CreateDirectory.php b/src/Filesystem/CreateDirectory.php
new file mode 100644
index 0000000..0c45c6c
--- /dev/null
+++ b/src/Filesystem/CreateDirectory.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Filesystem;
+
+use App\Filesystem\Create;
+
+class CreateDirectory extends Create
+{
+ protected $filename;
+ protected $thing = "directory";
+
+ public function __construct(string $filename)
+ {
+ parent::__construct($filename);
+
+ if (file_exists($filename)) {
+ throw new \Exception('Directory already exists at: ' . $filename);
+ }
+ }
+
+ public function excecute()
+ {
+ echo "execute";
+ }
+}
diff --git a/src/Filesystem/CreateFile.php b/src/Filesystem/CreateFile.php
new file mode 100644
index 0000000..f41d4b9
--- /dev/null
+++ b/src/Filesystem/CreateFile.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Filesystem;
+
+use App\Filesystem\Create;
+
+class CreateFile extends Create
+{
+ protected $filename;
+ protected $thing = "file";
+
+ public function __construct(string $filename)
+ {
+ parent::__construct($filename);
+
+ if (file_exists($filename)) {
+ throw new \Exception('File already exists at: ' . $filename);
+ }
+ }
+
+ public function excecute()
+ {
+ echo "execute";
+ }
+}
diff --git a/src/Script/Command/Site.php b/src/Script/Command/Site.php
new file mode 100644
index 0000000..8a6a8e7
--- /dev/null
+++ b/src/Script/Command/Site.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace App\Script\Command;
+
+use Symfony\Component\Console\Command\Command as SyCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Helper\ProgressBar;
+use App\Filesystem\CreateFile;
+use App\Filesystem\CreateDirectory;
+
+class Site extends SyCommand
+{
+ protected function configure()
+ {
+ $this
+ ->addArgument('name', InputArgument::REQUIRED, 'The name of the new site.');
+
+ $this
+ ->addArgument('domain', InputArgument::REQUIRED, 'The domain name of the new site.');
+
+ $this
+ ->setName('site:create')
+ ->setDescription('Create a new site.')
+ ->setHelp('This command allows you to create a new site.')
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $taskCount = 6;
+ $output->writeln(
+ 'Creating new site with domain: '
+ . $input->getArgument('domain')
+ . ' and name: '
+ . $input->getArgument('name')
+ );
+
+ $progressBar = new ProgressBar($output, $taskCount);
+ $progressBar->setFormatDefinition('custom', ' %current%/%max% -- %message%');
+ $progressBar->setFormat('custom');
+ $progressBar->setMessage('Starting...');
+ $progressBar->start();
+ $progressBar->setMessage('Running pre-flight checks');
+
+ $progressBar->advance();
+ try {
+ $create = new \App\Filesystem\CreateFile(DIPPER_ROOT . '/foo.test');
+ $create = new \App\Filesystem\CreateDirectory(DIPPER_ROOT);
+ sleep(1);
+ } catch (\Exception $e) {
+ $output->writeln('Error with pre-flight checks');
+ $output->writeln($e->getMessage());
+ exit;
+ }
+
+ $progressBar->advance();
+ $progressBar->setMessage('Creating directory structure');
+ sleep(1);
+
+ $progressBar->advance();
+ $progressBar->setMessage('Creating nginx config');
+ sleep(1);
+
+ $progressBar->advance();
+ $progressBar->setMessage('Creating default index.php');
+ sleep(1);
+
+ $progressBar->advance();
+ $progressBar->setMessage('Creating nginx config');
+ sleep(1);
+
+ $progressBar->advance();
+ $progressBar->finish();
+
+ $output->writeln('');
+ $output->writeln('Complete');
+ }
+}
diff --git a/src/Script/Console.php b/src/Script/Console.php
new file mode 100644
index 0000000..926f41f
--- /dev/null
+++ b/src/Script/Console.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Script;
+
+use Symfony\Component\Console\Application;
+use App\Script\Command\Site;
+
+class Console
+{
+ public function __construct()
+ {
+ $application = new Application();
+ $application->add(new Site());
+ $application->run();
+ }
+}