Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dsxack authored and Smotrov Dmitriy committed Jun 26, 2017
0 parents commit d40a43c
Show file tree
Hide file tree
Showing 22 changed files with 954 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Created by .ignore support plugin (hsz.mobi)
.DS_store
.idea/
vendor/
stub/
composer.phar
config.yml
composer.lock
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: php

php:
- '5.3'
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.1'

before_script:
- composer install

script:
phpunit
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Deployment assistant
[![Build Status](https://travis-ci.org/worksolutions/deployment-assistant.svg?branch=master)](https://travis-ci.org/worksolutions/deployment-assistant)

[Russian](README.ru.md)

Assistant safe deployment on production server.


## Install

Assistant is an executable phar-archive.
To install, enter the command:

```bash
php -r "copy('http://dep.worksolutions.ru/dep.phar', 'dep.phar');"
chmod +x ./dep.phar
```

Assistant phar-archive is downloaded and saved in your current directory.

Assistant supports php versions from 5.3 to 7.1


## Usage

### Deploy

Deployment command will check the state of the production and remote branches.
After a successful check, you will receive the changes from the remote branch to the production.


Syntax for the deployment command is:

```bash
php ./dep.phar deploy [<remote>] [<branch>]
```

To start deploy, type:

```bash
php ./dep.phar deploy
```

By default, changes will pull from the remote branch `origin/master`,
to change it is required to specify from which branch of the remote source
you need to pull the changes:

```bash
php ./dep.phar deploy origin master
```

### Update

Update command will check if there is a new version of the helper and,
if there is one, will update it.

```bash
php ./dep.phar self-update
```

## Contributing

To make a contribution to the assistant - send pool-requests.
59 changes: 59 additions & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Deployment assistant
[![Build Status](https://travis-ci.org/worksolutions/deployment-assistant.svg?branch=master)](https://travis-ci.org/worksolutions/deployment-assistant)

[English](README.md)

Помощник безопасного развертывания с git на боевом сервере.

## Установка

Помощник является исполняемым phar-архивом.
Для установки введите команду:

```bash
php -r "copy('http://dep.worksolutions.ru/dep.phar', 'dep.phar');"
chmod +x ./dep.phar
```

Phar-архив помощника скачается и сохранится в вашей текущей директории.

Помощник поддерживает версии php от 5.3 до 7.1

## Использование

### Развертывание

Команда развертывания проверит состояние локальной и удаленной веток.
После успешной проверки выполнит получение изменений из удаленной в локальную ветку.

Синтаксис команды развертывания:

```bash
php ./dep.phar deploy [<remote>] [<branch>]
```

Для запуска процесса развертывания введите:

```bash
php ./dep.phar deploy
```

По умолчанию изменения вытянутся из удаленной ветки `origin/master`,
чтобы изменить требуется указать из какой ветки удаленного источника
нужно вытянуть изменения:

```bash
php ./dep.phar deploy origin master
```

### Обновление

Команда обновления проверит есть ли новая версия помощника и, если есть – обновит его.

```bash
php ./dep.phar self-update
```

## Внести вклад

Чтобы внести вклад в инструмент – используйте пул-реквесты.
6 changes: 6 additions & 0 deletions bin/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env php
<?php
require __DIR__ . '/../vendor/autoload.php';

$app = new \WS\DeploymentAssistant\Application();
$app->run();
15 changes: 15 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"blacklist": [],
"directories": [
"src",
"bin",
"vendor"
],
"files": [
"config.yml"
],
"main": "bin/main.php",
"output": "build/dep.phar",
"chmod": "0755",
"stub": true
}
2 changes: 2 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"autoload": {
"psr-4": {
"WS\\DeploymentAssistant\\": "src",
"WS\\DeploymentAssistant\\Tests\\": "tests/src"
}
},
"require": {
"roave/security-advisories": "dev-master",
"symfony/console": "^2.8",
"symfony/process": "^2.8",
"symfony/config": "^2.8",
"symfony/yaml": "^2.8",
"symfony/event-dispatcher": "^2.8",
"sentry/sentry": "^1.7"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
}
}
6 changes: 6 additions & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
update:
phar_url: "http://host/dep.phar"
sum_url: "http://host/dep.md5.txt"

sentry:
dsn: "https://key:[email protected]/project"
19 changes: 19 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Deploy Assistant Test Suite">
<directory>./tests/src/</directory>
</testsuite>
</testsuites>
</phpunit>
69 changes: 69 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace WS\DeploymentAssistant;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Yaml\Yaml;
use WS\DeploymentAssistant\Commands\DeployCommand;
use WS\DeploymentAssistant\Commands\SelfUpdateCommand;
use WS\DeploymentAssistant\Helpers\GitHelper;
use WS\DeploymentAssistant\Helpers\SentryHelper;
use WS\DeploymentAssistant\Helpers\VersionHelper;
use WS\DeploymentAssistant\Listeners\SentryExceptionListener;

/**
* Class Application
* @package WS\DeployAssistant
*/
class Application extends \Symfony\Component\Console\Application
{
public function __construct($exceptionHandling = true, $version = 'UNKNOWN')
{
parent::__construct('Deployment assistant', $version);

$config = $this->getConfig();

$this->getHelperSet()->set(new GitHelper());
$this->getHelperSet()->set(new SentryHelper($config['sentry']['dsn']));
$this->getHelperSet()->set(new VersionHelper(
$config['update']['phar_url'],
$config['update']['sum_url']));

$this->addCommands(array(
new DeployCommand(),
new SelfUpdateCommand()
));

if ($exceptionHandling) {
$dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::EXCEPTION, new SentryExceptionListener());

$this->setDispatcher($dispatcher);
}
}

/**
* @return array
* @throws \Symfony\Component\Yaml\Exception\ParseException
*/
private function getConfig()
{
$path = dirname(__DIR__) . '/config.yml';
if (!file_exists($path)) {
$path = dirname(__DIR__) . '/config.example.yml';
}

$config = Yaml::parse(
file_get_contents($path)
);

$processor = new Processor();
$configuration = new Configuration();
return $processor->processConfiguration(
$configuration,
array($config)
);
}

}
Loading

0 comments on commit d40a43c

Please sign in to comment.