Skip to content

Commit

Permalink
Merge branch 'release/3.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
stmh committed Oct 14, 2019
2 parents cfffc37 + d260a3a commit 998c6a6
Show file tree
Hide file tree
Showing 30 changed files with 1,289 additions and 251 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
/bin/phpunit
/build/phabalicious.phar
/docs/site
/tests/tmp
node_modules
docs/.vuepress/dist
15 changes: 15 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 3.2.0 / 2019-10-14

### New:

* `rootFolder` is set by default now to the folder where the fabfile is located.
* All context variables are exposed as replacement patterns for using in scripts.
* new method `artifacts--git` to build an artifact and push it to a git repository, see new documentation about artifacts.
* Update documentation regarding the new artifact workflow

### Changed

* Refactored and renamed method `ftp-sync` to `artifacts--ftp` in preparation of artifacts--git. Be aware that you might need to change existing configuration!

### New

## 3.1.0 / 2019-09-27

### New
Expand Down
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
"/scripts.html",
"/app-scaffold.html",
"/app-create-destroy.html",
"/deploying-artifacts.html",
"/passwords.html",
"/contribute.html",
"/Changelog.html"
Expand Down
36 changes: 30 additions & 6 deletions docs/app-create-destroy.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Phabalicious can create or delete a complete app with two commands:
* `phab --config=<config> app:create --copy-from=<other-config>`
* `phab --config=<config> app:destroy`

Both commands executes a list of stages, which can be influenced via configuration
Both commands executes a list of stages, which can be influenced via configuration. Every method can react to the different stages and run some tasks if needed.

## the standard stages

Expand All @@ -19,18 +19,34 @@ appStages:
- stage: spinUp
- stage: installDependencies
- stage: install
createCode:
- stage: installCode
- stage: installDependencies
deploy:
- stage: spinUp
destroy:
- stage: spinDown
- stage: deleteContainers
# ftpSync and gitSync are only used for deploying artifacts.
ftpSync:
- stage: installCode
- stage: installDependencies
- stage: runDeployScript
gitSync:
useLocalRepository:
- stage: installDependencies
- stage: getSourceCommitInfo
- stage: pullTargetRepository
- stage: copyFilesToTargetRepository
- stage: runDeployScript
- stage: pushToTargetRepository
pullTargetRepository:
- stage: installCode
- stage: installDependencies
- stage: getSourceCommitInfo
- stage: pullTargetRepository
- stage: copyFilesToTargetRepository
- stage: runDeployScript
- stage: pushToTargetRepository
```
`createCode` is only used by the `ftp-sync`-method, to create a complete code version of an app.

## Creating a new app
Run the phab-command as usual. If you want to copy from an existing installation, add the `--copy-from`-option.
Expand Down Expand Up @@ -62,3 +78,11 @@ phab --config=some-config --blueprint=feature/<some-feature> create:app
```

Will create a new app from a blueprinted config.

## Customizing via scripts

* You can add custom scripts to your host-configuration which will be run before a stage is entered or after a stage is finished. They follow a naming-convention:
* `appCreate<NameOfStage>Before`
* `appCreate<NameOfStage>Finished`

e.g. `appCreateInstallDependenciesBefore` or `appCreateSpinDownFinished`. All context variables are exposed to scripts as `context.data.*` or `context.results.*`
3 changes: 2 additions & 1 deletion docs/available-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ After a successfull deployment the `reset`-task will be run.

* `git` will deploy to the latest commit for the given branch defined in the host-configuration. Submodules will be synced, and updated.
* `platform` will push the current branch to the `platform` remote, which will start the deployment-process on platform.sh
* `ftp-sync` will create a copy of the app in a temporary folder and syncs this folder with the help of `lftp` with a remote-ftp-server.
* `artifacts--ftpc` will create a copy of the app in a temporary folder and syncs this folder with the help of `lftp` with a remote ftp-server.
* `artifacts--git` will create a copy of the app in a temporary folder and push it to another git-repository

**Examples:**

Expand Down
21 changes: 16 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ List here all needed methods for that type of project. Available methods are:
* `composer` for composer support
* `drupalconsole` for drupal-concole support
* `platform` for deploying to platform.sh
* `ftp-sync` to deploy to a ftp-server
* `artifacts--ftp to deploy to a ftp-server
* `artifacts--git to deploy an artifact to a git repository

**Example for drupal 7**

Expand Down Expand Up @@ -88,7 +89,6 @@ hosts:
backupFolder: /var/www/backups
supportsInstalls: true|false
supportsCopyFrom: true|false
type: dev
branch: develop
docker:
...
Expand Down Expand Up @@ -124,6 +124,7 @@ This will print all host configuration for the host `staging`.
* `supportsCopyFrom`, default is true. If set to true, you can use that configuration as a source for the `copy-from`-task.
* `backupBeforeDeploy` is set to true for `types` `stage` and `prod`, if set to true, a backup of the DB is made before a deployment.
* `tmpFolder`, default is `/tmp`.
* `environment` contains a list of environment variables to set before running any command
* `shellProvider` defines how to run a shell, where commands are executed, current values are
* `local`: all commands are run locally
* `ssh`: all commands are run via a ssh-shell
Expand Down Expand Up @@ -184,15 +185,25 @@ This will print all host configuration for the host `staging`.
* `drushVersion` set the used crush-version, default is `8`. Drush is not 100% backwards-compatible, for phabalicious needs to know its version.
* `supportsZippedBackups` default is true, set to false, when zipped backups are not supported

#### Configuration of the ftp-sync-method
#### Configuration of the artifacts--ftp-method

* `ftp` keeps all configuration bundled:
* `target` keeps all configuration bundled:
* `user` the ftp-user
* `password` the ftp password
* `host` the ftp host
* `port`, default is 21, the port to connect to
* `rootFolder` the folder to copy the app into on the ftp-host.
* `lftpOptions`, an array of options to pass when executing `lftp`
* `actions` a list of actions to perform. See detailed documentation for more info.


#### Configuration of the artifacts--git method

* `target` contains the following options
* `repository` the url of the target repository
* `branch` the branch to use for commits
* `useLocalRepository` if set to true, phab will use the current directory as a source for the artifact, if set to false, phab will create a new app in a temporary folder and use that as a artifact
* `actions` a list of actions to perform. See detailed documentation for more info.

#### Configuration of the docker-method

Expand All @@ -201,7 +212,7 @@ This will print all host configuration for the host `staging`.
* `name` contains the name of the docker-container. This is needed to get the IP-address of the particular docker-container when using ssh-tunnels (see above).
* for docker-compose-base setups you can provide the `service` instead the name, phabalicious will get the docker name automatically from the service.

### Configuration of the mattermost-method
#### Configuration of the mattermost-method

* `notifyOn`: a list of all tasks where to send a message to a Mattermost channel. Have a look at the global Mattermost-configuration-example below.

Expand Down
182 changes: 182 additions & 0 deletions docs/deploying-artifacts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Deploying artifacts

If you want to deploy artifacts, phabalicious can help you here, currently there are two methods supported:

* artifacts--git
* artifacts--ftp

Both methods create a new application from scratch and deploy all or parts of it to a ftp server or store the artifacts in a git repository. Both methods are using the same stage mechanisms as in `app:create`.

Both methods needs the global `repository`-config, so they can pull the app into a new temporary folder.

## artifacts--ftp

ftp will create a new application in a temporary folder, install all needed dependencies, copies the data into a new temporary folder and run the deploy script of the host-config. After that is finished, phab will mirror all changed files via `lftp` to the server. `lftp` supports multiple protocols, not only ftp, but it needs to be installed on the machine running phab.

ftp-sync use the following stages:

* `installCode` will most of the time clone the source repository
* `installDependencies` will install all needed dependencies
* `runActions` will run all defined actions (see below)
* `runDeployScript` run the deploy-script of the host to apply some custom changes
* `syncToFtp` sync all changed files with the remote ftp server.

### Example config

```yaml

hosts:
ftp-artifacts:
needs:
- git
- composer
- artifacts--ftp
- script
artifact:
user: stephan
host: sftp://localhost
port: 22
password: my-secret
rootFolder: /home/stephan/somewhere
actions:
- action: copy
arguments:
from: "*"
to: .
- action: script
arguments:
- cp .env.example .env
- action: delete
arguments:
- .git/
- .fabfile
- .editorconfig
- .env.example
- .gitattributes
- .gitignore
- composer.lock
- composer.json
- docker-compose.yml
- action: script
arguments:
- ls -la
- action: confirm
arguments:
question: Do you want to continue?

```

The default actions for the ftp-artifact-method will copy all files to the target repo and remove the `.git`-folder and the fabfile.

## artifacts--git

This method will create the artifact, pull the target repository, copy all necessary files over to the target repository, commit any changes to the target repository and push the changes again. A CI listening to commits can do the actual deployment

It is using the following stages:

* `installCode`, creates a temporary folder and pulls the source repository. (only when `useLocalRepository` is set to false)
* `installDependencies` to install the dependencies
* `getSourceCommitInfo` get the commit hash from the source repo.
* `runActions` will run all defined actions (see below)
* `copyFilesToTargetDirectory`, copy specified `files` to the target directory, removes all files listed in `excludeFiles.gitSync`
* `runDeployScript` run the deploy script of the host-config.
* `pushToTargetRepository` commit and push all changes, using the changelog as a commit-message

If you run phabalicious as part of a CI-setup, it might make sense to set `useLocalRepository` to true, as this will instruct phab to use the current folder as a base for the artifact and won't create a new application in another temporary folder.

### Example config

```yaml
hosts:
git-artifact:
needs:
- git
- composer
- artifacts--git
- script
artifact:
branch: master
repository: ssh://somewhere/repository.git
useLocalRepository: false
actions:
- action: copy
arguments:
from: '*'
to: .
- action: script
arguments:
- cp .env.example .env
- action: delete
arguments:
- .env.example
- composer.json
- composer.lock
- docker-compose.yml
- docker-compose-mbb.yml
- .projectCreated
```
the default actions for the git-artifact-method will copy all files to the target repo and remove the fabfile.
## Available actions
You can customize the list of actions be run when deploying an artifact. Here's a list of available actions
### copy
```yaml
- action: copy
argumnents:
from:
- file1
- folder2
- subfolder/file3
to: targetsubfolder
```
This will copy the three mentioned files and folders into the subfolder `targetsubfolder` of the target folder. Please be aware, that you might need to create subdirectories beforehand manually via the `script`-method

### delete

```yaml
- action: delete
arguments:
- file1
- folder2
- subfolder/file3
```

This action will delete the list of files and folders in the target folder. Here you can clean up the target and get rid of unneeded files.

### exclude

```yaml
- action: exclude
arguments:
- file1
- folder2
- subfolder/file3
```

Similar to `delete` this will exclude the list of file and folders from be transferred to the target. For `ftp` the list of files get excluded from transferring, for `git` they will get resetted from the target repository.

### confirm

```yaml
- action: confirm
arguments:
question: Do you want to continue?
```

This action comes handy when degugging the build process, as it will stop the execution and asks the user the questions and wait for `yes` before continuing. Answering sth different will cancel the further execution.

### script

```yaml
- action: script
arguments:
- echo "Hello world"
- cp .env.production .env
```

The `script`-action will run the script from the arguments section line by line. You can use the usual replacement patterns as for other scripts.
46 changes: 46 additions & 0 deletions src/Artifact/Actions/ActionBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Phabalicious\Artifact\Actions;


use Phabalicious\Method\ArtifactsBaseMethod;
use Phabalicious\Validation\ValidationErrorBagInterface;
use Phabalicious\Validation\ValidationService;

abstract class ActionBase implements ActionInterface
{
protected $arguments= [];

public function setArguments($arguments) {
$this->arguments = $arguments;
}

protected function getArguments() : array
{
return $this->arguments;
}

protected function getArgument($name) {
return $this->arguments[$name] ?? null;
}

public function validateConfig($host_config, array $action_config, ValidationErrorBagInterface $errors) {
$service = new ValidationService($action_config, $errors, sprintf(
'host-config.%s.%s.actions', $host_config['configName'], ArtifactsBaseMethod::PREFS_KEY));
$service->hasKeys([
'action' => 'Every action needs the type of action to perform',
'arguments' => 'Missing arguments for an action'
]);
if (isset($action_config['arguments'])) {
$service->isArray('arguments', 'arguments need to be an array!');
}

if (!empty($action_config['action']) && is_array($action_config['arguments'])) {
$service = new ValidationService($action_config['arguments'], $errors, sprintf('%s.arguments', $action_config['action']));
$this->validateArgumentsConfig($action_config, $service);
}
}

abstract protected function validateArgumentsConfig(array $action_arguments, ValidationService $validation);

}
Loading

0 comments on commit 998c6a6

Please sign in to comment.