Skip to content

Commit

Permalink
fix: Vapor cli version update
Browse files Browse the repository at this point in the history
  • Loading branch information
SUDA Sankar committed Jan 22, 2024
2 parents 5d39e8b + 004aa61 commit a6946d8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ npm install -g serverless-dynamodb-autoscaling
npm install -g serverless-s3-sync
npm install -g serverless-plugin-scripts
npm install -g serverless-domain-manager
npm install -g serverless-lift
```
3 changes: 3 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ id: mobtexting
org: mobtexting
name: whatsapp
region: ap-south-1
architecture: null
ignore:
- database
- docker
Expand All @@ -23,6 +24,7 @@ environments:
production:
memory: 1024
cli-memory: 512
kms: arn:aws:kms:us-east-1:XXXXXX:key/some-hash
#runtime: php-7.4:2la
runtime: docker
#image: php7-fpm # custom docker image
Expand All @@ -35,6 +37,7 @@ environments:
asset-bucket: true # create aws bucket
warm: 10
timeout: 30
size: 1024
scheduler: false
queues: false
cloudfront: false
Expand Down
68 changes: 48 additions & 20 deletions src/Serverless.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Diviky\Serverless;

use Diviky\Serverless\Concerns\EnvReader;
use Illuminate\Support\Str;
use Laravel\VaporCli\Helpers;
use Laravel\VaporCli\Manifest;
use Laravel\VaporCli\Path;
Expand Down Expand Up @@ -35,7 +36,7 @@ public static function generate($stage): void

$queue_name = $stage . '_default';
$cache = $name . '_' . $stage . '_cache';
$queues = $env['queues'];
$queues = $env['queues'] ?? false;

if (false !== $queues) {
$queues = true === $queues ? [$queue_name] : $queues;
Expand Down Expand Up @@ -121,6 +122,7 @@ public static function generate($stage): void
'region' => $region,
'stage' => $stage,
'runtime' => 'provided',
'architecture' => $manifest['architecture'] ?? null,
'environment' => $environment,
'apiGateway' => [
'shouldStartNameWithService' => true,
Expand Down Expand Up @@ -160,7 +162,7 @@ public static function generate($stage): void
]);

if ($docker) {
if (!isset($env['image'])) {
if (empty($env['image'])) {
$yaml['provider']['ecr'] = [
'images' => [
$image => [
Expand All @@ -182,7 +184,7 @@ public static function generate($stage): void

$web = [
'handler' => 'vaporHandler.handle',
'timeout' => $env['timeout'] ?? 28,
'timeout' => $env['timeout'] ?? 60,
'memorySize' => $env['memory'] ?? 1024,
'reservedConcurrency' => $env['concurrency'] ?? null,
'provisionedConcurrency' => $env['capacity'] ?? null,
Expand All @@ -208,7 +210,7 @@ public static function generate($stage): void

if (isset($env['web'], $env['web']['targets']) && is_array($env['web']['targets'])) {
foreach ($env['web']['targets'] as $value) {
$resources[$value['name'] . '-tg'] = self::createTargetGroup('web', $value);
$resources[Str::studly($value['name'] . '-tg')] = self::createTargetGroup('web', $value);
}
}

Expand All @@ -217,7 +219,7 @@ public static function generate($stage): void
'environment' => [
'APP_RUNNING_IN_CONSOLE' => 'true',
],
'timeout' => $env['queue-timeout'] ?? null,
'timeout' => $env['queue-timeout'] ?? ($env['timeout'] ?? 60),
'memorySize' => $env['queue-memory'] ?? null,
'reservedConcurrency' => $env['queue-concurrency'] ?? null,
'layers' => $layers,
Expand All @@ -233,7 +235,7 @@ public static function generate($stage): void
'environment' => [
'APP_RUNNING_IN_CONSOLE' => 'true',
],
'timeout' => $env['cli-timeout'] ?? null,
'timeout' => $env['cli-timeout'] ?? ($env['timeout'] ?? 60),
'memorySize' => $env['cli-memory'] ?? 1024,
'layers' => $layers,
'events' => [[
Expand All @@ -258,6 +260,7 @@ public static function generate($stage): void
'Type' => 'AWS::SQS::Queue',
'Properties' => [
'QueueName' => $queue_name,
'VisibilityTimeout' => $env['queue-timeout'] ?? ($env['timeout'] ?? 60),
'RedrivePolicy' => [
'maxReceiveCount' => 3,
'deadLetterTargetArn' => '!GetAtt ' . ucfirst($queue_name) . 'FailedQueue.Arn',
Expand All @@ -269,6 +272,7 @@ public static function generate($stage): void
'Type' => 'AWS::SQS::Queue',
'Properties' => [
'QueueName' => $queue_name . '_failed',
'VisibilityTimeout' => $env['queue-timeout'] ?? ($env['timeout'] ?? 60),
'MessageRetentionPeriod' => (7 * 24 * 60),
],
];
Expand Down Expand Up @@ -356,24 +360,24 @@ public static function generate($stage): void
$fs = null;
if (isset($env['volumes']) && \count($env['volumes']) > 0) {
foreach ($env['volumes'] as $volume) {
list($local, $access_point) = \explode(':', $volume);
list($local, $access_point) = \explode(':', $volume, 2);

if ('arn:' != \substr($access_point, 0, 4)) {
if (!empty($access_point) && 'arn:' != \substr($access_point, 0, 4)) {
$access_point = 'arn:aws:elasticfilesystem:${self:provider.region}:' . $account_id . ':access-point/' . $access_point;
}

$fs = [
'localMountPath' => $local,
'arn' => $access_point,
];
if (!empty($local) && !empty($access_point)) {
$fs = [
'localMountPath' => $local,
'arn' => $access_point,
];
}
}

// \array_push($yaml['plugins'], 'serverless-pseudo-parameters');
}

if (!isset($env['web']) || false !== $env['web']) {
if ($docker) {
if (isset($env['image'])) {
if (!empty($env['image'])) {
$web['image'] = $env['image'];
} else {
$web['image'] = [
Expand All @@ -387,16 +391,24 @@ public static function generate($stage): void
unset($web['handler'], $web['layers']);
}

if (isset($fs) && \is_array($fs)) {
if (!empty($fs) && \is_array($fs)) {
$web['fileSystemConfig'] = $fs;
}

if (!empty($env['size']) && is_numeric($env['size'])) {
$web['ephemeralStorageSize'] = $env['size'];
}

if (!empty($env['kms'])) {
$web['awsKmsKeyArn'] = ('arn:' != \substr($env['kms'], 0, 4)) ? 'arn:aws:kms:${self:provider.region}:' . $account_id . ':key/' . $env['kms'] : $env['kms'];
}

$yaml['functions']['web'] = \array_filter($web);
}

if (isset($env['queues']) && false !== $queues) {
if ($docker) {
if (isset($env['image'])) {
if (!empty($env['image'])) {
$queue['image'] = $env['image'];
} else {
$queue['image'] = [
Expand All @@ -410,10 +422,18 @@ public static function generate($stage): void
unset($queue['handler'], $queue['layers']);
}

if (isset($fs) && \is_array($fs)) {
if (!empty($fs) && \is_array($fs)) {
$queue['fileSystemConfig'] = $fs;
}

if (!empty($env['size']) && is_numeric($env['size'])) {
$queue['ephemeralStorageSize'] = $env['size'];
}

if (!empty($env['kms'])) {
$queue['awsKmsKeyArn'] = ('arn:' != \substr($env['kms'], 0, 4)) ? 'arn:aws:kms:${self:provider.region}:' . $account_id . ':key/' . $env['kms'] : $env['kms'];
}

foreach ($queues as $queue_name) {
$queue['events'][]['sqs'] = [
'arn' => '!GetAtt ' . ucfirst($queue_name) . 'Queue.Arn',
Expand All @@ -426,7 +446,7 @@ public static function generate($stage): void

if (isset($env['scheduler']) && false !== $env['scheduler']) {
if ($docker) {
if (isset($env['image'])) {
if (!empty($env['image'])) {
$schedule['image'] = $env['image'];
} else {
$schedule['image'] = [
Expand All @@ -440,10 +460,18 @@ public static function generate($stage): void
unset($schedule['handler'], $schedule['layers']);
}

if (isset($fs) && \is_array($fs)) {
if (!empty($fs) && \is_array($fs)) {
$schedule['fileSystemConfig'] = $fs;
}

if (!empty($env['size']) && is_numeric($env['size'])) {
$schedule['ephemeralStorageSize'] = $env['size'];
}

if (!empty($env['kms'])) {
$schedule['awsKmsKeyArn'] = ('arn:' != \substr($env['kms'], 0, 4)) ? 'arn:aws:kms:${self:provider.region}:' . $account_id . ':key/' . $env['kms'] : $env['kms'];
}

$yaml['functions']['schedule'] = \array_filter($schedule);
}

Expand Down

0 comments on commit a6946d8

Please sign in to comment.