Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
Comment thread
Nyholm marked this conversation as resolved.
Outdated
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

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
Copy Markdown
Member

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?

Copy link
Copy Markdown

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
Copy Markdown

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.

Copy link
Copy Markdown

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
Copy Markdown
Member

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
Comment thread
Nyholm marked this conversation as resolved.
# SYMFONY_DECRYPTION_SECRET: ${ssm:/stripe-notifications/prod-decrypt-private-key}
Comment thread
Nyholm marked this conversation as resolved.
Outdated

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
Copy Markdown
Member

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?

Copy link
Copy Markdown

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
Copy Markdown
Member

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'
Comment thread
Nyholm marked this conversation as resolved.
- '.env*'