Skip to content

Instantly share code, notes, and snippets.

@viccherubini
Last active December 27, 2015 08:09
Show Gist options
  • Save viccherubini/7293911 to your computer and use it in GitHub Desktop.
Save viccherubini/7293911 to your computer and use it in GitHub Desktop.
Expert PHP Deployments Phing build.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<project name="Your Application" default="build">
<resolvepath propertyName="root_path" file="./" />
<resolvepath propertyName="config_path" file="./app/config/" />
<php function="date" returnProperty="build_date">
<param value="c" />
</php>
<php function="time" returnProperty="build_timestamp" />
<available file="${build_settings_file}" property="build_settings_file_exists" value="1" />
<if>
<equals arg1="${build_settings_file_exists}" arg2="1" />
<then>
<property file="${build_settings_file}" />
</then>
</if>
<target name="build" depends="clean,compile-configuration,compile-vendors,warmup-dev,run-database-migrations-dev"></target>
<target name="deploy" depends="compile-configuration,compile-vendors,warmup-prod,compile-composer-cache,run-database-migrations-prod"></target>
<target name="clean">
<delete file="${root_path}/config/config.php" quiet="true" />
</target>
<target name="compile-vendors">
<delete dir="${root_path}/vendor/" quiet="true" />
<exec command="php composer.phar install --optimize-autoloader --no-ansi" checkreturn="true" passthru="true" />
</target>
<target name="compile-composer-cache">
<exec command="php composer.phar dump-autoload --optimize --no-ansi" checkreturn="true" passthru="true" />
</target>
<target name="compile-configuration">
<copy file="${root_path}/config/config.php.template" tofile="${root_path}/config/config.php" overwrite="true">
<filterchain>
<replacetokens begintoken="@@" endtoken="@@">
<token key="DB_SETTINGS_HOST" value="${db_settings.host}" />
<token key="DB_SETTINGS_DATABASE" value="${db_settings.database}" />
<token key="DB_SETTINGS_USERNAME" value="${db_settings.username}" />
<token key="DB_SETTINGS_PASSWORD" value="${db_settings.password}" />
<token key="DB_SETTINGS_TEST_HOST" value="${db_settings_test.host}" />
<token key="DB_SETTINGS_TEST_DATABASE" value="${db_settings_test.database}" />
<token key="DB_SETTINGS_TEST_USERNAME" value="${db_settings_test.username}" />
<token key="DB_SETTINGS_TEST_PASSWORD" value="${db_settings_test.password}" />
<token key="REDIS_HOST" value="${redis_host}" />
<token key="REDIS_PORT" value="${redis_port}" />
<token key="MAILER_HOST" value="${mailer_host}" />
<token key="MAILER_USERNAME" value="${mailer_username}" />
<token key="MAILER_PASSWORD" value="${mailer_password}" />
<token key="BUILD_DATE" value="${build_date}" />
<token key="BUILD_TIMESTAMP" value="${build_timestamp}" />
</replacetokens>
</filterchain>
</copy>
</target>
<target name="run-database-migrations-dev">
<!-- Add an <exec> tag here to run your database migrations for the development environment. -->
</target>
<target name="run-database-migrations-prod">
<!-- Add an <exec> tag here to run your database migrations for the production environment. -->
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment