Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  update the doc
  replace travis by github ci
  add psalm
  CS
  update deps
  CS
  rename __toString to toString
  require php 7.4
  exception must extend throwable
  remove useless script
  • Loading branch information
Baptouuuu committed Mar 1, 2020
2 parents 867ace6 + 26e7a86 commit 55d9cd7
Show file tree
Hide file tree
Showing 30 changed files with 352 additions and 287 deletions.
3 changes: 0 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/fixtures export-ignore
/tests export-ignore
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on: [push]

jobs:
phpunit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['7.4']
name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }}'
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: xdebug
ini-values: xdebug.max_nesting_level=2048
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
psalm:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4']
name: 'Psalm - PHP/${{ matrix.php-version }}'
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: Psalm
run: vendor/bin/psalm --shepherd
6 changes: 0 additions & 6 deletions .scrutinizer.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Ark

| `develop` |
|-----------|
| [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Innmind/Ark/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Http/?branch=develop) |
| [![Code Coverage](https://scrutinizer-ci.com/g/Innmind/Ark/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Http/?branch=develop) |
| [![Build Status](https://scrutinizer-ci.com/g/Innmind/Ark/badges/build.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Http/build-status/develop) |
[![Build Status](https://github.com/Innmind/Ark/workflows/CI/badge.svg)](https://github.com/Innmind/Ark/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/Innmind/Ark/branch/develop/graph/badge.svg)](https://codecov.io/gh/Innmind/Ark)
[![Type Coverage](https://shepherd.dev/github/Innmind/Ark/coverage.svg)](https://shepherd.dev/github/Innmind/Ark)

The ark is a simple tool to spinup new servers and trash the ones in service in your infrastructure.

Expand Down Expand Up @@ -55,11 +53,11 @@ $ark = scaleway(
$os->process(),
new Local(
$os->control()->processes(),
new Path('/home/{serverUser}/.ssh')
Path::of('/home/{serverUser}/.ssh'),
),
new User\Id('your user uuid'),
new Organization\Id('the organization uuid you want to create servers in'),
new Image\Id('the image uuid you want to build')
new Image\Id('the image uuid you want to build'),
);

$installation = $ark->forge()->new();
Expand All @@ -84,9 +82,9 @@ $ark = ovh(
new Api(/* args */),
new Local(
$os->control()->processes(),
new Path('/home/{serverUser}/.ssh')
Path::of('/home/{serverUser}/.ssh'),
),
$os
$os,
);

$installation = $ark->forge()->new();
Expand Down
19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
"issues": "http://github.com/Innmind/Ark/issues"
},
"require": {
"php": "~7.2",
"innmind/url": "^2.0",
"innmind/immutable": "^2.8",
"php": "~7.4",
"innmind/url": "~3.3",
"innmind/immutable": "~3.5",
"ovh/ovh": "^2.0",
"innmind/server-control": "^2.3",
"innmind/scaleway-sdk": "^1.0",
"innmind/operating-system": "^1.6",
"innmind/scaleway-sdk": "~2.0",
"innmind/operating-system": "~2.0",
"ramsey/uuid": "^3.8",
"innmind/ssh-key-provider": "^1.0"
"innmind/ssh-key-provider": "~2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -39,9 +38,7 @@
},
"require-dev": {
"phpunit/phpunit": "~8.0",
"giorgiosironi/eris": "^0.11.0"
},
"scripts": {
"test": "vendor/bin/phpunit --colors=always"
"giorgiosironi/eris": "^0.11.0",
"vimeo/psalm": "^3.9"
}
}
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
4 changes: 2 additions & 2 deletions src/Ark.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

final class Ark
{
private $forge;
private $array;
private Forge $forge;
private InstallationArray $array;

public function __construct(Forge $forge, InstallationArray $array)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace Innmind\Ark\Exception;

interface Exception
interface Exception extends \Throwable
{
}
24 changes: 14 additions & 10 deletions src/Forge/Ovh.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
};
use Innmind\Url\Url;
use Innmind\Immutable\Set;
use function Innmind\Immutable\unwrap;
use Ovh\Api;

final class Ovh implements Forge
{
private $api;
private $available;
private $bootstrap;
private $dispose;
private Api $api;
private Available $available;
private Bootstrap $bootstrap;
private Dispose $dispose;

public function __construct(
Api $api,
Expand All @@ -41,22 +42,25 @@ public function new(): Installation
//iterate over existing vps and filter the ones "available" as the api
//doesn't allow to order a new vps on demand, so instead we look for an
//existing purchased vps that's available
$names = Set::of('string', ...$this->api->get('/vps'))->filter(function(string $vps): bool {
/** @var list<string> */
$vps = $this->api->get('/vps');
$names = Set::strings(...$vps)->filter(function(string $vps): bool {
return ($this->available)(new Name($vps));
});
$names = unwrap($names);

//attempt to bootstrap a new server, if one fails it will attempt to use
//the next available one
while ($names->valid()) {
while (\is_string(\current($names))) {
try {
($this->bootstrap)(new Name($names->current()));
($this->bootstrap)(new Name(\current($names)));

return new Installation(
new Name($names->current()),
Url::fromString($names->current())
new Name(\current($names)),
Url::of(\current($names)),
);
} catch (RuntimeException $e) {
$names->next();
\next($names);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Forge/Ovh/Available/Consensus.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

final class Consensus implements Available
{
private $strategies;
private Sequence $strategies;

public function __construct(Available ...$strategies)
{
$this->strategies = Sequence::of(...$strategies);
$this->strategies = Sequence::of(Available::class, ...$strategies);
}

public function __invoke(Name $name): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Forge/Ovh/Available/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

final class State implements Available
{
private $api;
private Api $api;

public function __construct(Api $api)
{
Expand All @@ -21,7 +21,7 @@ public function __construct(Api $api)
public function __invoke(Name $name): bool
{
try {
return $this->api->get('/vps/'.$name)['state'] === 'stopped';
return $this->api->get('/vps/'.$name->toString())['state'] === 'stopped';
} catch (\Throwable $e) {
return false;
}
Expand Down
24 changes: 14 additions & 10 deletions src/Forge/Ovh/Bootstrap/Reinstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
};
use Innmind\SshKeyProvider\Provide;
use Innmind\OperatingSystem\CurrentProcess;
use function Innmind\Immutable\first;
use Ovh\Api;

final class Reinstall implements Bootstrap
{
private $api;
private $provide;
private $wait;
private Api $api;
private Provide $provide;
private WaitTaskCompletion $wait;

public function __construct(
Api $api,
Expand All @@ -38,25 +39,28 @@ public function __invoke(Name $name): void
throw new BootstrapFailed('A ssh key is required');
}

$sshKey = (string) $sshKeys->current();
$sshKey = first($sshKeys)->toString();

$this->api->post('/me/sshKey', [
'key' => $sshKey,
'keyName' => (string) $name,
'keyName' => $name->toString(),
]);
$template = $this->api->get('/vps/'.$name.'/distribution')['id'];
/** @var array{id: int, bitFormat: int, name: string, locale: string, availableLanguage: list<string>, distribution: string} */
$distribution = $this->api->get('/vps/'.$name->toString().'/distribution');
$template = $distribution['id'];
try {
$task = $this->api->post('/vps/'.$name.'/reinstall', [
/** @var array{id: int, progress: int, type: string, state: string} */
$task = $this->api->post('/vps/'.$name->toString().'/reinstall', [
'doNotSendPassword' => true,
'templateId' => $template,
'sshKey' => [(string) $name],
'sshKey' => [$name->toString()],
]);

($this->wait)($name, $task['id']);
} catch (OvhTaskFailed $e) {
throw new BootstrapFailed((string) $name, 0, $e);
throw new BootstrapFailed($name->toString(), 0, $e);
} finally {
$this->api->delete('/me/sshKey/'.$name);
$this->api->delete('/me/sshKey/'.$name->toString());
}
}
}
3 changes: 2 additions & 1 deletion src/Forge/Ovh/Dispose/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

final class All implements Dispose
{
private $strategies;
/** @var list<Dispose> */
private array $strategies;

public function __construct(Dispose ...$strategies)
{
Expand Down
9 changes: 5 additions & 4 deletions src/Forge/Ovh/Dispose/Stop.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

final class Stop implements Dispose
{
private $api;
private $wait;
private Api $api;
private WaitTaskCompletion $wait;

public function __construct(Api $api, CurrentProcess $process)
{
Expand All @@ -26,12 +26,13 @@ public function __construct(Api $api, CurrentProcess $process)

public function __invoke(Name $name): void
{
$task = $this->api->post('/vps/'.$name.'/stop');
/** @var array{id: int, progress: int, type: string, state: string} */
$task = $this->api->post('/vps/'.$name->toString().'/stop');

try {
($this->wait)($name, $task['id']);
} catch (OvhTaskFailed $e) {
throw new InstallationDisposalFailed((string) $name, 0, $e);
throw new InstallationDisposalFailed($name->toString(), 0, $e);
}
}
}

0 comments on commit 55d9cd7

Please sign in to comment.