Skip to content

Allow setting PHP as a runtime in serverless.yml - #1394

Merged
mnapoli merged 2 commits into
v2from
serverless.yml-runtime-option
Feb 6, 2023
Merged

Allow setting PHP as a runtime in serverless.yml#1394
mnapoli merged 2 commits into
v2from
serverless.yml-runtime-option

Conversation

@mnapoli

@mnapoli mnapoli commented Feb 1, 2023

Copy link
Copy Markdown
Member

TODO:

  • Gather feedback from the community
  • Update docs
  • Update templates

This new feature allows setting PHP as a runtime when deploying with serverless.yml:

service: myapp

provider:
    name: aws

functions:
    function:
        handler: function.php
        runtime: php-81

    api:
        handler: api.php
        runtime: php-81-fpm
        url: true


plugins:
    - ./vendor/bref/bref

This replaces the layers variables (which still work!). One could migrate to this new simpler syntax like this for example:

service: myapp

provider:
    name: aws
-    runtime: provided.al2

functions:
    function:
        handler: function.php
-        layers
-            - ${bref:layer.php-81}
+        runtime: php-81

    api:
        handler: api.php
-        layers
-            - ${bref:layer.php-81-fpm}
+        runtime: php-81-fpm
        url: true

plugins:
    - ./vendor/bref/bref

This removes several wtfs for beginners:

  • wtf is "provided.al2"
  • wtf are "layers"
  • wtf is that ${bref:layer.php-81-fpm} syntax
  • wtf do I need 2 layers for console

Regarding the last one, indeed things get simpler for console:

functions:
    console:
        handler: bin/console
-        layers
-            - ${bref:layer.php-81}
-            - ${bref:layer.console}
+        runtime: php-81-console

And also it makes switching to ARM much simpler too because the runtime stays the same, the layer is automatically switched to the ARM layer by the Bref plugin (it detects architecture: arm64):

functions:
    console:
        handler: bin/console
        architecture: arm64
        runtime: php-81 # no need to add the `arm-` prefix

@mnapoli mnapoli added this to the 2.0 milestone Feb 1, 2023
@mnapoli mnapoli self-assigned this Feb 1, 2023
@afu-dev

afu-dev commented Feb 1, 2023

Copy link
Copy Markdown
Contributor

Feedback: less things to write = less error possible. Also it feels nicer to read/understand.

Cons: runtime and architecture may be flagged as "error" or "unknown" when using an IDE. Example with PhpStorm

image

@georgeboot

georgeboot commented Feb 1, 2023

Copy link
Copy Markdown
Contributor

Only thing I could really see is that newcomers might also want additional layers (isn't intl going to be a separate layer?) and now you are figuring out why there are 2 ways to declare stuff.

But overall and assuming that this os properly documented, I'm all for!

@mnapoli

mnapoli commented Feb 1, 2023

Copy link
Copy Markdown
Member Author

@afu-dev agreed, this is annoying to me as well.

@georgeboot regarding extensions, I was thinking about something like this too:

functions:
    hello:
        handler: ...
        runtime: php-81
        extensions:
            - redis
            - amqp

Would that be better?

(and yes we would need a clear error message in case users hit the layer limit)

@georgeboot

georgeboot commented Feb 1, 2023

Copy link
Copy Markdown
Contributor

Would that be better?

Yup amazing!

Could you cook it so that that would also enable the extension? 👀

@mnapoli

mnapoli commented Feb 1, 2023

Copy link
Copy Markdown
Member Author

Oh yes definitely!

@mnapoli

mnapoli commented Feb 6, 2023

Copy link
Copy Markdown
Member Author

Note: will look into extensions separately.

@mnapoli
mnapoli merged commit facaa3f into v2 Feb 6, 2023
@mnapoli
mnapoli deleted the serverless.yml-runtime-option branch February 6, 2023 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants