Skip to content

Use dynamic env params for critical settings and restore Heroku deploys #399

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

Closed
wants to merge 4 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
7 changes: 7 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
"repository": "https://github.com/symfony/symfony-demo",
"logo": "https://symfony.com/images/v5/pictos/demoapp.svg?v=4",
"success_url": "/",
"scripts": {
"postdeploy": "php bin/console doctrine:schema:create && php bin/console doctrine:fixtures:load -n"
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose it will fail on the 2nd push, won't it? Maybe php bin/console doctrine:schema:update --force is a better command here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. The name postdeploy for the script is, unfortunately, misleading; it is run only after the very first deploy using the "Deploy to Heroku" button.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I see, thanks!

},
"env": {
"SYMFONY_ENV": "prod",
"SYMFONY_LOG": "php://stderr",
"SYMFONY_SECRET": {
"description": "Extra entropy for %kernel.secret%; used for CSRF tokens, cookies and signed URLs.",
"generator": "secret"
}
},
"addons": [
"heroku-postgresql"
],
"image": "heroku/php"
}
2 changes: 1 addition & 1 deletion app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function registerBundles()
new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
new CodeExplorerBundle\CodeExplorerBundle(),
new AppBundle\AppBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), // used for initial population of non-SQLite databases in production envs
Copy link
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 it makes sense in a "real" application, might make sense as a demo app though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes and no. Even a real application, when first deployed somewhere, may need e.g. an initial user inserted into the database ;)

// uncomment the following line if your application sends emails
// new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
];
Expand All @@ -34,7 +35,6 @@ public function registerBundles()
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
}

return $bundles;
Expand Down
10 changes: 5 additions & 5 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ framework:
# http://symfony.com/doc/current/book/http_cache.html#edge-side-includes
esi: { enabled: true }
translator: { fallback: "%locale%" }
secret: "%secret%"
secret: "%env(SYMFONY_SECRET)%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
Expand Down Expand Up @@ -61,10 +61,10 @@ twig:
# Doctrine Configuration (used to access databases and manipulate their information)
doctrine:
dbal:
# if you don't want to use SQLite, comment the two following lines
driver: "pdo_sqlite"
path: "%kernel.root_dir%/data/blog.sqlite"
# uncomment the following lines to use a database different than SQLite
# if you don't want to use SQLite, change the URL in parameters.yml or set the DATABASE_URL environment variable
url: "%env(DATABASE_URL)%"

# instead of using a URL, you may also uncomment the following lines to configure your database
Copy link
Member

Choose a reason for hiding this comment

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

you also need to comment the URL (as the URL wins over these params if you configure both)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why it says "instead of" ;)

# driver: pdo_mysql
# host: "%database_host%"
# port: "%database_port%"
Expand Down
2 changes: 1 addition & 1 deletion app/config/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
path: "%env(SYMFONY_LOG)%"
level: info
console:
type: console
Expand Down
2 changes: 1 addition & 1 deletion app/config/config_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ monolog:
handler: nested
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
path: "%env(SYMFONY_LOG)%"
level: debug
console:
type: console
9 changes: 6 additions & 3 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ parameters:
# this demo application uses an embedded SQLite database to simplify setup.
# in a real Symfony application you probably will use a MySQL or PostgreSQL database
# the path must be relative or else it will not work on Windows
database_url: 'sqlite:///%kernel.root_dir%/data/blog.sqlite'
env(DATABASE_URL): 'sqlite:///%kernel.root_dir%/data/blog.sqlite'

# Uncomment this line to use a MySQL database instead of SQLite:
#
# database_url: 'mysql://root:[email protected]:3306/symfony_demo'
# env(DATABASE_URL): 'mysql://root:[email protected]:3306/symfony_demo'
#
# Furthermore, you must remove or comment out the "doctrine" section from config_dev.yml regarding SQLite!
#
Expand All @@ -35,4 +35,7 @@ parameters:
# used internally by Symfony in several places (CSRF tokens, URI signing,
# 'Remember Me' functionality, etc.)
# see: http://symfony.com/doc/current/reference/configuration/framework.html#secret
secret: 'secret_value_for_symfony_demo_application'
env(SYMFONY_SECRET): 'secret_value_for_symfony_demo_application'

# Destination for log files; can also be "php://stderr" etc
env(SYMFONY_LOG): %kernel.logs_dir%/%kernel.environment%.log
6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml",
"env-map": {
"database_url": "DATABASE_URL",
"secret": "SYMFONY_SECRET"
}
"file": "app/config/parameters.yml"
}
}
}
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.