Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2023

Conversation

mnapoli
Copy link
Member

@mnapoli mnapoli commented Feb 1, 2023

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
Copy link
Contributor

afu-dev commented Feb 1, 2023

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
Copy link
Contributor

georgeboot commented Feb 1, 2023

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
Copy link
Member Author

mnapoli commented Feb 1, 2023

@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
Copy link
Contributor

georgeboot commented Feb 1, 2023

Would that be better?

Yup amazing!

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

@mnapoli
Copy link
Member Author

mnapoli commented Feb 1, 2023

Oh yes definitely!

@mnapoli
Copy link
Member Author

mnapoli commented Feb 6, 2023

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