Skip to content

Commit

Permalink
Added external config file support
Browse files Browse the repository at this point in the history
  • Loading branch information
markomarkovic committed Nov 5, 2013
1 parent 65623d6 commit 1c9244c
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 11 deletions.
120 changes: 120 additions & 0 deletions deploy-config.example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
/**
* Deployment configuration
*
* It's preferable to configure the script using this file istead of directly.
*
* Rename this file to `deploy-config.php` and edit the
* configuration options here instead of directly in `deploy.php`.
* That way, you won't have to edit the configuration again if you download the
* new version of `deploy.php`.
*/

/**
* Protect the script from unauthorized access by using a secret access token.
* If it's not present in the access URL as a GET variable named `sat`
* e.g. deploy.php?sat=Bett...s the script is not going to deploy.
*
* @var string
*/
define('SECRET_ACCESS_TOKEN', 'BetterChangeMeNowOrSufferTheConsequences');

/**
* The address of the remote Git repository that contains the code that's being
* deployed.
* If the repository is private, you'll need to use the SSH address.
*
* @var string
*/
define('REMOTE_REPOSITORY', 'https://github.com/markomarkovic/simple-php-git-deploy.git');

/**
* The branch that's being deployed.
* Must be present in the remote repository.
*
* @var string
*/
define('BRANCH', 'master');

/**
* The location that the code is going to be deployed to.
* Don't forget the trailing slash!
*
* @var string Full path including the trailing slash
*/
define('TARGET_DIR', '/tmp/simple-php-git-deploy/');

/**
* Weather to delete the files that are not in the repository but are on the
* local (server) machine.
*
* !!! WARNING !!! This can lead to a serious loss of data if you're not
* careful. All files that are not in the repository are going to be deleted,
* except the ones defined in EXCLUDE section and the ones listed in .gitignore
* if EXCLUDE_GITIGNORE is set to true!
* BE CAREFUL!
*
* @var boolean
*/
define('DELETE_FILES', false);

/**
* The directories and files that are to be excluded when updating the code.
* Normally, these are the directories containing files that are not part of
* code base, for example user uploads or server-specific configuration files.
* Use rsync exclude pattern syntax for each element.
*
* @var serialized array of strings
*/
define('EXCLUDE', serialize(array(
'.git',
'webroot/uploads',
'app/config/database.php',
)));

/**
* Weather to exclude all files and directories listed in .gitignore.
* Only the .gitignore file in the project root directory is going to be used.
*
* @var boolean
*/
define('EXCLUDE_GITIGNORE', false);

/**
* Temporary directory we'll use to stage the code before the update. If it
* already exists, script assumes that it contains an already cloned copy of the
* repository with the correct remote origin and only fetches changes instead of
* cloning the entire thing.
*
* @var string Full path including the trailing slash
*/
define('TMP_DIR', '/tmp/spgd-'.md5(REMOTE_REPOSITORY).'/');

/**
* Weather to remove the TMP_DIR after the deployment.
* It's useful NOT to clean up in order to only fetch changes on the next
* deployment.
*/
define('CLEAN_UP', true);

/**
* Output the version of the deployed code.
*
* @var string Full path to the file name
*/
define('VERSION_FILE', TMP_DIR.'VERSION.txt');

/**
* Time limit for each command.
*
* @var int Time in seconds
*/
define('TIME_LIMIT', 30);

/**
* OPTIONAL
* Backup the TARGET_DIR into BACKUP_DIR before deployment
*
* @var string Full backup directory path e.g. '/tmp/'
*/
define('BACKUP_DIR', false);
31 changes: 20 additions & 11 deletions deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

// =========================================[ Configuration start ]===

/**
* It's preferable to configure the script using `deploy-config.php` file.
*
* Rename `deploy-config.example.php` to `deploy-config.php` and edit the
* configuration options there instead of here. That way, you won't have to edit
* the configuration again if you download the new version of `deploy.php`.
*/
if (file_exists(basename(__FILE__, '.php').'-config.php')) require_once basename(__FILE__, '.php').'-config.php';

/**
* Protect the script from unauthorized access by using a secret access token.
* If it's not present in the access URL as a GET variable named `sat`
Expand All @@ -26,23 +35,23 @@
*
* @var string
*/
define('REMOTE_REPOSITORY', 'https://github.com/markomarkovic/simple-php-git-deploy.git');
if (!defined('REMOTE_REPOSITORY')) define('REMOTE_REPOSITORY', 'https://github.com/markomarkovic/simple-php-git-deploy.git');

/**
* The branch that's being deployed.
* Must be present in the remote repository.
*
* @var string
*/
define('BRANCH', 'master');
if (!defined('BRANCH')) define('BRANCH', 'master');

/**
* The location that the code is going to be deployed to.
* Don't forget the trailing slash!
*
* @var string Full path including the trailing slash
*/
define('TARGET_DIR', '/tmp/simple-php-git-deploy/');
if (!defined('TARGET_DIR')) define('TARGET_DIR', '/tmp/simple-php-git-deploy/');

/**
* Weather to delete the files that are not in the repository but are on the
Expand All @@ -56,7 +65,7 @@
*
* @var boolean
*/
define('DELETE_FILES', false);
if (!defined('DELETE_FILES')) define('DELETE_FILES', false);

/**
* The directories and files that are to be excluded when updating the code.
Expand All @@ -66,7 +75,7 @@
*
* @var serialized array of strings
*/
define('EXCLUDE', serialize(array(
if (!defined('EXCLUDE')) define('EXCLUDE', serialize(array(
'.git',
'webroot/uploads',
'app/config/database.php',
Expand All @@ -78,7 +87,7 @@
*
* @var boolean
*/
define('EXCLUDE_GITIGNORE', false);
if (!defined('EXCLUDE_GITIGNORE')) define('EXCLUDE_GITIGNORE', false);

/**
* Temporary directory we'll use to stage the code before the update. If it
Expand All @@ -88,36 +97,36 @@
*
* @var string Full path including the trailing slash
*/
define('TMP_DIR', '/tmp/spgd-'.md5(REMOTE_REPOSITORY).'/');
if (!defined('TMP_DIR')) define('TMP_DIR', '/tmp/spgd-'.md5(REMOTE_REPOSITORY).'/');

/**
* Weather to remove the TMP_DIR after the deployment.
* It's useful NOT to clean up in order to only fetch changes on the next
* deployment.
*/
define('CLEAN_UP', true);
if (!defined('CLEAN_UP')) define('CLEAN_UP', true);

/**
* Output the version of the deployed code.
*
* @var string Full path to the file name
*/
define('VERSION_FILE', TMP_DIR.'VERSION.txt');
if (!defined('VERSION_FILE')) define('VERSION_FILE', TMP_DIR.'VERSION.txt');

/**
* Time limit for each command.
*
* @var int Time in seconds
*/
define('TIME_LIMIT', 30);
if (!defined('TIME_LIMIT')) define('TIME_LIMIT', 30);

/**
* OPTIONAL
* Backup the TARGET_DIR into BACKUP_DIR before deployment
*
* @var string Full backup directory path e.g. '/tmp/'
*/
define('BACKUP_DIR', false);
if (!defined('BACKUP_DIR')) define('BACKUP_DIR', false);

// ===========================================[ Configuration end ]===

Expand Down

0 comments on commit 1c9244c

Please sign in to comment.