mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	Merge pull request #184 from edpauto/env-vars-support
Environment variables support
This commit is contained in:
		
						commit
						7f0cab1a38
					
				@ -222,6 +222,7 @@ abstract class AbstractTask
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    final protected function runCommand($command, &$output = null)
 | 
					    final protected function runCommand($command, &$output = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        $command = ltrim($this->getEnvVarsString() . ' ' . $command);
 | 
				
			||||||
        if ($this->getStage() == self::STAGE_DEPLOY || $this->getStage() == self::STAGE_POST_RELEASE) {
 | 
					        if ($this->getStage() == self::STAGE_DEPLOY || $this->getStage() == self::STAGE_POST_RELEASE) {
 | 
				
			||||||
            return $this->runCommandRemote($command, $output);
 | 
					            return $this->runCommandRemote($command, $output);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
@ -305,4 +306,56 @@ abstract class AbstractTask
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return $result;
 | 
					        return $result;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Returns the array of environment variables
 | 
				
			||||||
 | 
					     * Returned array contains both system variables and variables set in config
 | 
				
			||||||
 | 
					     * WARNING: To access system's variables you need to set proper value in your php.ini at variables_order key
 | 
				
			||||||
 | 
					     * @see http://php.net/manual/en/ini.core.php#ini.variables-order
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return array
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected function getEnvVariables()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $configVars = array_merge(
 | 
				
			||||||
 | 
					            $this->getConfig()->general('env', []),
 | 
				
			||||||
 | 
					            $this->getConfig()->environmentConfig('env', []),
 | 
				
			||||||
 | 
					            $this->getConfig()->getParameter('env', []),
 | 
				
			||||||
 | 
					            [
 | 
				
			||||||
 | 
					                'variables' => $this->getConfig()->getParameter('env.variables', [])
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (isset($configVars['variables'])) {
 | 
				
			||||||
 | 
					            $configVars = $configVars['variables'];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $envVariables = array_merge(
 | 
				
			||||||
 | 
					            $_ENV,
 | 
				
			||||||
 | 
					            $configVars
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $envVariables;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Returns ready to inject environment string
 | 
				
			||||||
 | 
					     * The string is build from env vars array in schema:
 | 
				
			||||||
 | 
					     *  key1=value1 key2=value3 ...
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return string
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected function getEnvVarsString()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $envVarsArray = $this->getEnvVariables();
 | 
				
			||||||
 | 
					        $envVars = array_map(
 | 
				
			||||||
 | 
					            function ($key, $value) {
 | 
				
			||||||
 | 
					                return "$key=$value";
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            array_keys($envVarsArray),
 | 
				
			||||||
 | 
					            $this->getEnvVariables()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return join(' ', $envVars);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -22,3 +22,6 @@ tasks:
 | 
				
			|||||||
    - sampleTask
 | 
					    - sampleTask
 | 
				
			||||||
    - sampleTaskRollbackAware
 | 
					    - sampleTaskRollbackAware
 | 
				
			||||||
verbose_logging: true
 | 
					verbose_logging: true
 | 
				
			||||||
 | 
					env:
 | 
				
			||||||
 | 
					  variables:
 | 
				
			||||||
 | 
					    symfony_env: prod
 | 
				
			||||||
 | 
				
			|||||||
@ -7,3 +7,7 @@ verbose_logging: false
 | 
				
			|||||||
scm:
 | 
					scm:
 | 
				
			||||||
  type: git
 | 
					  type: git
 | 
				
			||||||
  url:  git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git
 | 
					  url:  git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git
 | 
				
			||||||
 | 
					env:
 | 
				
			||||||
 | 
					  variables:
 | 
				
			||||||
 | 
					    node_path: "/bin/node"
 | 
				
			||||||
 | 
					    symfony_env: prod
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user