コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function run(JobInterface $job, $data)
 {
     // Data format:
     // i) array('patch_file' => '...', 'patch_dir' => '...')
     // or
     // iii) array(array(...), array(...))
     // Normalize data to the third format, if necessary
     $data = count($data) == count($data, COUNT_RECURSIVE) ? [$data] : $data;
     $job->getOutput()->writeln("<info>Entering setup_patch().</info>");
     foreach ($data as $key => $details) {
         if (empty($details['patch_file'])) {
             $job->errorOutput("Error", "No valid patch file provided for the patch command.");
             return;
         }
         $workingdir = realpath($job->getWorkingDir());
         $patchfile = $details['patch_file'];
         $patchdir = !empty($details['patch_dir']) ? $details['patch_dir'] : $workingdir;
         // Validate target directory.
         if (!($directory = $this->validate_directory($job, $patchdir))) {
             // Invalid checkout directory
             $job->errorOutput("Error", "The patch directory <info>{$directory}</info> is invalid.");
             return;
         }
         $cmd = "patch -p1 -i {$patchfile} -d {$directory}";
         exec($cmd, $cmdoutput, $result);
         if ($result !== 0) {
             // The command threw an error.
             $job->errorOutput("Patch failed", "The patch attempt returned an error.");
             $job->getOutput()->writeln($cmdoutput);
             // TODO: Pass on the actual return value for the patch attempt
             return;
         }
         $job->getOutput()->writeln("<comment>Patch <options=bold>{$patchfile}</options=bold> applied to directory <options=bold>{$directory}</options=bold></comment>");
     }
 }
コード例 #2
0
 protected function setupCheckoutGit(JobInterface $job, $details)
 {
     $job->getOutput()->writeln("<info>Entering setup_checkout_git().</info>");
     $repo = isset($details['repo']) ? $details['repo'] : 'git://drupalcode.org/project/drupal.git';
     $gitbranch = isset($details['branch']) ? $details['branch'] : 'master';
     $gitdepth = isset($details['depth']) ? $details['depth'] : NULL;
     $workingdir = $job->getWorkingDir();
     $checkoutdir = isset($details['checkout_dir']) ? $details['checkout_dir'] : $workingdir;
     // TODO: Ensure we don't end up with double slashes
     // Validate target directory.  Must be within workingdir.
     if (!($directory = $this->validate_directory($job, $checkoutdir))) {
         // Invalid checkout directory
         $job->errorOutput("Error", "The checkout directory <info>{$directory}</info> is invalid.");
         return;
     }
     $job->getOutput()->writeln("<comment>Performing git checkout of {$repo} {$gitbranch} branch to {$directory}.</comment>");
     $cmd = "git clone -b {$gitbranch} {$repo} {$directory}";
     if (!is_null($gitdepth)) {
         $cmd .= " --depth={$gitdepth}";
     }
     exec($cmd, $cmdoutput, $result);
     if ($result !== 0) {
         // Git threw an error.
         $job->errorOutput("Checkout failed", "The git checkout returned an error.");
         // TODO: Pass on the actual return value for the git checkout
         return;
     }
     $job->getOutput()->writeln("<comment>Checkout complete.</comment>");
 }
コード例 #3
0
 protected function buildImageNames($data, JobInterface $job)
 {
     $images = [];
     foreach ($data as $key => $php_version) {
         $images["web-{$php_version}"]['image'] = "drupalci/web-{$php_version}";
         $job->getOutput()->writeln("<info>Adding image: <options=bold>drupalci/web-{$php_version}</options=bold></info>");
     }
     return $images;
 }
コード例 #4
0
 public function validateImageNames($containers, JobInterface $job)
 {
     // Verify that the appropriate container images exist
     $job->getOutput()->writeln("<comment>Validating container images exist</comment>");
     $docker = $job->getDocker();
     $manager = $docker->getImageManager();
     foreach ($containers as $key => $image_name) {
         $name = $image_name['image'];
         try {
             $image = $manager->find($name);
         } catch (ImageNotFoundException $e) {
             $job->errorOutput("Failed", "Required container image <options=bold>'{$name}'</options=bold> not found.");
             // TODO: Robust error handling.
             return FALSE;
         }
         $id = substr($image->getID(), 0, 8);
         $job->getOutput()->writeln("<comment>Found image <options=bold>{$name}</options=bold> with ID <options=bold>{$id}</options=bold></comment>");
     }
     return TRUE;
 }
コード例 #5
0
 public function setupCodebase(JobInterface $job)
 {
     $arguments = $job->getBuildVars();
     // Check if the source codebase directory has been specified
     if (empty($arguments['DCI_CodeBase'])) {
         // If no explicit codebase provided, assume we are using the code in the local directory.
         $arguments['DCI_CodeBase'] = "./";
         $job->setBuildVars($arguments);
     } else {
         $job->getOutput()->writeln("<comment>Using codebase directory defined in DCI_CodeBase: <options=bold>{$arguments['DCI_CodeBase']}</options=bold></comment>");
     }
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function run(JobInterface $job, $data)
 {
     // Data format: 'command [arguments]' or array('command [arguments]', 'command [arguments]')
     // $data May be a string if one version required, or array if multiple
     // Normalize data to the array format, if necessary
     $data = is_array($data) ? $data : [$data];
     $docker = $job->getDocker();
     $manager = $docker->getContainerManager();
     if (!empty($data)) {
         // Check that we have a container to execute on
         $configs = $job->getExecContainers();
         foreach ($configs as $type => $containers) {
             foreach ($containers as $container) {
                 $id = $container['id'];
                 $instance = $manager->find($id);
                 $short_id = substr($id, 0, 8);
                 $job->getOutput()->writeln("<info>Executing on container instance {$short_id}:</info>");
                 foreach ($data as $cmd) {
                     $job->getOutput()->writeln("<fg=magenta>{$cmd}</fg=magenta>");
                     $exec = explode(" ", $cmd);
                     $exec_id = $manager->exec($instance, $exec, TRUE, TRUE, TRUE, TRUE);
                     $job->getOutput()->writeln("<info>Command created as exec id " . substr($exec_id, 0, 8) . "</info>");
                     $result = $manager->execstart($exec_id, function ($output, $type) use($job) {
                         if ($type === 1) {
                             $job->getOutput()->writeln("<info>{$output}</info>");
                         } else {
                             $job->errorOutput('Error', $output);
                         }
                     });
                     //Response stream is never read you need to simulate a wait in order to get output
                     $result->getBody()->getContents();
                     $job->getOutput()->writeln((string) $result);
                 }
             }
         }
     }
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function run(JobInterface $job, $data)
 {
     // Data format:
     // i) array('url' => '...', 'fetch_dir' => '...')
     // or
     // iii) array(array(...), array(...))
     // Normalize data to the third format, if necessary
     $data = count($data) == count($data, COUNT_RECURSIVE) ? [$data] : $data;
     $job->getOutput()->writeln("<info>Entering setup_fetch().</info>");
     foreach ($data as $key => $details) {
         // URL and target directory
         // TODO: Ensure $details contains all required parameters
         if (empty($details['url'])) {
             $job->errorOutput("Error", "No valid target file provided for fetch command.");
             return;
         }
         $url = $details['url'];
         $workingdir = realpath($job->getWorkingDir());
         $fetchdir = !empty($details['fetch_dir']) ? $details['fetch_dir'] : $workingdir;
         if (!($directory = $this->validate_directory($job, $fetchdir))) {
             // Invalid checkout directory
             $job->errorOutput("Error", "The fetch directory <info>{$directory}</info> is invalid.");
             return;
         }
         $info = pathinfo($url);
         $destfile = $directory . "/" . $info['basename'];
         $contents = file_get_contents($url);
         if ($contents === FALSE) {
             $job->errorOutput("Error", "An error was encountered while attempting to fetch <info>{$url}</info>.");
             return;
         }
         if (file_put_contents($destfile, $contents) === FALSE) {
             $job->errorOutput("Error", "An error was encountered while attempting to write <info>{$url}</info> to <info>{$directory}</info>");
             return;
         }
         $job->getOutput()->writeln("<comment>Fetch of <options=bold>{$url}</options=bold> to <options=bold>{$destfile}</options=bold> complete.</comment>");
     }
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function run(JobInterface $job, $data = NULL)
 {
     // Get and parse test definitions
     // DrupalCI jobs are controlled via a hierarchy of configuration settings, which define the behaviour of the platform while running DrupalCI jobs.  This hierarchy is defined as follows, which each level overriding the previous:
     // 1. Out-of-the-box DrupalCI defaults
     // 2. Local overrides defined in ~/.drupalci/config
     // 3. 'DCI_' namespaced environment variable overrides
     // 4. Test-specific overrides passed inside a DrupalCI test definition (e.g. .drupalci.yml)
     // 5. Custom overrides located inside a test definition defined via the $source variable when calling this function.
     $confighelper = new ConfigHelper();
     // Load job defaults
     $platform_args = $job->getPlatformDefaults();
     $default_args = $job->getDefaultArguments();
     if (!empty($default_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables for this job type.</comment>");
     }
     // Load DrupalCI local config overrides
     $local_args = $confighelper->getCurrentConfigSetParsed();
     if (!empty($local_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables from DrupalCI local config overrides.</comment>");
     }
     // Load "DCI_ namespaced" environment variable overrides
     $environment_args = $confighelper->getCurrentEnvVars();
     if (!empty($environment_args)) {
         $job->getOutput()->writeln("<comment>Loading build variables from namespaced environment variable overrides.</comment>");
     }
     // Load command line arguments
     // TODO: Routine for loading command line arguments.
     // TODO: How do we pull arguments off the drupalci command, when in a job class?
     // $cli_args = $somehelper->loadCLIargs();
     $cli_args = array();
     if (!empty($cli_args)) {
         $job->getOutput()->writeln("<comment>Loading test parameters from command line arguments.</comment>");
     }
     // Create temporary config array to use in determining the definition file source
     $config = $cli_args + $environment_args + $local_args + $default_args + $platform_args;
     // Load any build vars defined in the job definition file
     // Retrieve test definition file
     if (isset($source)) {
         $config['explicit_source'] = $source;
     }
     $definition_file = $this->getDefinitionFile($config);
     $definition_args = array();
     // Load test definition file
     if (!empty($definition_file)) {
         $job->getOutput()->writeln("<comment>Loading test parameters from build file: </comment><info>{$definition_file}</info>");
         $jobdef = new JobDefinition();
         $result = $jobdef->load($definition_file);
         if ($result == -1) {
             // Error loading definition file.
             $job->errorOutput("Failed", "Unable to parse build file.");
             // TODO: Robust error handling
             return;
         }
         $job_definition = $jobdef->getParameters();
         if (empty($job_definition)) {
             $job_definition = array();
             $definition_args = array();
         } else {
             $definition_args = !empty($job_definition['build_vars']) ? $job_definition['build_vars'] : array();
         }
         $job->setDefinition($job_definition);
     }
     $config = $cli_args + $definition_args + $environment_args + $local_args + $default_args + $platform_args;
     // Set initial build variables
     $buildvars = $job->getBuildVars();
     $job->setBuildVars($buildvars + $config);
     // Map relevant build variables into the job definition array
     // $this->buildvarsToDefinition($job);
     return;
 }