Skip to content

Commit

Permalink
Merge pull request #46 from richdynamix/release/2.1
Browse files Browse the repository at this point in the history
release/2.1
  • Loading branch information
Steven Richardson committed May 17, 2016
2 parents e482669 + e61ce92 commit c6a956b
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ $ composer global require "richdynamix/magestead"

Make sure to place the `~/.composer/vendor/bin` directory in your PATH so the `magestead` executable can be located by your system.

### Updating

```
$ composer global update "richdynamix/magestead"
```


## Usage

Once installed, the `magestead new` command will start a fresh new development environment in the directory you specify. For instance, `magestead new my-project` will create a directory named `my-project` and start the setup process for your new development environment.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "richdynamix/magestead",
"description": "Magestead CLI - A command line installer for Magestead Vagrant environment",
"description": "Magestead - A command line installer for Magento Vagrant environments",
"license": "MIT",
"require": {
"symfony/console" : "^2.6",
Expand Down
6 changes: 5 additions & 1 deletion magestead
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use Symfony\Component\Console\Application;

define('APP_PATH', __DIR__);

$app = new Application('Magestead CLI', '2.0.4');
$app = new Application('Magestead CLI', '2.1.0');
$app->addCommands(array(
// Project Setup Command
new Magestead\Command\NewCommand(),
Expand All @@ -33,6 +33,10 @@ $app->addCommands(array(
new Magestead\Command\VM\ResumeCommand(),
new Magestead\Command\VM\RunCommand(),

// Log Commands
new Magestead\Command\Log\ViewCommand(),
new Magestead\Command\Log\StreamCommand(),

// Cache Commands
new Magestead\Command\Cache\CleanCommand(),
new Magestead\Command\Cache\DisableCommand(),
Expand Down
3 changes: 3 additions & 0 deletions provision/puphpet/magestead/magento/configure-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ block="server {
access_log off;
}
access_log /var/log/nginx/$BASE_URL-access.log;
error_log /var/log/nginx/$BASE_URL-error.log error;
## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
Expand Down
3 changes: 2 additions & 1 deletion provision/puphpet/magestead/magento/stubs/composer.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"require": {
"aydin-hassan/magento-core-composer-installer" : "~1.0",
"magento/magento" : "1.9.2.2",
"magento-hackathon/magento-composer-installer": "3.0.*"
"magento-hackathon/magento-composer-installer": "3.0.*",
"inchoo/php7": "1.0.*"
},
"authors": [
{
Expand Down
3 changes: 3 additions & 0 deletions provision/puphpet/magestead/magento2/configure-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ block="server {
autoindex off;
charset off;
access_log /var/log/nginx/$BASE_URL-access.log;
error_log /var/log/nginx/$BASE_URL-error.log error;
location / {
try_files \$uri \$uri/ /index.php?\$args;
}
Expand Down
79 changes: 79 additions & 0 deletions src/Magestead/Command/Log/StreamCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php namespace Magestead\Command\Log;

use Magestead\Command\ProcessCommand;
use Magestead\Helper\Config;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class StreamCommand
* @package Magestead\Command\Redis
*/
class StreamCommand extends Command
{
protected $_config;
protected $_projectPath;

/**
* Configure the stream command
*/
protected function configure()
{
$this->_projectPath = getcwd();
$this->setName("log:stream");
$this->setDescription("Stream a specific server log");
$this->addArgument('log', InputArgument::REQUIRED, 'access or error');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return ProcessCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$log = $input->getArgument('log');

$output->writeln('<info>Streaming '. ucwords($log) . ' Log</info>');
$command = $this->getCommand(new Config($output), $log);
if (!$command) {
return $output->writeln('<error>Command not available for this application</error>');
}

$pCommand = "vagrant ssh -c '". $command ."'";
return new ProcessCommand($pCommand, $this->_projectPath, $output);
}

/**
* @param Config $config
* @param $log
* @return string
*/
private function getCommand(Config $config, $log)
{
$server = $config->_config['magestead']['server'];
$os = $config->_config['magestead']['os'];

$location = $this->getLogLocation($server, $os);
$command = 'tail -f /var/log/' . $location . '/' . $config->base_url . '-' . $log . '.log';

return $command;
}

/**
* @param $server
* @param $os
* @return string
*/
private function getLogLocation($server, $os)
{
$location = 'nginx';
if ($server != 'nginx') {
$location = ($os == 'ubuntu14') ? 'apache2' : 'httpd';
}

return $location;
}
}
79 changes: 79 additions & 0 deletions src/Magestead/Command/Log/ViewCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php namespace Magestead\Command\Log;

use Magestead\Command\ProcessCommand;
use Magestead\Helper\Config;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class ViewCommand
* @package Magestead\Command\Redis
*/
class ViewCommand extends Command
{
protected $_config;
protected $_projectPath;

/**
* Configure the view command
*/
protected function configure()
{
$this->_projectPath = getcwd();
$this->setName("log:view");
$this->setDescription("View a specific server log");
$this->addArgument('log', InputArgument::REQUIRED, 'access or error');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return ProcessCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$log = $input->getArgument('log');

$output->writeln('<info>Viewing '. ucwords($log) . ' Log</info>');
$command = $this->getCommand(new Config($output), $log);
if (!$command) {
return $output->writeln('<error>Command not available for this application</error>');
}

$pCommand = "vagrant ssh -c '". $command ."'";
return new ProcessCommand($pCommand, $this->_projectPath, $output);
}

/**
* @param Config $config
* @param $log
* @return string
*/
private function getCommand(Config $config, $log)
{
$server = $config->_config['magestead']['server'];
$os = $config->_config['magestead']['os'];

$location = $this->getLogLocation($server, $os);
$command = 'cat /var/log/' . $location . '/' . $config->base_url . '-' . $log . '.log';

return $command;
}

/**
* @param $server
* @param $os
* @return string
*/
private function getLogLocation($server, $os)
{
$location = 'nginx';
if ($server != 'nginx') {
$location = ($os == 'ubuntu14') ? 'apache2' : 'httpd';
}

return $location;
}
}
6 changes: 4 additions & 2 deletions src/Magestead/Command/NewCommand.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php namespace Magestead\Command;

use Magestead\Exceptions\ExistingProjectException;
use Magestead\Helper\Options;
use Magestead\Service\UsageApi;
use Magestead\Installers\Project;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Dumper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Magestead\Exceptions\ExistingProjectException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Yaml\Exception\ParseException;
Expand All @@ -32,7 +33,6 @@ protected function configure()
$this->addArgument('project', InputArgument::REQUIRED, 'Name your project directory');
}


/**
* @param InputInterface $input
* @param OutputInterface $output
Expand Down Expand Up @@ -153,6 +153,8 @@ protected function setupProject(OutputInterface $output, $options)
$provisionFolder = $this->_basePath . "provision";
$this->copyConfigFiles($provisionFolder, $this->_projectPath, $output);
$this->configureProject($options->getAllOptions(), $output);

(new UsageApi($options->getAllOptions()))->send();
}

/**
Expand Down
16 changes: 7 additions & 9 deletions src/Magestead/Helper/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ protected function setVagrantSettings($helper, InputInterface $input, OutputInte
protected function setApplicationSettings($helper, InputInterface $input, OutputInterface $output, $project)
{
$output->writeln('<comment>Lets configure your project\'s application</comment>');
if ($this->_phpVer !== '70') {
$appQuestion = new ChoiceQuestion(
"Which application do you want to install?",
['Magento', 'Magento2'],
0
);

$this->_app = strtolower($helper->ask($input, $output, $appQuestion));
}
$appQuestion = new ChoiceQuestion(
"Which application do you want to install?",
['Magento', 'Magento2'],
0
);

$this->_app = strtolower($helper->ask($input, $output, $appQuestion));

$baseUrlQuestion = new Question("Enter your application's base_url ($project.dev): ", $project.'.dev');
$this->_baseUrl = strtolower($helper->ask($input, $output, $baseUrlQuestion));
Expand Down
70 changes: 70 additions & 0 deletions src/Magestead/Service/UsageApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php namespace Magestead\Service;

/**
* Class UsageApi
* @package Magestead\Service
*/
class UsageApi
{
/**
* @var string
*/
protected $_apiUrl = "http://api.magestead.com/v1/usage";
// protected $_apiUrl = "http://magestead-api.app/v1/usage";

/**
* @var array
*/
protected $_params = [];

/**
* UsageApi constructor.
* @param $data
*/
public function __construct($data)
{
$this->_params['os_type'] = urlencode($data['os']);
$this->_params['server_type'] = urlencode($data['server']);
$this->_params['php_version'] = urlencode($data['phpver']);
$this->_params['application_version'] = urlencode($data['app']);
$this->_params['vm_memory_limit'] = urlencode($data['memory_limit']);
$this->_params['vm_cpu_count'] = urlencode($data['cpus']);
$this->_params['ip_address'] = urlencode($data['ip_address']);
$this->_params['box'] = urlencode($data['box']);
$this->_params['locale'] = urlencode($data['locale']);
$this->_params['default_currency'] = urlencode($data['default_currency']);
}

/**
*
*/
public function send()
{
$fields_string = $this->getFieldsString();

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $this->_apiUrl);
curl_setopt($ch,CURLOPT_POST, count($this->_params));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

}

/**
* @return string
*/
protected function getFieldsString()
{
$fields_string = '';
foreach ($this->_params as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
return $fields_string;
}
}

0 comments on commit c6a956b

Please sign in to comment.