Skip to content

Commit

Permalink
building out dockerize command
Browse files Browse the repository at this point in the history
  • Loading branch information
stovak committed Jul 9, 2021
1 parent 15f81dc commit efdd421
Show file tree
Hide file tree
Showing 35 changed files with 890 additions and 298 deletions.
2 changes: 1 addition & 1 deletion Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ brew "[email protected]"
brew "git"
brew "bash"
brew "gh"

brew "direnv"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ These packages will install when you install Terminus.
| tag:add | Adds a tag on a site within an organization. ||
| tag:list | Displays the list of tags for a site within an organization. ||
| tag:remove | Removes a tag from a site within an organization. ||
| upstream:info | Displays information about an upstream. | |
| upstream:list | Displays the list of upstreams accessible to the currently | |
| upstream:info | Displays information about an upstream. | |
| upstream:list | Displays the list of upstreams accessible to the currently | |
| | logged-in user. | |
| upstream:updates:apply | Applies upstream updates to a site development environment. ||
| upstream:updates:list | Displays a cached list of new code commits available from | |
| upstream:updates:list | Displays a cached list of new code commits available from | |
| | the upstream for a site development environment. Note: To | |
| | refresh the cache you will need to run | |
| | site:upstream:clear-cache before running this command. | |
| upstream:updates:status | Displays a whether there are updates available from the | |
| upstream:updates:status | Displays a whether there are updates available from the | |
| | upstream for a site environment. | |
| workflow:info:logs | Displays the details of a workflow including Quicksilver ||
| | operation logs. | |
Expand All @@ -244,4 +244,4 @@ These packages will install when you install Terminus.

Testing Legend: ✅ Pass 💩 Bad test 🤮 Exception ❌ Fail️️ ⚠️ Warning ❓ Missing/Not Written

Tests Passing: 4 / 118 ( 114 not written / missing )
Tests Passing: 0 / 118 ( 118 not written / missing )
4 changes: 2 additions & 2 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct()
*/
public function doc($file = null)
{
//TODO: change this to real documentation building from phpdoc
$readme = (string) CommandCoverageReport::factory();
if ($file) {
file_put_contents($file, $readme);
Expand All @@ -61,8 +62,7 @@ public function doc($file = null)
*/
public function coverage($file = null)
{
$readme = CommandCoverageReport::factory()
->getReport('coverage.twig');
$readme = CommandCoverageReport::factory();
if ($file) {
file_put_contents($file, $readme);
$readme = './README.md regenerated.';
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
"bin/t3"
],
"scripts": {
"build": "@phar:build",
"test": "@test:functional",
"phar:build": [
"rm -Rf ./t3",
"vendor/bin/phar-composer.phar build .",
Expand Down Expand Up @@ -142,8 +144,7 @@
"pre-commit": [
"@code:fix",
"@code:lint",
"composer validate --strict",
"composer docs"
"composer validate --strict"
]
},
"config": {
Expand Down
84 changes: 74 additions & 10 deletions docs/TestCoverage.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
# terminus : Pantheon's Command-Line Interface

## ***COTRIBUTING***

We need help with testing. Take a look in `tests/Functional` and any test that's just `$this->fail("figure out how to test");` and feel free to file a pull request against that.

## Status

[![Commit Build](https://github.com/pantheon-systems/terminus/actions/workflows/ci.yml/badge.svg?branch=v3.0)](https://github.com/pantheon-systems/terminus/actions/workflows/ci.yml)

## About

Terminus is Pantheon's Command Line Interface (CLI), providing at least equivalent functionality to the Pantheon's
browser-based Dashboard and easier scripting.

If you would like to contribute, pull requests are welcome!

## The Manual

Our documentation is kept in the Terminus Manual, located here: https://pantheon.io/docs/terminus

## Requirements

| Operating System | Version |
|------------------------|------------|
| MacOS | 10.14+ |
| Ubuntu | Latest LTR |
| Windows + WSL + Ubuntu | TBD |

### Package Manager

- [apt](https://ubuntu.com/server/docs/package-management) for Ubuntu/WinWSL-Ubuntu

- [Homebrew](https://brew.sh) for mac

#### Required Packages

These packages will install when you install Terminus.

- [Composer 2](https://getcomposer.org)

- [PHP](https://www.php.net) (v7.4+)

- [Git](https://help.github.com/articles/set-up-git/)

#### Recommended Packages

- [Drush](http://docs.drush.org/en/master/install/) (Useful to run incompatible-with-Terminus Drush commands)

- [WP-CLI](http://wp-cli.org/) (Useful to run incompatible-with-Terminus WP-CLI commands)


## Installation

### Mac OS:

`> brew tap *** TBD ***`

`> brew install *** TBD ***`

### Ubuntu / WinWSL+Ubuntu:

`*** TBD ***`



| Command | Description | ⚖️ |
Expand Down Expand Up @@ -30,17 +94,17 @@
| | D9 site. | |
| dashboard:view | Displays the URL for the Pantheon Dashboard or opens the ||
| | Dashboard in a browser. | |
| domain:add | Associates a domain with the environment. | |
| domain:dns | Displays recommended DNS settings for the environment. | |
| domain:list | Displays domains associated with the environment. | |
| domain:lookup | Displays site and environment with which a given domain is | |
| domain:add | Associates a domain with the environment. | |
| domain:dns | Displays recommended DNS settings for the environment. | |
| domain:list | Displays domains associated with the environment. | |
| domain:lookup | Displays site and environment with which a given domain is | |
| | associated. Note: Only sites for which the user is | |
| | authorized will appear. | |
| domain:primary:add | Sets a domain associated to the environment as primary, ||
| | causing all traffic to redirect to it. | |
| domain:primary:remove | Removes the primary designation from the primary domain in ||
| | the site and environment. | |
| domain:remove | Disassociates a domain from the environment. | |
| domain:remove | Disassociates a domain from the environment. | |
| env:clear-cache | Clears caches for the environment. ||
| env:clone-content | Clones database/files from one environment to another ||
| | environment. | |
Expand Down Expand Up @@ -75,9 +139,9 @@
| import:files | Imports a file archive to the environment. ||
| import:site | Imports a site archive (code, database, and files) to the ||
| | site. | |
| local:clone | CLone a copy of the site code into | |
| local:clone | CLone a copy of the site code into | |
| | $HOME/pantheon-local-copies | |
| local:commitAndPush | CLone a copy of site code into $HOME/pantheon-local-copies | |
| local:commitAndPush | CLone a copy of site code into $HOME/pantheon-local-copies | |
| local:getLiveDB | Create new backup of your live site db and download to ||
| | $HOME/pantheon-local-copies/{Site}/db | |
| local:getLiveFiles | Create new backup of your live site FILES folder and ||
Expand Down Expand Up @@ -163,11 +227,11 @@
| upstream:list | Displays the list of upstreams accessible to the currently ||
| | logged-in user. | |
| upstream:updates:apply | Applies upstream updates to a site development environment. ||
| upstream:updates:list | Displays a cached list of new code commits available from | |
| upstream:updates:list | Displays a cached list of new code commits available from | |
| | the upstream for a site development environment. Note: To | |
| | refresh the cache you will need to run | |
| | site:upstream:clear-cache before running this command. | |
| upstream:updates:status | Displays a whether there are updates available from the | |
| upstream:updates:status | Displays a whether there are updates available from the | |
| | upstream for a site environment. | |
| workflow:info:logs | Displays the details of a workflow including Quicksilver ||
| | operation logs. | |
Expand All @@ -180,4 +244,4 @@

Testing Legend: ✅ Pass 💩 Bad test 🤮 Exception ❌ Fail️️ ⚠️ Warning ❓ Missing/Not Written

Tests Passing: 34 / 118 ( 34 not written / missing )
Tests Passing: 42 / 118 ( 33 not written / missing )
18 changes: 16 additions & 2 deletions src/Collections/Domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Pantheon\Terminus\Collections;

use Pantheon\Terminus\Exceptions\TerminusException;
use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
use Pantheon\Terminus\Models\Domain;
use Pantheon\Terminus\Request\RequestOperationResult;

/**
* Class Domains
Expand All @@ -27,10 +29,22 @@ class Domains extends EnvironmentOwnedCollection
* @param string $domain Domain to add to environment
* @return array
*/
public function create($domain)
public function create($domain): RequestOperationResult
{
$url = $this->getUrl() . '/' . rawurlencode($domain);
$this->request->request($url, ['method' => 'put',]);
$result = $this->request->request($url, ['method' => 'put']);
if ($result->isError()) {
throw new TerminusException(
'Error trying to add {domain} to {env}: {error}',
[
'domain' => $domain,
'site' => $this->getEnvironment()->getSite(),
'env' => $this->getEnvironment(),
'error' => $result->getStatusCodeReason(),
]
);
}
return $result;
}

/**
Expand Down
21 changes: 15 additions & 6 deletions src/Collections/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Pantheon\Terminus\Collections;

use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
use Pantheon\Terminus\Models\Site;
use Pantheon\Terminus\Models\TerminusModel;
use Pantheon\Terminus\Session\SessionAwareInterface;
Expand Down Expand Up @@ -180,22 +181,25 @@ public function filterByUpstream($upstream_id)
* @return Site
* @throws TerminusException
*/
public function get($id): TerminusModel
public function get($id): ?TerminusModel
{
try {
$uuid = $this->findUUIDByNameOrUUID($id);
$site = $this->models[$uuid] ?? null;
if (!$site instanceof Site) {
$injectionNickname = $id . "-" . \uniqid();
$this->getContainer()->add($injectionNickname, $this->collected_class)
$nickname = 'site-' . $uuid;
$this->getContainer()->add($nickname, $this->collected_class)
->addArguments(
[
(object)['id' => $uuid],
['id' => $uuid, 'collection' => $this]
]
);
$site = $this->getContainer()->get($injectionNickname);
$site = $this->getContainer()->get($nickname);
$site->fetch();
if (!$site->valid()) {
throw new TerminusException("Site is not valid!");
}
$this->models[$uuid] = $site;
}
} catch (\Exception $e) {
Expand Down Expand Up @@ -227,12 +231,17 @@ public function nameIsTaken($name) : bool
*/
protected function findUUIDByName($name): ?string
{

$response = $this->request()->request(
"site-names/$name",
'site-names/' . $name,
['method' => 'get',]
);

return $response['data']->id ?? null;
if ($response->isError()) {
throw new TerminusNotFoundException($response->getData());
}

return $response->getData()->id ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Collections/TerminusCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function filterByRegex($attribute, $regex = '(.*)')
* @return TerminusModel $this->models[$id]
* @throws TerminusNotFoundException
*/
public function get($id): TerminusModel
public function get($id): ?TerminusModel
{
$all = $this->all();
foreach ($this->all() as $member) {
Expand Down
13 changes: 8 additions & 5 deletions src/Collections/Workflows.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function ($workflow) {
public function create($type, array $options = [])
{

$params = isset($options['params']) ? $options['params'] : [];
$params = $options['params'] ?? [];
$results = $this->request()->request(
$this->getUrl(),
[
Expand All @@ -103,15 +103,18 @@ public function create($type, array $options = [])
],
]
);
if ($results['status_code'] <= 199 || $results['status_code'] >= 300) {
throw new TerminusException($results['data']);
if ($results->isError()) {
throw new TerminusException(
"Workflow Creation Failed: {error}",
['error' => $results->getStatusCodeReason()]
);
}
$nickname = \uniqid(__CLASS__ . "-");
$this->getContainer()->add($nickname, $this->collected_class)
->addArguments([
$results['data'],
$results->getData(),
[
'id' => $results['data']->id,
'id' => $results->getData()->id,
'collection' => $this,
'owner' => $this->owner
]
Expand Down
17 changes: 16 additions & 1 deletion src/Commands/Connection/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Consolidation\OutputFormatters\StructuredData\PropertyList;

use Pantheon\Terminus\Commands\TerminusCommand;
use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
use Pantheon\Terminus\Models\Environment;
use Pantheon\Terminus\Site\SiteAwareInterface;
use Pantheon\Terminus\Site\SiteAwareTrait;

Expand Down Expand Up @@ -55,7 +57,20 @@ class InfoCommand extends TerminusCommand implements SiteAwareInterface
*/
public function connectionInfo($site_env)
{
list(, $env) = $this->getSiteEnv($site_env);
[$site, $env] = explode('.', $site_env);
if (empty($site) || empty($env)) {
throw new TerminusNotFoundException(
'The Site and environment must take the form of {site}.{env} followed by the domain name you are adding'
);
}

$env = $this->sites()->get($site)->getEnvironments()->get($env);
if (!$env instanceof Environment) {
throw new TerminusNotFoundException(
'Site/env not found {site}.{env}',
['site' => $site, 'env' => $env]
);
}
return new PropertyList($env->connectionInfo());
}
}
12 changes: 11 additions & 1 deletion src/Commands/D9ify/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,17 @@ protected function updateDestEsLibrariesFromSource()
$repos = $this->sourceDirectory->getComposerObject()->getOriginal()['repositories'];
$composerFile = $this->getDestinationDirectory()->getComposerObject();
foreach ($fileList as $key => $file) {
$package = \json_decode(file_get_contents($file->getRealPath()), true, 10, JSON_THROW_ON_ERROR);
try {
$package = \json_decode(
file_get_contents($file->getRealPath()),
true,
10,
JSON_THROW_ON_ERROR
);
} catch (\JsonException $jsonException) {
continue;
}

$repoString = (string)$package['name'];
if (empty($repoString)) {
$repoString = is_string($package['repository']) ?
Expand Down
Loading

0 comments on commit efdd421

Please sign in to comment.