php - Correlating list properties in phing -


i have automated deployment system working using phing. adding second server , need modify deployment target in order handle this. issue paths deploy between 2 servers not same, i'm not sure how associate current deploy server path need deploy to.

in main phing.xml file, set properties:

<property name="deploy.servers.production"    value="server1.com,server2.com" /> <property name="deploy.path.production"       value="/path/on/server1,/path/on/server2" /> 

during build, have foreach element iterates on different servers , calls upload task setting them property:

<foreach list="${deploy.servers.production}" param="deploy.server" target="deploy.deliver" /> 

the problem have can't find a way associate path need deliver server i'm deploying to. avoid having have separate properties each server, this:

<property name="deploy.servers.production1"    value="server1.com" /> <property name="deploy.servers.production2"    value="server2.com" /> <property name="deploy.path.production1"       value="/path/on/server1" /> <property name="deploy.path.production2"       value="/path/on/server2" /> 

is there way have 2 separate list properties in phing correlate 1 another?

i wound having write 2 custom phing tasks this. 1 of them adding of feature foreach task, added gist on github here. other 1 simpler task used retrieve item in delimited list property index, added gist here. importing these tasks works this:

<includepath    classpath="${base.dir}${ds}tasks${ds}" /> <taskdef name="foreachkey"      classname="foreachkeytask" /> <taskdef name="listitembykey"   classname="listitembykeytask" />  <property name="deploy.targets.production"          value="server1,server2,server3" /> <property name="deploy.users.production"            value="user1,user2,user3" /> <property name="deploy.privatekeys.production"      value=".ssh/key1_rsa,.ssh/key2_rsa,.ssh/key3_rsa" /> <property name="deploy.publickeys.production"       value=".ssh/key1_rsa.pub,.ssh/key2_rsa.pub,.ssh/key3_rsa.pub" /> <property name="deploy.paths.production"            value="/path/on/server1,/path/on/server2,/path/on/server3" /> 

the list of servers iterated on using <foreach> task, minor addition of adding property name keep track of current index:

<foreachkey list="deploy.targets" key="currentindex" param="deploy.server" target="install" /> 

the callee has 2 properties can access, deploy.server current value in list of target servers, , currentindex references current index in list. using this, can other associated values:

<-- properties above aliased these properties when target environment selected --> <listitembykey key="currentindex" property="deploy.users" returnval="user" /> <listitembykey key="currentindex" property="deploy.privatekeys" returnval="privatekey" /> <listitembykey key="currentindex" property="deploy.publickeys" returnval="publickey" /> <listitembykey key="currentindex" property="deploy.paths" returnval="path" />  <!-- properties available hold current credential information related       current deployment target:         user, privatekey, publickey, passphrase, path -->  <!-- , can used execute ssh commands... -->  <netssh username="${user}"     pubkeyfile="${publickey}"     privkeyfile="${privatekey}"     host="${deploy.server}"     sshlib="${deploy.sshlib}"     command="mkdir -p ${path}${ds}${deploy.releasedir}${ds}${deploy.ts}" /> 

the downside approach have keep associated data in same indices. if username (or keys, or paths) between server1 , server2 same, still have list twice (in case different).


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -