diff --git a/README.md b/README.md index d02df85..47d447c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,13 @@ run.config: ## Composer This engine uses [Composer](https://getcomposer.org) to manage dependencies. If a composer.json file exists at the root of your application, dependencies will be fetched during a build. +The composer install command can be customized during the build process using a setting in the boxfile.yml. +```yaml +run.config: + engine: php + engine.config: + composer_install: "composer install --no-interaction --prefer-source" +``` ## Basic Configuration diff --git a/doc/advanced-php-config.md b/doc/advanced-php-config.md index 06a0df1..0097fa5 100644 --- a/doc/advanced-php-config.md +++ b/doc/advanced-php-config.md @@ -50,6 +50,9 @@ run.config: session_autostart: false date_timezone: 'US/central' iconv_internal_encoding: 'UTF-8' + + # Composer Settings + composer_install: 'composer install --no-interaction --prefer-source' # Apache Settings apache_version: 2.2 @@ -155,6 +158,7 @@ run.config: ##### Quick Links [Web Server Settings](#web-server-settings) [PHP Settings](#php-settings) +[Composer Settings](#composer-settings) [Apache Settings](#apache-settings) [Nginx Settings](#nginx-settings) [Built-In PHP Web Server Settings](#built-in-php-web-server-settings) @@ -581,6 +585,25 @@ run.config: --- +### Composer Settings +The following settings allow you to customize how [Composer](https://getcomposer.org/) is used in your application. + +[composer_install](#composer_install) + +--- + +#### composer_install +Customize the `composer install` command that is run in your app's build process. + +``` +run.config: + engine: php + engine.config: + composer_install: 'composer install --no-interaction --prefer-source' +``` + +--- + ### Apache Settings The following settings are used to configure Apache. These only apply when using `apache` as your `webserver`. diff --git a/lib/php/composer.sh b/lib/php/composer.sh index 6ba8259..40e8eef 100644 --- a/lib/php/composer.sh +++ b/lib/php/composer.sh @@ -12,12 +12,18 @@ composer_required_extensions() { echo "${exts[@]}" } +composer_install_command() { + # boxfile composer_install + composer_install_command=$(nos_validate "$(nos_payload config_composer_install)" "string" "composer install --no-interaction --prefer-source") + echo "$composer_install_command" +} + # Runs composer install composer_install() { if [[ -f $(nos_code_dir)/composer.json ]]; then if [[ ! -f $(nos_code_dir)/composer.lock ]]; then nos_print_warning "No 'composer.lock' file detected. This may cause a slow or failed build. To avoid this issue, commit the 'composer.lock' file to your git repo." fi - (cd $(nos_code_dir); nos_run_process "composer install" "composer install --no-interaction --prefer-source") + (cd $(nos_code_dir); nos_run_process "composer install" "$(composer_install_command)") fi } diff --git a/test/tests/integration/extensions2.bats b/test/tests/integration/extensions2.bats new file mode 100644 index 0000000..d70ed02 --- /dev/null +++ b/test/tests/integration/extensions2.bats @@ -0,0 +1,157 @@ +# Integration test for a simple go app + +# source environment helpers +. util/env.sh + +payload() { + cat <<-END +{ + "code_dir": "/tmp/code", + "data_dir": "/data", + "app_dir": "/tmp/app", + "cache_dir": "/tmp/cache", + "etc_dir": "/data/etc", + "env_dir": "/data/etc/env.d", + "config": {"runtime": "php-5.6","extensions": ["phar","json","filter","hash","mongo"],"dev_zend_extensions":{"add":["xdebug"]}} +} +END +} + +setup() { + # cd into the engine bin dir + cd /engine/bin +} + +@test "setup" { + # prepare environment (create directories etc) + prepare_environment + + # prepare pkgsrc + run prepare_pkgsrc + + # create the code_dir + mkdir -p /tmp/code + + # copy the app into place + cp -ar /test/apps/phpinfo/* /tmp/code + + run pwd + + [ "$output" = "/engine/bin" ] +} + +@test "boxfile" { + if [[ ! -f /engine/bin/boxfile ]]; then + skip "No boxfile script" + fi + run /engine/bin/boxfile "$(payload)" + + echo "$output" + + [ "$status" -eq 0 ] +} + +@test "build" { + if [[ ! -f /engine/bin/build ]]; then + skip "No build script" + fi + run /engine/bin/build "$(payload)" + + echo "$output" + + [ "$status" -eq 0 ] + + echo "prod" + ls /data/etc/php.prod.d + echo "dev" + ls /data/etc/php.dev.d + + [ ! -f "/data/etc/php.prod.d/xdebug.ini" ] + [ -f "/data/etc/php.dev.d/xdebug.ini" ] +} + +@test "compile" { + if [[ ! -f /engine/bin/compile ]]; then + skip "No compile script" + fi + run /engine/bin/compile "$(payload)" + + echo "$output" + + [ "$status" -eq 0 ] +} + +@test "cleanup" { + if [[ ! -f /engine/bin/cleanup ]]; then + skip "No cleanup script" + fi + run /engine/bin/cleanup "$(payload)" + + echo "$output" + + [ "$status" -eq 0 ] +} + +@test "release" { + if [[ ! -f /engine/bin/release ]]; then + skip "No release script" + fi + run /engine/bin/release "$(payload)" + + echo "$output" + + [ "$status" -eq 0 ] +} + +@test "verify" { + # remove the code dir + rm -rf /tmp/code + + # mv the app_dir to code_dir + mv /tmp/app /tmp/code + + # cd into the app code_dir + cd /tmp/code + + # start php-fpm + # /data/bin/start-php & + + # start apache + # /data/bin/start-apache & + php-server & + + # sleep a few seconds so the server can start + sleep 3 + + # curl the index + run curl -s 127.0.0.1:8080 2>/dev/null + + # kill the server + # pkill php-fpm + pkill php-server + + + echo "$output" + + [[ "$output" =~ "phpinfo()" ]] + + # start php-fpm + # APP_NAME=dev /data/bin/start-php & + APP_NAME=dev php-server & + + sleep 3 + + # curl the index + run curl -s 127.0.0.1:8080 2>/dev/null + + # kill the server + # pkill php-fpm + + # pkill httpd + pkill php-server + + echo "$output" + + [[ "$output" =~ "phpinfo()" ]] + [[ "$output" =~ "xdebug" ]] +}