Skip to content

Commit a8a9498

Browse files
author
Slavey Karadzhov
committed
Merge branch 'composer-advanced'
2 parents 1016c0f + 38ca736 commit a8a9498

File tree

10 files changed

+829
-82
lines changed

10 files changed

+829
-82
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.phar
2+
composer.lock
3+
vendor/

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ It will output the name of the newly created package file. You have to use this
136136
or update an existing application on Zend Server. If you want to use other name for
137137
the output file you can use the --name="{desired-zpk-name}" option.
138138

139+
#### Composer Integration ####
140+
There is experimental integration with composer that allows you to download the dependant packages, as described in composer.json,
141+
download them and convert them to zpk files. The above command with composer integration will look like this
142+
143+
```
144+
php bin/zs-client.php packZpk --folder="<folder-where-the-PHP-code-is>" \
145+
--destination="<folder-where-the-package-will-be-created>" \
146+
--composer
147+
```
148+
The result from the command will be list of packages in the order that they have to be installed (top first, bottom last).
149+
Example:
150+
151+
/tmp/zendframework.zend-stdlib-2.2.4.zpk
152+
/tmp/zendframework.zend-console-2.2.4.zpk
153+
/tmp/zendframework.zend-file-2.2.4.zpk
154+
/tmp/zendframework.zend-mvc-2.2.4.zpk
155+
/tmp/zendframework.zend-text-2.2.4.zpk
156+
/tmp/zendframework.zend-math-2.2.4.zpk
157+
/tmp/zendframework.zend-json-2.2.4.zpk
158+
/tmp/zendframework.zend-serializer-2.2.4.zpk
159+
/tmp/zenddevops.webapi-dev-dev.zpk
160+
/tmp/AddYourUniqueApplicationName-1.0.0.zpk
161+
139162
### Deploy Package
140163
Run the following command to install a package.
141164
```
@@ -153,6 +176,22 @@ php bin/zs-client.php installApp --zpk="<location-of-the-zpk-file>" \
153176
--baseUri="<baseUri>" \
154177
--userParams="APPLICATION_ENV=staging&DB_TYPE=mysql"
155178
```
179+
#### Deploy Multiple Packages
180+
If you use the composer integration then packZpk can create multiple packages, instead of one. Below is a suggestion how you can
181+
deploy these newly created packages in the correct order.
182+
183+
```
184+
ZPKS=`php bin/zs-client.php packZpk --folder="<folder-where-the-PHP-code-is>" \
185+
--destination="<folder-where-the-package-will-be-created>" \
186+
--composer`;
187+
188+
for i in $ZPKS; do
189+
php bin/zs-client.php installApp --zpk="$i" \
190+
--target="<the-name-of-the-target>" \
191+
--baseUri="<baseUri>" \
192+
--userParams="APPLICATION_ENV=staging&DB_TYPE=mysql"
193+
done;
194+
```
156195

157196
HTTP tuning
158197
============
@@ -171,6 +210,12 @@ php bin/zs-client.php getSystemInfo --target="<name-of-the-target> \
171210
In most cases the HTTPS access to your Zend Server will use self-signed certificate.
172211
In order to instruct the client to accept the SSL certificate you can do the following.
173212

213+
```
214+
php bin/zs-client.php getSystemInfo --target="<name-of-the-target> \
215+
--http="sslverify=0"
216+
217+
```
218+
174219
### Combining Multiple HTTP options
175220
If you want to combine multiple HTTP options in the same request then you can format the value of the http parameter as a valid
176221
HTTP query string. Request with timeout of 40 seconds and acceptance of self-signed certificates will look like this.

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
"require" : {
2323
"php" : ">=5.3.3",
2424
"openlss/lib-array2xml" : "dev-master",
25-
"zenddevops/webapi" : "dev-master"
25+
"zenddevops/webapi" : "dev-master",
26+
"mustangostang/spyc" : "dev-master"
2627
},
2728
"require-dev" : {
2829
"phpunit/phpunit" : "3.7.*",
29-
"zendframework/zendframework" : "2.*"
30+
"zendframework/zendframework" : "2.2.*"
3031
},
3132
"autoload" : {
3233
"psr-0" : {

module/Client/Module.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,14 @@ public function postRoute (MvcEvent $event)
114114
$path = $services->get('path');
115115
foreach ($config['console']['router']['routes'][$routeName]['options']['files'] as $param) {
116116
if ($value = $match->getParam($param)) {
117-
$match->setParam($param, $path->getAbsolute($value));
117+
if (!is_array($value)) {
118+
$match->setParam($param, $path->getAbsolute($value));
119+
} else {
120+
$newValue = array_map(function($v) use ($path) {
121+
return $path->getAbsolute($v);
122+
}, $value);
123+
$match->setParam($param,$newValue);
124+
}
118125
}
119126
}
120127
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
// Start: AutoGenerated from @ZendServerClient
3+
4+
// Map back all composer env variables.
5+
foreach ($_ENV as $key=> $value) {
6+
if (0 === ($pos = strpos($key, 'ZS_COMPOSER_'))) {
7+
putenv(substr($key, $pos),$value);
8+
}
9+
}
10+
11+
###libLines###
12+
13+
copy(__DIR__ . '/composer.json', getenv('ZS_APPLICATION_BASE_DIR') . '/composer.json');
14+
$cwd = getcwd();
15+
chdir(__DIR__);
16+
17+
$phpBin = "/usr/local/zend/bin/php";
18+
if (defined('PHP_BINARY')) {
19+
$phpBin = PHP_BINARY;
20+
}
21+
22+
$command = 'post-install-cmd';
23+
if (getenv('ZS_PREVIOUS_APP_VERSION')) {
24+
$command = 'post-update-cmd';
25+
}
26+
27+
shell_exec("$phpBin composer.phar run-script $command -n -d " . getenv('ZS_APPLICATION_BASE_DIR'));
28+
unlink(getenv('ZS_APPLICATION_BASE_DIR') . '/composer.json ');
29+
chdir($cwd);
30+
// End: AutoGenerated from @ZendServerClient

module/Client/config/module.config.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
),
152152
'packZpk' => array(
153153
'options' => array (
154-
'route' => 'packZpk [--folder=] [--destination=] [--name=] [--version=]',
154+
'route' => 'packZpk [--folder=] [--destination=] [--name=] [--version=] [--composer] [--composer-options=] [--composer-dist-files=]',
155155
'defaults' => array (
156156
'controller' => 'webapi-zpk-controller',
157157
'action' => 'pack',
@@ -163,16 +163,21 @@
163163
array('--folder','Folder where the source code is located'),
164164
array('--destination','Folder in which to save the created ZPK file'),
165165
array('--name','The name of the package. If not provided the name will be constructed from the name of the application and its version.'),
166-
array('--version','The version release of the package. The version release will be replace in deployment.xml before creating ZPK package.')
166+
array('--version','The version release of the package. The version release will be replace in deployment.xml before creating ZPK package.'),
167+
array('--composer','Enables experimental composer support.'),
168+
array('--composer-options','Adds composer options when running composer'),
169+
array('--composer-dist-files', 'Comma separated list of YAML .dist files containing user parameters.'),
170+
),
171+
'arrays' => array(
172+
'composer-dist-files',
167173
),
168174
'files' => array(
169-
'folder', 'destination'
175+
'folder', 'destination','composer-dist-files',
170176
),
171177
'no-target' => true,
172178
'group' => 'packaging'
173179
),
174180
),
175-
176181
'installLib' => array (
177182
'options' => array (
178183
'route' => 'installLib --zpk= [--target=] [--zsurl=] [--zskey=] [--zssecret=] [--zsversion=]',
@@ -216,6 +221,8 @@
216221
'invokables' => array (
217222
'zpk' => 'Client\Service\ZpkInvokable',
218223
'path' => 'Client\Service\PathInvokable',
224+
'composer' => 'Client\Service\ComposerInvokable',
225+
'Composer\File' => 'Client\Service\Composer\File',
219226
)
220227
),
221228

0 commit comments

Comments
 (0)