Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Composer on Azure Websites
[config]
command = "D:\Program Files (x86)\PHP\v5.3\php.exe" build_azure.php

Composer on Azure Websites

Pending this Pull Request https://github.com/composer/composer/pull/1341 you can make Composer run on Azure as post deployment command.

The way Azure Websites works, this doesn't affect your site at all. The composer installation is run, and after that completed successfully, the webroot is symlinked to the new checkout.

To get this working before the PR is merged, checkout my composer fork, call ./bin/compile and use the generated composer.phar file as part of your git repository.

<?php
if (!file_exists("composer.phar")) {
$url = 'https://getcomposer.org/composer.phar';
file_put_contents("composer.phar", file_get_contents($url));
}
register_shutdown_function('copyFiles');
$_SERVER['argv'][1] = "update";
$_SERVER['argv'][2] = "--prefer-dist";
$_SERVER['argv'][3] = "-v";
require "composer.phar";
function copyFiles()
{
if (!isset($_SERVER['DEPLOYMENT_TARGET'])) {
echo "Cannot find pyhsical path to application root.\n";
echo "There should be an 'DEPLOYMENT_TARGET' env variable.\n";
exit(1);
}
echo "Copying code to webroot\n";
copyDirectory($_SERVER['DEPLOYMENT_SOURCE'], $_SERVER['DEPLOYMENT_TARGET']);
}
function copyDirectory($source, $target)
{
$it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
if ( !file_exists($target)) {
mkdir($target, 0777, true);
}
foreach ($ri as $file) {
$targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
if ($file->isDir()) {
if ( ! file_exists($targetPath)) {
mkdir($targetPath);
}
} else if (!file_exists($targetPath) || filemtime($targetPath) < filemtime($file->getPathname())) {
copy($file->getPathname(), $targetPath);
}
}
}
@davidfowl

This comment has been minimized.

Show comment Hide comment
@davidfowl

davidfowl Nov 19, 2012

Instead of hardcoding "D:\Program Files (x86)" I you should be able to use environment variables like %ProgramFiles(x86)%

Instead of hardcoding "D:\Program Files (x86)" I you should be able to use environment variables like %ProgramFiles(x86)%

@beberlei

This comment has been minimized.

Show comment Hide comment
@beberlei

beberlei Nov 19, 2012

@davidfowl Thanks for the suggestion, but

command = "%ProgramFiles(x86)%\PHP\v5.3\php.exe" azurecomposer.php

fails with:

remote: 'D:\Program' is not recognized as an internal or external command,

So even if i escape with " - it gets borked by the space.

Owner

beberlei commented Nov 19, 2012

@davidfowl Thanks for the suggestion, but

command = "%ProgramFiles(x86)%\PHP\v5.3\php.exe" azurecomposer.php

fails with:

remote: 'D:\Program' is not recognized as an internal or external command,

So even if i escape with " - it gets borked by the space.

@beberlei

This comment has been minimized.

Show comment Hide comment
@beberlei

beberlei Nov 19, 2012

Added a ticket on kudu: projectkudu/kudu#221

Owner

beberlei commented Nov 19, 2012

Added a ticket on kudu: projectkudu/kudu#221

@beberlei

This comment has been minimized.

Show comment Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment