Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #341 #284: Automating alias installation and template updates. #368

Merged
merged 10 commits into from
Sep 9, 2016
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ script:
- yes | blt init
# The local.hostname must be set to 127.0.0.1:8888 because we are using drush runserver to run the site on Travis CI.
- drupal yaml:update:value project.yml project.local.hostname '127.0.0.1:8888'
- blt configure
# Running `blt init` modified composer.json, so we must update.
- composer update
# Call targets in the new 'blt-project' project.
Expand Down
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ git commit -m 'Initial commit.'

The new `blt-project` directory will have a composer dependency on your local clone of BLT via a `../blt` symlink. You can therefore make changes to files in `blt` and see them immediately reflected in `blt-project/vendor/acquia/blt`.

### Updating BLT

Given that `vendor/acquia/blt` is symlinked to `../blt`, you won't need to actually rebuild the blt dependency often. However, you may need to trigger a blt event or rebuild autoloader files, in which case you should run the following command: `rm -rf vendor/acquia/blt && composer update acquia/blt`.

## Development conventions

### Phing targets vs. Symfony commands?
Expand Down
10 changes: 2 additions & 8 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ You should be able to use the following tools on the command line of your native

1. Install the `blt` alias and follow on-screen instructions:

./vendor/bin/blt install-alias
composer blt-alias

1. Customize BLT configuration files:
* `project.yml`
* `docroot/sites/default/settings/local.settings.php`
* Add your local DB credentials to `$databases`
1. Replace tokens in new BLT-generated files with your custom values in project.yml:

blt configure

1. Follow instructions for [Setting up your \*AMP stack](#set-up-your-amp-stack)
1. Follow instructions for <a href="#build-your-projects-local-dependencies-and-install-drupal-locally">installing Drupal locally</a>. Don't install Drupal locally using your web browser.
1. (optional) Modify project files. Important files that you may want to modify include:
Expand All @@ -53,10 +49,9 @@ To add BLT to a pre-existing Drupal project, do the following:
1. Ensure that your project directory structure is Acquia-cloud compatible by asserting that the Drupal root is in a top-level folder called `docroot`.
1. If you currently manage your dependencies via Composer, ensure that they are all up to date via `composer update`. Assert that these updates do not break your project.
1. `cd` into your existing project directory.
1. Add BLT via composer and initialize it:
1. Add BLT via composer:

composer require acquia/blt:~8 --dev
./vendor/bin/blt init

1. Follow instructions for [Setting up your \*AMP stack](#set-up-your-42amp-stack)
1. Follow instructions for <a href="#build-your-projects-local-dependencies-and-install-drupal-locally">installing Drupal locally</a>. Don't install Drupal locally using your web browser.
Expand All @@ -72,7 +67,6 @@ To add BLT to a pre-existing Drupal project, do the following:
If you are already using BLT via Composer, you can update to the latest version of BLT by running the following commands from your project's root directory:

composer update acquia/blt
blt update

Review and commit changes to your project files. For customized files like `.travis.yml` or `docroot/sites/default/settings.php` it is recommended that you use `git add -p` to select which specific line changes you'd like to stage and commit.

Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "acquia/blt",
"description": "BLT",
"type": "composer-plugin",
"license": "GPL-2.0",
"require": {
"drupal/console": "~1",
Expand All @@ -11,14 +12,19 @@
"symfony/yaml": "~2.7",
"drupal/coder": "~8.2",
"symfony/console": "~2",
"symfony/twig-bridge": "~2"
"symfony/twig-bridge": "~2",
"php": ">=5.6",
"composer-plugin-api": "^1.0.0"
},
"autoload": {
"psr-4": {
"Acquia\\Blt\\": "src/",
"Acquia\\Blt\\Tests\\": "tests/phpunit/src/"
}
},
"extra": {
"class": "Acquia\\Blt\\Composer\\Plugin"
},
"bin": [
"bin/blt",
"bin/blt-console"
Expand All @@ -29,6 +35,6 @@
"minimum-stability": "beta",
"prefer-stable": true,
"scripts": {
"install-blt-alias": "./blt.sh install-alias"
"install-blt-alias": "blt install-alias -Dcreate_alias=true"
}
}
8 changes: 5 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
61 changes: 13 additions & 48 deletions phing/tasks/blt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,19 @@
<echo>BLT files have been copied to your project directory.</echo>
<echo>Some of your existing files may have been modified.</echo>
<echo></echo>
<echo>Please customize ${repo.root}/project.yml and then run:</echo>
<echo>blt configure</echo>
<echo></echo>
<echo>This will replace placeholders with your custom values in the new files created by BLT.</echo>
<echo>Please customize ${repo.root}/project.yml.</echo>
</target>

<target name="blt:rsync-template">
<echo>Copying files from BLT's template into your project.</echo>
<!-- @todo Do not overwrite structured or executable files. Instead, update them intelligently settings.php, drush.wrapper etc. -->
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --exclude '/project.yml' --exclude '/composer.json' --exclude '/README.md'" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --exclude-from=${blt.root}/scripts/blt/rsync-include-if-does-not-exist.txt" logoutput="true" checkreturn="true" level="info" passthru="true"/>

<!--Rsync files without overwriting existing-->
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/project.yml ${repo.root}/ --ignore-existing" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/README.md ${repo.root}/ --ignore-existing" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --include-from=${blt.root}/scripts/blt/rsync-include-if-does-not-exist.txt --ignore-existing" logoutput="true" checkreturn="true" level="info" passthru="true"/>
</target>

<target name="update" depends="init, blt:update-yml, configure">
<target name="update" depends="init">
<!-- @todo Ignore some files, settings.php, project.yml, in update. Instead, change only specific values. -->
<exec dir="${repo.root}" command="${blt.root}/scripts/blt/update.sh" logoutput="true" checkreturn="true" level="info" passthru="true" />
<echo>Some of your customized files may have been modified.</echo>
Expand Down Expand Up @@ -59,51 +55,20 @@
<echo>project.yml has been modified.</echo>
</target>

<target name="configure">
<!-- @todo add multisite support. -->
<echo>Making ${docroot}/sites/default/settings.php writable.</echo>
<chmod mode="0644" failonerror="false" file="${docroot}/sites/default/settings.php"/>

<echo>Expanding Phing properties in BLT files.</echo>
<!-- Reflexively expand properties in specified dirs/files. -->
<reflexive>
<fileset dir="${repo.root}">
<include name="composer.json" />
<include name="README.md" />
<include name="docroot/sites/*/local.drushrc.php" />
<include name="readme/**/*" />
<include name="scripts/git-hooks/*" />
<include name="tests/phpunit/Bolt" />
</fileset>
<filterchain>
<expandproperties />
</filterchain>
</reflexive>
</target>

<target name="install-alias" description="Installs the BLT alias for command line usage.">
<if>
<not><equals arg1="${create_alias}" arg2="false"/></not>
<then>
<!-- @todo Add this to ~/.blt/aliases and include that into ~/.bashrc or whatever. -->
<exec dir="${blt.root}/scripts/blt" command="./install-alias.sh" logoutput="true" level="info" passthru="true"/>
<if>
<equals arg1="${create_alias}" arg2="true"/>
<then>
<exec dir="${blt.root}/scripts/blt" command="./install-alias.sh -y" logoutput="true" level="info" passthru="true"/>
</then>
<else>
<exec dir="${blt.root}/scripts/blt" command="./install-alias.sh" logoutput="true" level="info" passthru="true"/>
</else>
</if>
</then>
</if>
</target>

<!-- This target is meant to test BLT itself on TravisCI.
A few things to note:
- We do not run validate:* targets, since they can be run in parallel.
-->
<target name="self-test" description="Runs tests against acquia/blt proper.">
<phingcall target="configure" />
<phingcall target="create" />
<phingcall target="setup:build" />
<phingcall target="setup:drupal:install" />
<phingcall target="setup:git-hooks" />
<phingcall target="setup:behat" />
<phingcall target="tests:security-updates" />
<phingcall target="tests:behat" />
<phingcall target="tests:phpunit" />
</target>
</project>
4 changes: 2 additions & 2 deletions phing/tasks/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<echo>Making ${docroot}/sites/default/settings.php writable.</echo>
<chmod mode="0755" failonerror="false" file="${docroot}/sites/default/settings.php"/>
<echo>Ensuring that blt.settings.php is required by settings.php</echo>
<exec dir="${docroot}/sites/default" command="grep blt.settings.php settings.php || echo 'require DRUPAL_ROOT . &quot;/../vendor/acquia/blt/settings/blt.settings.php&quot;;' >> settings.php" logoutput="true" checkreturn="true" level="info"/>
<exec dir="${docroot}/sites/default" command="grep vendor/acquia/blt/settings/blt.settings.php settings.php || echo 'require DRUPAL_ROOT . &quot;/../vendor/acquia/blt/settings/blt.settings.php&quot;;' >> settings.php" logoutput="true" checkreturn="true" level="info"/>

<echo>Generating local settings files.</echo>
<!--@todo Check that install_profile is set in settings.php.-->
Expand Down Expand Up @@ -121,7 +121,7 @@

<target name="setup:drupal:install"
description="Installs a specific Drupal site."
depends="setup:drupal:settings, setup:hash-salt, configure">
depends="setup:drupal:settings, setup:hash-salt">

<echo>Printing drush status.</echo>
<drush command="status"/>
Expand Down
28 changes: 22 additions & 6 deletions phing/tasks/vm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<echo>BLT support for Drupal VM is EXPERIMENTAL. Not all BLT features currently work with Drupal VM. </echo>

<echo>Creating a drush alias for the new VM.</echo>
<exec dir="${repo.root}" command="cat ${blt.root}/scripts/drupal-vm/drupal-vm.aliases.drushrc.php >> ${repo.root}/drush/site-aliases/aliases.drushrc.php" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="cat ${blt.root}/scripts/drupal-vm/drupal-vm.aliases.drushrc.php >> ${repo.root}/drush/site-aliases/aliases.drushrc.php" logoutput="true" checkreturn="true" level="info"/>
<reflexive>
<fileset dir="${repo.root}">
<include name="drush/site-aliases/aliases.drushrc.php" />
Expand All @@ -13,16 +13,23 @@
<expandproperties />
</filterchain>
</reflexive>

<echo>Creating a config.yml file for Drupal VM.</echo>
<mkdir dir="${repo.root}/box" mode="755"/>
<echo>Adding geerlingguy/drupal-vm to composer dev dependencies.</echo>
<exec dir="${repo.root}" command="composer require --dev geerlingguy/drupal-vm:~3.1" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<copy file="${blt.root}/scripts/drupal-vm/config.yml" tofile="${repo.root}/box/config.yml">
<filterchain>
<expandproperties />
</filterchain>
</copy>

<echo>Creating a Vagrantfile.</echo>
<copy file="${blt.root}/scripts/drupal-vm/Vagrantfile" todir="${repo.root}"/>

<echo>Adding geerlingguy/drupal-vm to composer dev dependencies.</echo>
<exec dir="${repo.root}" command="composer require --dev geerlingguy/drupal-vm:~3.1" logoutput="true" checkreturn="true" level="info" passthru="true"/>

<!-- Sadly this wipes out comments in the file. -->
<echo>Updating project.yml.</echo>
<exec dir="${repo.root}" command="${composer.bin}/drupal yaml:update:value ${repo.root}/project.yml drush.default_alias '${project.machine_name}.local'" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="${composer.bin}/drupal yaml:update:value ${repo.root}/project.yml drush.aliases.local '${project.machine_name}.local'" logoutput="true" checkreturn="true" level="info" passthru="true"/>

Expand All @@ -36,12 +43,21 @@
<echo>To run drush commands against the VM, use the @${drush.aliases.local} alias.</echo>
<echo>You may pin yourself to this alias using "drush use @${drush.aliases.local}"</echo>

<exec dir="${repo.root}" command="vagrant plugin list | grep vagrant-hostsupdater" outputProperty="vagrant.hostsupdater.exists"/>
<exec dir="${repo.root}" command="vagrant" returnProperty="vagrant.exists"/>
<if>
<not><istrue value="${vagrant.hostsupdater.exists}"/></not>
<not><istrue value="${vagrant.exists}"/></not>
<then>
<echo>The vagrant-hostsupdater plugin is not installed!</echo>
<echo>The vagrant is not installed!</echo>
</then>
<else>
<exec dir="${repo.root}" command="vagrant plugin list | grep vagrant-hostsupdater" outputProperty="vagrant.hostsupdater.exists"/>
<if>
<not><istrue value="${vagrant.hostsupdater.exists}"/></not>
<then>
<echo>The vagrant-hostsupdater plugin is not installed!</echo>
</then>
</if>
</else>
</if>
</target>

Expand Down
23 changes: 19 additions & 4 deletions scripts/blt/install-alias.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

if [ "`basename "/$SHELL"`" = "zsh" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile"
fi
Expand All @@ -23,11 +23,23 @@ if [ ! -z "$DETECTED_PROFILE" ]; then
exit
fi

while getopts ":y" arg; do
case $arg in
y)
REPLY=y
;;
esac
done

echo ""
echo "BLT can automatically create a Bash alias to make it easier to run BLT tasks."
echo "This alias may be created in .bash_profile or .bashrc depending on your system architecture."
echo ""
read -p "Install alias? (y/n)" -n 1 -r
echo ""

if [ -z $REPLY ]; then
read -p "Install alias? (y/n)" -n 1 -r
echo ""
fi

if [[ $REPLY =~ ^[Yy]$ ]]; then
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
Expand All @@ -37,12 +49,15 @@ if [ ! -z "$DETECTED_PROFILE" ]; then
echo "You may now use the 'blt' command from anywhere within a BLT-generated repository."
echo ""
echo "Restart your terminal session or run 'source $DETECTED_PROFILE' to use the new command."
exit
else
echo "Error: Could not modify $DETECTED_PROFILE."
exit 1
fi

fi

else
echo "Could not install blt alias. No profile found. Tried ~/.zshrc, ~/.bashrc, ~/.bash_profile and ~/.profile."
exit 1
fi
5 changes: 4 additions & 1 deletion scripts/blt/rsync-include-if-does-not-exist.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# These files will be included if they do not yet exist. They will not overwrite
# These files from template dir will be included if they do not yet exist. They will not overwrite
# existing files.
project.yml
composer.json
README.md
drush/site-aliases/aliases.drushrc.php
2 changes: 0 additions & 2 deletions scripts/drupal-vm/drupal-vm.aliases.drushrc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<?php

// [vagrant_machine_name].local
$aliases['${project.machine_name}.local'] = array(
// /var/www/[vagrant_machine_name]/docroot
Expand Down
Loading