echo "Was able to make receiveWork call on SQS '{$queueUrl}' without error\n\n"; } catch (Exception $e) { shutDown("Error when attempting to access and/or receive work from SQS: '{$queueUrl}'" . ". Error message: {$e->getMessage()}"); } $cli = new \Io\Samk\AmiBuilder\Utils\Cli($logger, ["patterns" => ['/(aws_access_key)=([\\w\\+]+)(.*)/', '/(aws_secret_key)=([\\w\\+]+)(.*)/'], "replacements" => '$1=<$1>$3']); /** * Test Github connectivity */ try { echo "2. Checking git hub template repo connectivity\n\n"; $templatesConfig = $config->get('templates', true); $templatesRepo = $templatesConfig['templatesRepo']; $templatesCheckoutPath = $templatesConfig['checkoutPath']; if (!file_exists($templatesCheckoutPath)) { echo "Template repo not found locally, attempting Clone of repo '{$templatesRepo}' to local dir '{$templatesCheckoutPath}'...\n"; list($output, $returnCode) = $cli->execute("git clone {$templatesRepo} {$templatesCheckoutPath}"); checkCliResponse($output, $returnCode); } else { echo "Local checkout of template repo '{$templatesRepo}', exists at '{$templatesCheckoutPath}', attempting git fetch...\n"; list($output, $returnCode) = $cli->execute('git fetch --all', $templatesCheckoutPath); checkCliResponse($output, $returnCode); } } catch (Exception $e) { shutDown("Error when attempting to access Githup repo: '{$templatesRepo}'" . ". Error message: {$e->getMessage()}"); } /** * Test S3 connectivity */ try { /** @var \Aws\S3\S3Client $s3Client */ $s3Client = $aws->get('S3');
} $executionMetrics['jobMessage'] = $message; // a lot of unneeded characters for digest message unset($executionMetrics['jobMessage']['ReceiptHandle']); $executionMetrics['jobBuildTemplate'] = $template; $executionMetrics['jobBuildTemplateSha'] = $templateSha; $logger->info("Found Work, request for template '{$template}' @ SHA '{$templateSha}'"); $cli = new \Io\Samk\AmiBuilder\Utils\Cli($logger, ["patterns" => ['/(aws_access_key)=([\\w\\+]+)(.*)/', '/(aws_secret_key)=([\\w\\+]+)(.*)/'], "replacements" => '$1=<$1>$3']); /** * update template checkout */ $templatesConfig = $config->get('templates'); $templatesRepo = $templatesConfig['templatesRepo']; $templatesCheckoutPath = $templatesConfig['checkoutPath']; if (!file_exists($templatesCheckoutPath)) { list($output, $returnCode) = $cli->execute("git clone {$templatesRepo} {$templatesCheckoutPath}"); } $logger->info("checking out local packer templates repo '{$templatesCheckoutPath}' to SHA '{$templateSha}'"); list($output, $returnCode) = $cli->execute('git fetch --all', $templatesCheckoutPath); list($output, $returnCode) = $cli->execute("git reset --hard origin/master", $templatesCheckoutPath); list($output, $returnCode) = $cli->execute("git checkout {$templateSha}", $templatesCheckoutPath); /** * Run packer and capture image region and name */ $pathToTemplate = trim("{$templatesCheckoutPath}/{$template}"); if (!file_exists($pathToTemplate)) { $logger->error("Path to build template not exists and/or not readable: '{$pathToTemplate}'"); shutDown("Path to build template not exists and/or not readable: '{$pathToTemplate}'"); } $packerConfig = $config->get('packer'); list($result, $returnCode) = $cli->runPackerBuild($packerConfig['executablePath'], $pathToTemplate, isset($packerConfig['awsAccessKey']) ? $packerConfig['awsAccessKey'] : null, isset($packerConfig['awsSecretKey']) ? $packerConfig['awsSecretKey'] : null);