Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ngrok to more easily share progress on dev sites #68

Merged
merged 16 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/Commands/Dns/SetHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class SetHost extends BaseCommand
public function handle(): void
{
if ($this->option('restore')) {
$this->porterLibrary->getMechanic()->restoreNetworking();
app(Config::class)->updateIp('127.0.0.1');
$this->porterLibrary->getMechanic()->removeAlternativeLoopbackAddress();
app(Config::class)->updateIp($this->porterLibrary->getMechanic()->getStandardLoopback());
$this->porter->restart('dns');

return;
}

$this->porterLibrary->getMechanic()->setupNetworking();
app(Config::class)->updateIp($this->porterLibrary->getMechanic()->getHostAddress());
$this->porterLibrary->getMechanic()->addAlternativeLoopbackAddress();
app(Config::class)->updateIp($this->porterLibrary->getMechanic()->getAlternativeLoopback());
$this->porter->restart('dns');
}
}
2 changes: 1 addition & 1 deletion app/Commands/Ngrok/Open.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function handle(): void
public function checkItWillResolveProperly()
{
try {
if ($this->porterLibrary->getMechanic()->isUsingDefaultHostAddress()) {
if ($this->porterLibrary->getMechanic()->isUsingStandardLoopback()) {
$this->info('You need to use an alternative loopback address.');
$this->info('Please run porter dns:set-host and review the documentation here: https://github.com/konsulting/porter#dns');

Expand Down
1 change: 1 addition & 0 deletions app/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Site extends Model
{
protected $guarded = [];
protected $casts = ['secure' => 'boolean'];

/**
* PHP Version.
Expand Down
14 changes: 14 additions & 0 deletions app/PorterLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ public function __construct(FilePublisher $filePublisher, Mechanic $mechanic, $p
$this->mechanic = $mechanic;
}

/**
* Set the Mechanic instance
*
* @param Mechanic $mechanic
*
* @return $this
*/
public function setMechanic(Mechanic $mechanic)
{
$this->mechanic = $mechanic;

return $this;
}

/**
* Return the path for storing container config files.
*
Expand Down
17 changes: 17 additions & 0 deletions app/Support/Console/DockerCompose/NullCliCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Support\Console\DockerCompose;


class NullCliCommand extends CliCommand
{
/**
* Execute the command.
*
* @return string|null
*/
public function perform()
{
return null;
}
}
54 changes: 10 additions & 44 deletions app/Support/Mechanics/MacOs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class MacOs extends Untrained
{
/** @var string $hostAddress Address for Host */
protected $hostAddress = '10.200.10.1';
/** @var string Alternative Loopback Address */
protected $alternativeLoopback = '10.200.10.1';

/**
* Trust the given root certificate file in the Keychain.
Expand Down Expand Up @@ -63,71 +63,37 @@ public function flushDns()
}

/**
* Set up networking for Mac.
* Add the alternative loopback address to the system.
*
* Add a loopback alias to 10.200.10.1. This is then used as the IP for DNS resolution, otherwise
* we get weird results when trying to access services hosted in docker (since they resolve
* 127.0.0.1 to the requesting container).
*
* @return void
*/
public function setupNetworking()
public function addAlternativeLoopbackAddress()
{
$this->consoleWriter->info("Adding loopback alias to {$this->hostAddress}/24. Please provide your sudo password.");
$this->consoleWriter->info("Adding loopback alias to {$this->alternativeLoopback}/24. Please provide your sudo password.");

$command = "sudo ifconfig lo0 alias {$this->hostAddress}/24";
$command = "sudo ifconfig lo0 alias {$this->alternativeLoopback}/24";

$this->cli->passthru($command);
}

/**
* Restore networking on Mac.
* Remove the alternative loopback address from the system.
*
* @return void
*/
public function restoreNetworking()
public function removeAlternativeLoopbackAddress()
{
$this->consoleWriter->info("Removing loopback alias to {$this->hostAddress}. Please provide your sudo password.");
$this->consoleWriter->info("Removing loopback alias to {$this->alternativeLoopback}. Please provide your sudo password.");

$command = "sudo ifconfig lo0 -alias {$this->hostAddress}";
$command = "sudo ifconfig lo0 -alias {$this->alternativeLoopback}";

$this->cli->passthru($command);
}

/**
* Return the host IP address in use.
*
* @return string
*/
public function getHostAddress()
{
return $this->hostAddress;
}

/**
* Does a Porter domain resolve to the Host Address.
*
* @throws UnableToRetrieveIP
*
* @return bool
*/
public function isUsingHostAddress()
{
return $this->getPorterDomainIp() === $this->getHostAddress();
}

/**
* Does a Porter domain resolve to 127.0.0.1.
*
* @throws UnableToRetrieveIP
*
* @return bool
*/
public function isUsingDefaultHostAddress()
{
return $this->getPorterDomainIp() === '127.0.0.1';
}

/**
* Determine the working IP for Porter.
*
Expand Down
36 changes: 26 additions & 10 deletions app/Support/Mechanics/Mechanic.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,51 @@ public function getUserHomePath();
public function flushDns();

/**
* Setup networking for Porter.
* Add the alternative loopback address to the system.
*
* @return void
*/
public function setupNetworking();
public function addAlternativeLoopbackAddress();

/**
* Restore networking.
* Remove the alternative loopback address from the system.
*
* @return void
*/
public function restoreNetworking();
public function removeAlternativeLoopbackAddress();

/**
* Get Host IP address.
* Get standard loopback address.
*
* @return string
*/
public function getStandardLoopback();

/**
* Get alternative loopback address.
*
* @return string
*/
public function getHostAddress();
public function getAlternativeLoopback();

/**
* Does a porter domain resolve to the Host Address.
* Does a Porter domain resolve to the standard loopback address.
*
* @return bool
*/
public function isUsingHostAddress();
public function isUsingAlternativeLoopback();

/**
* Does a porter domain resolve to 127.0.0.1.
* Does a Porter domain resolve to the standard loopback address?
*
* @return bool
*/
public function isUsingDefaultHostAddress();
public function isUsingStandardLoopback();

/**
* Determine the working IP for Porter.
*
* @return string
*/
public function getPorterDomainIp();
}
49 changes: 36 additions & 13 deletions app/Support/Mechanics/Untrained.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class Untrained implements Mechanic
/** @var ServerBag */
protected $serverBag;

/** @var string $hostAddress Address for Host */
protected $hostAddress = '127.0.0.1';
/** @var string Standard Loopback Address */
protected $standardLoopback = '127.0.0.1';

/** @var string Alternative Loopback Address */
protected $alternativeLoopback = '127.0.0.1';

/**
* Untrained constructor.
Expand Down Expand Up @@ -94,7 +97,7 @@ protected function iAmNotTrainedTo($activity)
*
* @return void
*/
public function setupNetworking()
public function addAlternativeLoopbackAddress()
{
$this->iAmNotTrainedTo('set up special networking for Porter');
}
Expand All @@ -104,38 +107,58 @@ public function setupNetworking()
*
* @return void
*/
public function restoreNetworking()
public function removeAlternativeLoopbackAddress()
{
$this->iAmNotTrainedTo('restore special networking for Porter');
}

/**
* Get Host IP for Porter.
* Get standard loopback address.
*
* @return string
*/
public function getStandardLoopback()
{
return $this->standardLoopback;
}

/**
* Get alternative loopback address.
*
* @return string
*/
public function getHostAddress()
public function getAlternativeLoopback()
{
return $this->hostAddress;
return $this->alternativeLoopback;
}

/**
* Does a porter domain resolve to the Host Address.
* Does a Porter domain resolve to the standard loopback address.
*
* @return bool
*/
public function isUsingHostAddress()
public function isUsingAlternativeLoopback()
{
$this->iAmNotTrainedTo('determine if we are using the Host Address for Porter');
return $this->getPorterDomainIp() === $this->getAlternativeLoopback();
}

/**
* Does a porter domain resolve to 127.0.0.1.
* Does a Porter domain resolve to the standard loopback address?
*
* @return bool
*/
public function isUsingDefaultHostAddress()
public function isUsingStandardLoopback()
{
return $this->getPorterDomainIp() === $this->getStandardLoopback();
}

/**
* Determine the working IP for Porter.
*
* @return string
*/
public function getPorterDomainIp()
{
$this->iAmNotTrainedTo('determine if we are using the Default Host Address for Porter');
$this->iAmNotTrainedTo('obtain the current IP address for Porter');
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Commands/Browser/OffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OffTest extends BaseTestCase
/** @test */
public function it_turns_the_browser_on()
{
$this->porter->shouldReceive('turnOffService')->with('browser');
$this->porter->shouldReceive('turnOffService')->with('browser')->once();

$this->artisan('browser:off');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Commands/Browser/OnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OnTest extends BaseTestCase
/** @test */
public function it_turns_the_browser_on()
{
$this->porter->shouldReceive('turnOnService')->with('browser');
$this->porter->shouldReceive('turnOnService')->with('browser')->once();

$this->artisan('browser:on');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Commands/MakeFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function it_will_remake_the_files()

factory(Site::class, 2)->create([]);

$this->porter->shouldReceive('isUp')->andReturn(false);
$this->porter->shouldReceive('compose');
$this->porter->shouldReceive('isUp')->once()->andReturn(false);
$this->porter->shouldReceive('compose')->once();

$conf->shouldReceive('build')->twice();
$cert->shouldReceive('build')->with('porter_default')->once();
Expand All @@ -47,8 +47,8 @@ public function it_will_remake_the_files_and_restart_porter()

factory(Site::class, 2)->create([]);

$this->porter->shouldReceive('isUp')->andReturn(true);
$this->porter->shouldReceive('compose');
$this->porter->shouldReceive('isUp')->once()->andReturn(true);
$this->porter->shouldReceive('compose')->once();

$conf->shouldReceive('build')->twice();
$cert->shouldReceive('build')->with('porter_default')->once();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Commands/MySql/OffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OffTest extends BaseTestCase
/** @test */
public function it_turns_the_browser_on()
{
$this->porter->shouldReceive('turnOffService')->with('mysql');
$this->porter->shouldReceive('turnOffService')->with('mysql')->once();

$this->artisan('mysql:off');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Commands/MySql/OnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OnTest extends BaseTestCase
/** @test */
public function it_turns_the_browser_on()
{
$this->porter->shouldReceive('turnOnService')->with('mysql');
$this->porter->shouldReceive('turnOnService')->with('mysql')->once();

$this->artisan('mysql:on');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Commands/MySql/OpenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function it_runs_mysql()
$this->dockerCompose->shouldReceive('runContainer')
->andReturn($command = \Mockery::mock(CliCommand::class));

$command->shouldReceive('append')->andReturn($command)
->shouldReceive('interactive')->andReturn($command)
->shouldReceive('perform');
$command->shouldReceive('append')->andReturn($command)->once();
$command->shouldReceive('interactive')->andReturn($command)->once();
$command->shouldReceive('perform')->once();

$this->artisan('mysql:open');
}
Expand Down
Loading