Skip to content

Commit

Permalink
Merge pull request #34 from MasonD/master
Browse files Browse the repository at this point in the history
Replace hardcoded occurences of mysite with phing property.
  • Loading branch information
Nathan authored Jan 13, 2019
2 parents fd9763c + b628680 commit a74918f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 40 deletions.
37 changes: 23 additions & 14 deletions SilverStripeDeployTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SilverStripeDeployTask extends SilverStripeBuildTask {
/* deployment config */

private $localpath;
private $apppath;
private $package = '';
private $apachegroup = 'apache';
private $remotepath = '';
Expand Down Expand Up @@ -93,12 +94,12 @@ protected function beforeDeploy($releasePath, $currentPath) {
// These are legacy, but remain to support older projects.

$this->execute("cp $currentPath/_ss_environment.php $releasePath/");
$this->execute("cp $currentPath/mysite/local.conf.php $releasePath/mysite/local.conf.php");
$this->execute("cp $currentPath/$this->apppath/local.conf.php $releasePath/$this->apppath/local.conf.php");

// ---

$localConf = "$currentPath/mysite/_config/local.yml";
$cmd = "if [ -f $localConf ]; then cp $localConf $releasePath/mysite/_config/; fi";
$localConf = "$currentPath/$this->apppath/_config/local.yml";
$cmd = "if [ -f $localConf ]; then cp $localConf $releasePath/$this->apppath/_config/; fi";
$this->execute($cmd);
}
}
Expand Down Expand Up @@ -130,29 +131,29 @@ protected function doDeploy($releasePath, $currentPath) {
// These are legacy, but remain to support older projects.

$this->execute("cp $currentPath/_ss_environment.php $releasePath/");
$this->execute("cp $currentPath/mysite/local.conf.php $releasePath/mysite/local.conf.php");
$this->execute("cp $currentPath/$this->apppath/local.conf.php $releasePath/$this->apppath/local.conf.php");

// ---

$localConf = "$currentPath/mysite/_config/local.yml";
$cmd = "if [ -f $localConf ]; then cp $localConf $releasePath/mysite/_config/; fi";
$localConf = "$currentPath/$this->apppath/_config/local.yml";
$cmd = "if [ -f $localConf ]; then cp $localConf $releasePath/$this->apppath/_config/; fi";
$this->execute($cmd);

$this->log("Copying site assets");
$this->execute("rsync -rl $currentPath/assets $releasePath/");
}

$this->log("Pre-deploy");
$this->executeOptionalPhpScript($releasePath .'/mysite/scripts/pre_deploy.php');
$this->executeOptionalPhpScript($releasePath .'/'. $this->apppath .'/scripts/pre_deploy.php');

$this->log("Backing up database");
$this->execute("php $currentPath/mysite/scripts/backup_database.php");
$this->execute("php $currentPath/$this->apppath/scripts/backup_database.php");

$this->log("Saving .htaccess");
$this->execute("cp $releasePath/.htaccess $releasePath/mysite/.htaccess.bak");
$this->execute("cp $releasePath/.htaccess $releasePath/$this->apppath/.htaccess.bak");

$this->log("Checking for maintenance mode, and switching if found");
$maintenanceHtaccess = "$releasePath/mysite/.htaccess-maintenance";
$maintenanceHtaccess = "$releasePath/$this->apppath/.htaccess-maintenance";
$cmd = "if [ -f $maintenanceHtaccess ]; then cp $maintenanceHtaccess $currentPath/.htaccess; fi";
$this->execute($cmd);
$cmd = "if [ -f $maintenanceHtaccess ]; then cp $maintenanceHtaccess $releasePath/.htaccess; fi";
Expand All @@ -171,7 +172,7 @@ protected function doDeploy($releasePath, $currentPath) {
}

$this->log("Restoring .htaccess");
$htaccessBak = "$releasePath/mysite/.htaccess.bak";
$htaccessBak = "$releasePath/$this->apppath/.htaccess.bak";
$cmd = "if [ -f $htaccessBak ]; then cp $htaccessBak $releasePath/.htaccess; fi";
$this->execute($cmd);

Expand All @@ -187,7 +188,7 @@ protected function doDeploy($releasePath, $currentPath) {
* @param type $currentPath
*/
public function preLinkSwitch($releasePath) {
$this->executeOptionalPhpScript($releasePath .'/mysite/scripts/pre_switch.php', dirname($releasePath));
$this->executeOptionalPhpScript($releasePath .'/'. $this->apppath .'/scripts/pre_switch.php', dirname($releasePath));

$this->log("Setting silverstripe-cache permissions");
$this->execute("chgrp -R $this->apachegroup $releasePath/silverstripe-cache", true);
Expand All @@ -203,7 +204,7 @@ public function preLinkSwitch($releasePath) {
*/
public function postDeploy($releasePath) {
$arg = dirname($releasePath);
$this->executeOptionalPhpScript($releasePath .'/mysite/scripts/post_deploy.php', $arg);
$this->executeOptionalPhpScript($releasePath .'/'. $this->apppath .'/scripts/post_deploy.php', $arg);

$this->log("Fixing permissions");
// force silverstripe-cache permissions first before the rest.
Expand All @@ -215,7 +216,7 @@ public function postDeploy($releasePath) {
$this->execute("find $releasePath -type f -exec chmod 664 {} \;", true);
$this->execute("find $releasePath -type d -exec chmod 2775 {} \;", true);

$this->executeOptionalPhpScript($releasePath .'/mysite/scripts/finalise_deployment.php', dirname($releasePath));
$this->executeOptionalPhpScript($releasePath .'/'. $this->apppath .'/scripts/finalise_deployment.php', dirname($releasePath));
}

protected function executeOptionalPhpScript($script) {
Expand Down Expand Up @@ -332,6 +333,14 @@ public function getLocalpath() {
return $this->localpath;
}

public function setApppath($p) {
$this->apppath = $p;
}

public function getApppath() {
return $this->apppath;
}

public function setRemotepath($p) {
$this->remotepath = $p;
}
Expand Down
6 changes: 4 additions & 2 deletions build.properties.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#
########################################################################

# The project code folder. SS3 uses mysite, and SS4's default is app.
project.root=mysite

# Where should the modules be retrieved from?
# This reads and loads the modules one by one to remove any problems
# with dependencies between modules. Just make sure they're
# in the file in the order they should be loaded...
modules.depends.file=mysite/build/dependent-modules
modules.depends.file=${project.root}/build/dependent-modules

# The core modules for silverstripe
modules.core.file=build/core-modules
Expand Down Expand Up @@ -48,7 +50,7 @@ git.branch=master

build.output.dir=build
build.archive.dir=${build.output.dir}/archive
patches.dir=mysite/build/patches
patches.dir=${project.root}/build/patches

# Module package information
module.name=${phing.project.name}
Expand Down
52 changes: 28 additions & 24 deletions buildfile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<echo>${git.branch}</echo>

<property file="${project.basedir}/build/build.properties"></property>
<!-- To maintain backwards compatibility, we must default project.root to mysite, even if not
present in build.properties, since this used to be hardcoded. -->
<property name="project.root" value="mysite" />

<if>
<isset property="env.GIT_COMMIT" />
Expand Down Expand Up @@ -144,7 +147,7 @@ Other features
<then>
<echo>Touching configs if they exist</echo>
<exec command="touch -c .env" checkreturn="true" />
<exec command="touch -c mysite/_config/local.yml" checkreturn="true" />
<exec command="touch -c ${project.root}/_config/local.yml" checkreturn="true" />
<exec command="touch -c test-assist/artifacts/html/.htaccess" checkreturn="true" />
<exec command="touch -c .htaccess" checkreturn="true" />
</then>
Expand All @@ -154,8 +157,8 @@ Other features
replacement, we use that -->
<property name="config_prefix" value="" />
<if>
<available file="mysite/${local.php.config}" />
<then><property name="config_prefix" value="mysite/" override="true" /></then>
<available file="${project.root}/${local.php.config}" />
<then><property name="config_prefix" value="${project.root}/" override="true" /></then>
</if>
<echo>local.php prefix = ${config_prefix}</echo>
<if>
Expand All @@ -171,11 +174,11 @@ Other features

<property name="config_prefix" value="" override="true" />
<if>
<available file="mysite/${local.yml.config}" />
<then><property name="config_prefix" value="mysite/" override="true" /></then>
<available file="${project.root}/${local.yml.config}" />
<then><property name="config_prefix" value="${project.root}/" override="true" /></then>
</if>
<echo>local.yml prefix = ${config_prefix}</echo>
<copy tofile="mysite/_config/local.yml" file="${config_prefix}${local.yml.config}" overwrite="false">
<copy tofile="${project.root}/_config/local.yml" file="${config_prefix}${local.yml.config}" overwrite="false">
<filterchain>
<expandproperties />
</filterchain>
Expand All @@ -194,8 +197,8 @@ Allow from 127.0.0.1

<property name="config_prefix" value="" override="true" />
<if>
<available file="mysite/${htaccess.config}" />
<then><property name="config_prefix" value="mysite/" override="true" /></then>
<available file="${project.root}/${htaccess.config}" />
<then><property name="config_prefix" value="${project.root}/" override="true" /></then>
</if>
<!-- Copy the htaccess -->
<copy tofile=".htaccess" file="${config_prefix}${htaccess.config}" overwrite="false">
Expand All @@ -214,15 +217,15 @@ Allow from 127.0.0.1
<delete dir="assets" />
<delete dir="public/assets" />
<delete file="${project.basedir}/.env" />
<delete file="${project.basedir}/mysite/_config/local.yml" />
<delete file="${project.basedir}/${project.root}/_config/local.yml" />
<property name="properties_exist" value="true" override="true" />
<property file="${project.basedir}/build/build.properties"></property>
<mkdir dir="${project.basedir}/silverstripe-cache" />
</target>

<!-- Installs a freshly checked-out silverstripe project -->
<target name="build" depends="init,default_configs">
<echo file="mysite/BUILD_NUMBER" append="false">Build ${BUILD_STAMP}</echo>
<echo file="${project.root}/BUILD_NUMBER" append="false">Build ${BUILD_STAMP}</echo>

<phingcall target="update-composer" />
<phingcall target="update_modules" />
Expand Down Expand Up @@ -253,12 +256,12 @@ Allow from 127.0.0.1
</target>

<target name="pak">
<delete file="mysite/build/site.sspak" />
<exec command="sspak save . mysite/build/site.sspak" passthru="true" />
<delete file="${project.root}/build/site.sspak" />
<exec command="sspak save . ${project.root}/build/site.sspak" passthru="true" />
</target>

<target name="unpak">
<exec command="sspak load mysite/build/site.sspak ." passthru="true" />
<exec command="sspak load ${project.root}/build/site.sspak ." passthru="true" />
</target>

<!-- Create a deployable package to use as the base for installing a new site FROM SCRATCH.
Expand All @@ -279,11 +282,11 @@ Allow from 127.0.0.1
<exclude name="build/" />
<exclude name="build.xml" />
<exclude name=".env" />
<exclude name="mysite/local.conf.php" />
<exclude name="mysite/_config/local.yml" />
<exclude name="mysite/db.conf.php" />
<exclude name="mysite/*.log" />
<exclude name="mysite/build/**" />
<exclude name="${project.root}/local.conf.php" />
<exclude name="${project.root}/_config/local.yml" />
<exclude name="${project.root}/db.conf.php" />
<exclude name="${project.root}/*.log" />
<exclude name="${project.root}/build/**" />
<exclude name="**/.svn/**" />
<exclude name="**/.git/**" />
<exclude name="nbproject/**" />
Expand Down Expand Up @@ -374,14 +377,14 @@ Allow from 127.0.0.1
<fileset dir="${project.basedir}">
<include name="**/**" />
<exclude name="sitemap.xml" />
<exclude name="mysite/db.conf.php" />
<exclude name="${project.root}/db.conf.php" />
<exclude name=".env" />
<exclude name="_ss_environment.php" />
<exclude name="mysite/local.conf.php" />
<exclude name="mysite/_config/local.yml" />
<exclude name="mysite/*.log" />
<exclude name="${project.root}/local.conf.php" />
<exclude name="${project.root}/_config/local.yml" />
<exclude name="${project.root}/*.log" />
<exclude name="build/**" />
<exclude name="mysite/build/**" />
<exclude name="${project.root}/build/**" />
<exclude name="build.xml" />
<exclude name=".htaccess" />
<exclude name="**/.svn/**" />
Expand Down Expand Up @@ -554,6 +557,7 @@ Deny from all
ignoreerrors="${deploy.first}"
incremental="${deploy.incremental}"
localpath="${build.output.dir}"
apppath="${project.root}"
remotepath="${deploy.${deptarget}.path}"
package="${deploy.package}"
apachegroup="${deploy.${deptarget}.apache-group}"
Expand Down Expand Up @@ -612,7 +616,7 @@ Deny from all
<if>
<not><isset property="phpstan.dir" /></not>
<then>
<property name="phpstan.dir" value="mysite" />
<property name="phpstan.dir" value="${project.root}" />
</then>
</if>
<!-- Run PHPStan -->
Expand Down

0 comments on commit a74918f

Please sign in to comment.