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 recipe for runtime/bref #1001

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions runtime/bref/0.2/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

#
# Keep this file in the application's root or install bref/extra-php-extensions.
# See https://github.com/php-runtime/bref
#

# Fail on error
set -e

LAMBDA_ARGV=(${_HANDLER//:/ })

while true
do
# We redirect stderr to stdout so that everything
# written on the output ends up in Cloudwatch automatically
/opt/bin/php "${LAMBDA_ARGV[0]}" 2>&1
done
10 changes: 10 additions & 0 deletions runtime/bref/0.2/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"copy-from-recipe": {
"serverless.yaml": "serverless.yml",
"bootstrap": "bootstrap"
},
"gitignore": [
"/.serverless/"
],
"aliases": [ "bref" ]
}
4 changes: 4 additions & 0 deletions runtime/bref/0.2/post-install.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* <fg=blue>Read</> the full documentation to properly configure your
Symfony application at <comment>https://bref.sh/docs/frameworks/symfony.html</>

* Bref documentation: <comment>https://bref.sh/docs/</>
52 changes: 52 additions & 0 deletions runtime/bref/0.2/serverless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Read the documentation at https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/
service: my-symfony-app
configValidationMode: error
useDotenv: true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something you may not want to use useDotenv: true.

This will inject all .env env variables (application variables) into the serverless process (build/deploy process). And it will also automatically exclude .env files from being uploaded.

This feature was supposed to be enabled by default in Serverless Framework v3, but we've decided to keep it opt-in to avoid messing up applications. At the moment the error message says that this line should be added, but this will be changed soon.

If you want to control .env files separately from serverless deploy then you don't want to mix the 2.


provider:
name: aws
# The AWS region in which to deploy (us-east-1 is the default)
region: us-east-1
# The stage of the application, e.g. dev, production, staging… ('dev' is the default)
stage: prod
runtime: provided.al2
environment:
# Symfony environment variables
APP_ENV: prod
Comment on lines +11 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stage: prod
runtime: provided.al2
environment:
# Symfony environment variables
APP_ENV: prod
stage: ${opt:stage,'prod'}
runtime: provided.al2
environment:
# Symfony environment variables
APP_ENV: ${self:provider.stage}

By doing this, the user can easily deploy a prod/env Symfony app by specifying --stage when deploying.

At work, we used to work on multiples stages/Symfony environments:

  • a "staging" environement: we automatically deploy branch develop or pull requests with --stage dev, which will run a Symfony app in dev environment
  • a "production" environment: we automatically deploy branch main with --stage prod, which will run our Symfony app in prod environment

What do you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed if you use the variable ${sls:stage} which looks first for the cli option first, then the provider.stage value then defaults to dev if none is found.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 this is not needed, you should consider stage like a defaultStage configuration (we are considering renaming it to that in the future).

Also you might not want to mix Symfony env and stages, as you can have many stages (e.g. one per developer) which would not map to Symfony environments.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely agree here, those are two different concepts that I would not mix to avoid confusion.

Also see my previous comment here about this #1001 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, didn't know about that, thanks!

APP_RUNTIME: Runtime\Bref\Runtime
BREF_LOOP_MAX: 1 # Increase to keep the Lambda process alive between requests
Nyholm marked this conversation as resolved.
Show resolved Hide resolved
# SYMFONY_DECRYPTION_SECRET: ${ssm:/my-symfony-app/prod-decrypt-private-key}

plugins:
- ./vendor/bref/bref

functions:
# This function runs the Symfony website/API
web:
handler: public/index.php
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
layers:
- ${bref:layer.php-80}
events:
- httpApi: '*'

# This function let us run console commands in Lambda
console:
handler: bin/console
timeout: 120 # in seconds
layers:
- ${bref:layer.php-80}

package:
patterns:
# Excluded files and folders for deployment
- '!assets/**'
- '!node_modules/**'
- '!public/build/**'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should exclude the whole public/build directory (even if you add entrypoints.json and manifest.json files back).
What happens to files bundled by webpack Encore? They won't be deployed with this configuration right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assets should be served through s3 or Cloudfront. Serving them from lambda is highly inefficient in terms of performance or costs. See https://bref.sh/docs/frameworks/symfony.html#assets and https://bref.sh/docs/websites.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point, thx!

- '!tests/**'
- '!var/**'
# If you want to include files and folders that are part of excluded folders,
# add them at the end
- 'var/cache/prod/**'
- 'public/build/entrypoints.json'
- 'public/build/manifest.json'
Nyholm marked this conversation as resolved.
Show resolved Hide resolved