Skip to content
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

Add PHP runtime configuration from composer.json #392

Conversation

iamacarpet
Copy link

@iamacarpet iamacarpet commented Mar 14, 2024

To aid it a more idiomatic and friendly developer experience, when building for a PHP application, allow the runtime to be configured from composer.json, e.g.:

{
    "require": {
        "php": "^8.3",
        "myorg/mypackage": "^0.7"
    },
    "scripts": {
        "gcp-build": "my-script"
    },
    "extra": {
        "laravel": {
            "dont-discover": [
                "myorg/mypackage"
            ]
        },
        "google-buildpacks": {
            "document_root": "public",
            "front_controller": "index.php",
            "php-fpm": {
                "enable_dynamic_workers": true,
                "workers": 4
            },
            "serve_static": true
        }
    }
}

You can omit this entirely, or omit individual fields, so just specify the bits you want to customise.

This should work for both App Engine Flex, plus Cloud Run.

RFC @sonnysasaka @sl0wik @jama22 @kennethye1

I don't necessarily intend to have this merged as is, but use it as a starting point for a further discussion, unless you are all happy - what do we think?

@sl0wik
Copy link
Contributor

sl0wik commented Mar 14, 2024

I like it in general. It feels like some of those things should be set in app.yaml instead. For example php-fpm behavior might be different in different environments.

@iamacarpet
Copy link
Author

iamacarpet commented Mar 15, 2024

Good point @sl0wik , like if you're wanting to deploy the same repository on test/staging with a smaller instance and less concurrency, vs perhaps a larger instance and more concurrency in production?

If we're talking using build packs to builder a docker container image for Cloud Run, there isn't really anything like an app.yaml file - so perhaps the environment variable options on the pack command are the best choice?

If we want it to be a file in the repository, I suppose those settings could be included in a cloudbuild.yaml file.

And do we think document_root, front_controller and possible serve_static are the kind of settings that would be global to all deployments, so they'd be suitable to be (optionally) defined in composer.json?


In terms of the php-fpm options specifically, would this be something that's useful to tune with runtime environment variables, rather than build time environment variables?

The configuration files are generated during the build and static inside the container for the Cloud Run style builds, however, on App Engine Standard, serve is dynamically generating the php-fpm configuration at start-up - would we be better placed to switch to something like this for Cloud Run?

I say this as imagine you are using Cloud Deploy for a deployment pipeline into Cloud Run, you build a single docker image from source, then pass it to Cloud Deploy to roll out onto test/staging, then onto production - your instance size / concurrency could be different between the two environments, but you've got to use the same docker image.

@sonnysasaka
Copy link
Contributor

It's nice that common features can be tweaked without replacing the whole file. I support making these configs easy! Not sure about composer.json though, maybe environment variables will be more generic?

@iamacarpet
Copy link
Author

Ok, thanks @sonnysasaka , I think it’s looking like the consensus is becoming environment variables rather than composer.json, which is fair.

What are your thoughts on the php-fpm settings being runtime environment variables rather than build time variable, when on Cloud Run?

@sl0wik
Copy link
Contributor

sl0wik commented Mar 18, 2024

@iamacarpet I agree with @sonnysasaka that env sounds like a better solution. You can pass env variables to both, App Engine and Cloud Run. I'm already using it to set composer version.

@sonnysasaka
Copy link
Contributor

Hi @iamacarpet,

What are your thoughts on the php-fpm settings being runtime environment variables rather than build time variable, when on Cloud Run?

I am a bit wary about php-fpm settings being runtime config, since it might make troubleshooting harder. I think build time is already convenient enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants