Skip to content
This repository has been archived by the owner on May 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request nanobox-io#94 from nanobox-io/feature/custom-composer
Browse files Browse the repository at this point in the history
Feature/custom composer, resolves nanobox-io#94
  • Loading branch information
sanderson authored Mar 14, 2018
2 parents 1882bb5 + 2d0819e commit adfe827
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions doc/advanced-php-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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`.
Expand Down
8 changes: 7 additions & 1 deletion lib/php/composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
157 changes: 157 additions & 0 deletions test/tests/integration/extensions2.bats
Original file line number Diff line number Diff line change
@@ -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" ]]
}

0 comments on commit adfe827

Please sign in to comment.