Exemplo n.º 1
0
<?php

date_default_timezone_set('UTC');
require 'vendor/autoload.php';
require __DIR__ . '/common.php';
$executionStartTime = microtime(true);
$executionUuid = getExecutionUuid();
$executionMetrics = ["executionUuid" => $executionUuid, "startTimestamp" => $executionStartTime, "startDateTime" => date('r', $executionStartTime), "amiBuildQueueUrl" => "", "jobMessage" => null, "jobBuildTemplate" => "", "jobBuildTemplateSha" => "", "createdAmiId" => "", "createdAmiRegion" => "", "endedInError" => false, "endTimestamp" => "", "endDateTime" => "", "processingDuration" => ""];
$logger = getAppLogger($executionUuid);
$cliConfigArg = getCliArgValue($argv, '--config');
$configPath = $cliConfigArg ?: __DIR__ . "/config/config.yml";
$config = getConfig($configPath, $logger);
$aws = createAwsClient($argv, $config);
/** @var \Aws\S3\S3Client $s3Client */
$s3Client = $aws->get('S3');
$s3Client->registerStreamWrapper();
$appConfig = $config->get('appConfig');
// switch to log level in app config
$logger->setLogLevelThreshold($appConfig['logLevel']);
$sqsConfig = $config->get('sqsConfig');
/** @var \Aws\Sqs\SqsClient $sqsClient */
$sqsClient = $aws->get('sqs');
$queueUrl = $sqsConfig['amiBuildRequestQueueUrl'];
$executionMetrics['amiBuildQueueUrl'] = $queueUrl;
try {
    $work = $sqsClient->receiveMessage(["QueueUrl" => $queueUrl, "MaxNumberOfMessages" => 1, "MessageAttributeNames" => []]);
} catch (Aws\Sqs\Exception\SqsException $e) {
    $logger->error($e);
    shutDown('Error access SQS: ' . $e->getMessage());
} catch (\Exception $e) {
    $logger->error($e);
Exemplo n.º 2
0
/**
 * @param array $cliDefinitions
 * @param array $argv
 * @param \Io\Samk\AmiBuilder\Utils\Config $config
 */
function processCli($cliDefinitions, $argv, $config)
{
    foreach ($cliDefinitions as $cliArgName => $cliArgDef) {
        list($sectionKey, $itemKey) = explode('.', $cliArgDef['configKeyPath']);
        $config->setSectionValue($sectionKey, $itemKey, getCliArg($cliArgName, $argv, $cliDefinitions));
    }
}
/**
 * @param string $awsRegion
 */
function createCloudWatchLogsConfigs($awsRegion)
{
    $cloudWatchLogsConfDir = __DIR__ . '/config/cloudwatchLogs';
    $awsCliConfContent = file_get_contents("{$cloudWatchLogsConfDir}/awscli.dist.conf");
    $awsCliConfContent = str_replace('{{aws-region}}', $awsRegion, $awsCliConfContent);
    file_put_contents("{$cloudWatchLogsConfDir}/awscli.conf", $awsCliConfContent);
    // nothing to replace in this file
    copy("{$cloudWatchLogsConfDir}/awslogs.dist.conf", "{$cloudWatchLogsConfDir}/awslogs.conf");
}
$logger = getAppLogger(getExecutionUuid());
$config = getConfig(__DIR__ . '/config/config.dist.yml', $logger);
processCli($cliDefinitions, $argv, $config);
$config->dumpYamlTo(__DIR__ . "/config/config.yml");
// write the AWS CloudWatch Logs configs to ./config/cloudwatchLogs
// the deploy script will mv them to the proper place on the machine filesystem
createCloudWatchLogsConfigs(getCliArg('awsRegion', $argv, $cliDefinitions));