From 0eeb721a55e568640626e03d48ca8f30118483ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Kut=C3=A1=C4=8D?= Date: Tue, 9 Oct 2018 19:35:16 +0200 Subject: [PATCH] Always run jobs option --- .gitignore | 3 + .travis.yml | 40 -------- composer.json | 36 ------- deployment.sample.ini | 3 + deployment.sample.php | 1 + readme.md | 191 +++-------------------------------- src/Deployment/CliRunner.php | 2 + src/Deployment/Deployer.php | 25 ++++- 8 files changed, 41 insertions(+), 260 deletions(-) delete mode 100644 .travis.yml delete mode 100644 composer.json diff --git a/.gitignore b/.gitignore index 41ea1322..7b981293 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ /composer.lock /tests/tmp /tests/output +/temp +*.sublime-* +composer.phar \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7c909669..00000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: php -php: - - 7.1 - -before_install: - # turn off XDebug - - phpenv config-rm xdebug.ini || return 0 - -install: - - travis_retry composer install --no-progress --prefer-dist - -script: - - vendor/bin/tester tests -s - -after_failure: - # Print *.actual content - - for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done - -jobs: - include: - - stage: Code Standard Checker - install: - # Install Nette Code Checker - - travis_retry composer create-project nette/code-checker temp/code-checker ^3 --no-progress - # Install Nette Coding Standard - - travis_retry composer create-project nette/coding-standard temp/coding-standard ^2 --no-progress - - script: - - php temp/code-checker/code-checker - - php temp/coding-standard/ecs check src tests --config temp/coding-standard/coding-standard-php71.yml - - -sudo: false - -cache: - directories: - - $HOME/.composer/cache - -notifications: - email: false diff --git a/composer.json b/composer.json deleted file mode 100644 index 0a575007..00000000 --- a/composer.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "dg/ftp-deployment", - "type": "project", - "description": "A tool for automated deployment of web applications to an FTP server.", - "keywords": ["deployment", "ftp", "ssh"], - "homepage": "https://github.com/dg/ftp-deployment", - "license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"], - "authors": [ - { - "name": "David Grudl", - "homepage": "https://davidgrudl.com" - } - ], - "require": { - "php": ">=7.1", - "ext-zlib": "*" - }, - "require-dev": { - "nette/tester": "~1.3" - }, - "suggest": { - "ext-ftp": "to connect to ftp:// server", - "ext-openssl": "to connect to ftps:// server and preprocess CSS files", - "ext-ssh2": "to connect to sftp:// server", - "ext-json": "to preprocess CSS files via online service" - }, - "autoload": { - "classmap": ["src/"] - }, - "bin": ["deployment"], - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - } -} diff --git a/deployment.sample.ini b/deployment.sample.ini index c087d6d6..25090311 100644 --- a/deployment.sample.ini +++ b/deployment.sample.ini @@ -10,6 +10,9 @@ remote = ftp://user:secretpassword@ftp.example.com/directory ; FTP passive mode passiveMode = yes +; Always run before, afterUpload, purge and after jobs +alwaysRunActions = yes + ; local path (optional) local = . diff --git a/deployment.sample.php b/deployment.sample.php index 7dee749a..cadae6bd 100644 --- a/deployment.sample.php +++ b/deployment.sample.php @@ -5,6 +5,7 @@ 'remote' => 'ftp://user:secretpassword@ftp.example.com/directory', 'local' => '.', 'test' => false, + 'alwaysRunActions' => true, 'ignore' => ' /deployment.* /log diff --git a/readme.md b/readme.md index 70143559..de714cf3 100644 --- a/readme.md +++ b/readme.md @@ -1,185 +1,18 @@ -FTP Deployment: smart upload [![Buy me a coffee](https://files.nette.org/images/coffee1s.png)](https://nette.org/make-donation?to=deployment) -==================================== +# FTP Deployment - Fork with custom edits -[![Downloads this Month](https://img.shields.io/packagist/dm/dg/ftp-deployment.svg)](https://packagist.org/packages/dg/ftp-deployment) -[![Build Status](https://travis-ci.org/dg/ftp-deployment.svg?branch=master)](https://travis-ci.org/dg/ftp-deployment) -[![Latest Stable Version](https://poser.pugx.org/dg/ftp-deployment/v/stable)](https://github.com/dg/ftp-deployment/releases) -[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/dg/ftp-deployment/blob/master/license.md) +See original from David Grudl on [https://github.com/dg/ftp-deployment](https://github.com/dg/ftp-deployment) -FTP deployment is a tool for automated deployment to an FTP server. +--- -There is nothing worse than uploading web applications to FTP server manually, -using tools like Total Commander. (Although, editing files directly on the server -and then trying to keep some kind of synchronization is even worse ;-) +## Custom changes +Sometimes I want to add custom changes, which is not merged into original repo for any reason.
+Full documentation is available in the link above, here are only changes. -Once the process is automated, it costs you a fraction of time and minimizes the risk of error -(didn't I forget to upload some files?). There are lots of sophisticated deploying techniques available today, -but many people are still using FTP. This tool is designed for them. - -FTP Deployment is a script written in PHP and will automate -the entire process. Just say which local folder to upload and where. This -information is stored in a `deployment.ini` text file, which you can associate -with `deployment` script, so deployment will become a one click thing. - -``` -php deployment deployment.ini -``` - -And what does the `deployment.ini` file contain? **Only the `remote` item is required**, all the others are optional: - -```ini -; log file (defaults to config file with .log extension) -log = ... - -; Show full log in command line (Defaults to no) -; Yes to disable shortening or list any of: http, local, remote, upload, exception -fullCliLog = http exception - -; directory for temporary files (defaults to system's temporary directory) -tempDir = /temp/deployment - -; enable colored highlights? (defaults to autodetect) -colors = yes - -[my site] ; Optional section (there may be more than one section). -; remote FTP server -remote = ftp://user:secretpassword@ftp.example.com/directory -; you can use ftps://, sftp:// or file:// protocols (sftp requires SSH2 extension) - -; do not like to specify user & password in 'remote'? Use these options: -user = ... -password = ... - -; FTP passive mode -passiveMode = yes - -; local path (optional) -local = . - -; run in test-mode? (can be enabled by option -t or --test) -test = no - -; files and directories to ignore -ignore = " - .git* - project.pp[jx] - /deployment.* - /log - temp/* - !temp/.htaccess -" - -; explicit list of files and directories to include (by default includes all files and directories) -include = " - /app - /app/* - /index.php -" - -; is allowed to delete remote files? (defaults to yes) -allowDelete = yes - -; jobs to run before uploading -before[] = local: lessc assets/combined.less assets/combined.css -before[] = http://example.com/deployment.php?before - -; jobs to run after uploading and before uploaded files are renamed -afterUpload[] = http://example.com/deployment.php?afterUpload - -; directories to purge after uploading -purge[] = temp/cache - -; jobs to run after everything (upload, rename, delete, purge) is done -after[] = remote: unzip api.zip -after[] = remote: chmod 0777 temp/cache ; change permissions -after[] = upload: config.server.neon app/config.local.neon -after[] = http://example.com/deployment.php?after - -; files to preprocess (defaults to none) -preprocess = *.js *.css - -; file which contains hashes of all uploaded files (defaults to .htdeployment) -deploymentFile = .deployment - -; default permissions for new files (defaults to none) -filePermissions = 0644 - -; default permissions for new directories (defaults to none) -dirPermissions = 0755 -``` - -In the config file you can create multiple sections (like `[my site]`), so you may have separate -rules for data and for application. - -Configuration can also be stored in a [PHP file](deployment.sample.php). - -In test mode (with `-t` option) uploading or deleting files is skipped, so you can use it -to verify your settings. - -Item `ignore` uses the similar format to [`.gitignore`](http://git-scm.com/docs/gitignore): - -``` -log - ignore all 'log' files or directories in all subfolders -/log - ignore 'log' file or directory in the root -app/log - ignore 'log' file or directory in the 'app' in the root -data/* - ignore everything inside the 'data' folder, but the folder will be created on FTP -!data/db/file.sdb - make an exception for the previous rule and do not ignore file 'file.sdb' -project.pp[jx] - ignore files or folders 'project.ppj' and 'project.ppx' -``` - -Before the upload starts, after it finishes and after all jobs, you can execute commands or call your scripts on -the server (see `before`, `afterUpload`, `after`), which can, for example, switch the server to a maintenance mode. -If you use PHP config, you can run lambda function with deployment environment: - -```php - 'ftp://user:secretpassword@ftp.example.com/directory', - 'local' => '.', - 'before' => [ - function (Deployment\Server $server, Deployment\Logger $logger, Deployment\Deployer $deployer) { - ... do something - }, - ], - ... -]; -``` - -Syncing a large number of files attempts to run in (something like) a transaction: all files are -uploaded with extension `.deploytmp` and then quickly renamed. - -An `.htdeployment` file is uploaded to the server, which contains MD5 hashes of all the files and -is used for synchronization. So the next time you run `deployment`, only modified files are uploaded -and deleted files are deleted from server (if it is not forbidden by the `allowDelete` directive). - -Uploaded files can be processed by a preprocessor. These rules are predefined: `.css` files -are compressed using the Clean-CSS (via online service) and `.js` are minified by Google Closure Compiler (via Java utility). - -There is also a rule for expanding [mod_include](http://httpd.apache.org/docs/current/mod/mod_include.html) Apache directives. -For example, you can create a file `combined.js`: +### Ignore "Already synchronized" +- This was many times requested feature, but never accepted [dg/ftp-deployment#104](/dg/ftp-deployment/issues/104) and [dg/ftp-deployment#88](/dg/ftp-deployment/issues/88). +- To run `before[]`, `afterUpload[]`, `purge[]`, `after[]` actions even not single file is changed add to config: +- Reason why want this? Using `after[]` I upload config files, which is normally ignored. I always want to upload them, as they are not tracked with Git or FTP-Deployment. Example is in [article on my blog](http://www.kutac.cz/blog/weby-a-vse-okolo/nahravani-webu-pomoci-nastroje-ftp-deployment/) (Czech language only). ``` - - - -``` - -This tool will combine scripts together and minify them with the Closure Compiler to speed-up your website. - - -Installing FTP Deployment -------------------------- - -FTP Deployment 3.x requires PHP 7.1 or later (version 2.x requires PHP 5.4 or newer). It also requires openssl extensions for ftps:// and SSH2 extension for sftp:// connections. - -The easiest way to obtain FTP Deployment is to download [a single PHAR file](https://github.com/dg/ftp-deployment/releases). If you want to use JavaScript minification, -download [compiler.jar](src/vendor/Google-Closure-Compiler/compiler.jar) to the same folder. - -Or you can install it using Composer: - -``` -composer create-project dg/ftp-deployment -``` - -If you like it, **[please make a donation now](https://nette.org/make-donation?to=deployment)**. Thank you! +alwaysRunActions = yes +``` \ No newline at end of file diff --git a/src/Deployment/CliRunner.php b/src/Deployment/CliRunner.php index 399d4d9e..509ee2d1 100644 --- a/src/Deployment/CliRunner.php +++ b/src/Deployment/CliRunner.php @@ -23,6 +23,7 @@ class CliRunner 'include' => '', 'ignore' => '', 'allowdelete' => true, + 'alwaysrunactions' => false, 'purge' => '', 'before' => '', 'afterupload' => '', @@ -147,6 +148,7 @@ private function createDeployer(array $config): Deployer $deployment->ignoreMasks = array_merge($this->ignoreMasks, self::toArray($config['ignore'])); $deployment->deploymentFile = empty($config['deploymentfile']) ? $deployment->deploymentFile : $config['deploymentfile']; $deployment->allowDelete = $config['allowdelete']; + $deployment->alwaysRunActions = $config['alwaysrunactions']; $deployment->toPurge = self::toArray($config['purge'], true); $deployment->runBefore = self::toArray($config['before'], true); $deployment->runAfterUpload = self::toArray($config['afterupload'], true); diff --git a/src/Deployment/Deployer.php b/src/Deployment/Deployer.php index e7245cab..ef13c07f 100644 --- a/src/Deployment/Deployer.php +++ b/src/Deployment/Deployer.php @@ -33,6 +33,9 @@ class Deployer /** @var bool */ public $allowDelete = false; + /** @var bool Ignore Already synchronized*/ + public $alwaysRunActions = false; + /** @var string[] relative paths */ public $toPurge = []; @@ -120,7 +123,9 @@ public function deploy(): void if (!$toUpload && !$toDelete) { $this->logger->log('Already synchronized.', 'lime'); - return; + if (!$this->alwaysRunActions) { + return; + } } elseif ($this->testMode) { $this->logger->log("\nUploading:\n" . implode("\n", $toUpload), 'green', false); @@ -144,13 +149,12 @@ public function deploy(): void if ($toUpload) { $this->logger->log("\nUploading:"); $this->uploadPaths($toUpload); - if ($this->runAfterUpload) { - $this->logger->log("\nAfter-upload-jobs:"); - $this->runJobs($this->runAfterUpload); - } + $this->runAfterUploadJobs(); $this->logger->log("\nRenaming:"); $this->renamePaths($toUpload); unlink($deploymentFile); + }else if($this->alwaysRunActions){ + $this->runAfterUploadJobs(); } if ($toDelete) { @@ -179,6 +183,17 @@ public function deploy(): void } + /** + * Run after-upload jobs + */ + private function runAfterUploadJobs(){ + if ($this->runAfterUpload) { + $this->logger->log("\nAfter-upload-jobs:"); + $this->runJobs($this->runAfterUpload); + } + } + + /** * Appends preprocessor for files. */