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

Use Symfony's Dotenv so Symfony Server is more convenient #2841

Merged
merged 7 commits into from Jul 3, 2019

Conversation

Projects
None yet
5 participants
@StijnVrolijk
Copy link
Contributor

commented Jun 25, 2019

Type

  • Enhancement

Pull request description

We've been using Symfony server in favor of Docker for the past few months now as it boasts quite a bit of advantages (not least of all a serious speed improvement).

The main disadvantage here was how Fork handles environments and debugging. In Docker, a virtual machine would be booted containing some environment variables: FORK_ENV and FORK_DEBUG. Fork would then read these using PHP's getenv() method. This poses a problem for Symfony server since it doesn't run a virtual machine but rather a local PHP instance, thus setting environment variables would be very cumbersome and not very dynamic.

Using Symfony's Dotenv we can set environment variables for each project or even environment or machine individually.

A perfect example might be something like this: By default, Fork ships in production mode without debugging. If you'd like to run in dev mode with debugging on, simply create a .env.local file with this content:

FORK_ENV=dev
FORK_DEBUG=1

@StijnVrolijk StijnVrolijk added this to the 5.6.0 milestone Jun 25, 2019

@StijnVrolijk StijnVrolijk requested review from forkcms/core-contributors Jun 25, 2019

Show resolved Hide resolved autoload.php
cp .env.dist .env
# Use this file to set your environment variables for Docker
# XDebug variables

This comment has been minimized.

Copy link
@jessedobbelaere

jessedobbelaere Jun 25, 2019

Contributor

Docker-compose only looks at .env currently (https://docs.docker.com/compose/environment-variables/#the-env-file).

I guess we can set the .env.local in the docker-compose.yml:

    env_file:
     - .env.local

To make it point to .env.local, and people can move the xdebug variables in the .env.local?

This comment has been minimized.

Copy link
@WouterSioen

WouterSioen Jun 25, 2019

Member

You can even add multiple env files in the docker-compose env_file directive

This comment has been minimized.

Copy link
@StijnVrolijk

StijnVrolijk Jun 25, 2019

Author Contributor

@jessedobbelaere I hadn't considered people still using Docker for a webserver. I'll add both .env and .env.local

This comment has been minimized.

Copy link
@StijnVrolijk

StijnVrolijk Jun 27, 2019

Author Contributor

Unfortunately Docker doesn't like loading environment variables from files that don't exist and .env.local doesn't always exist so I created a Docker specific .env file in var/docker

@jeroendesloovere
Copy link
Member

left a comment

I don't like the way we push env variables into $_SERVER variables.

We should use environment variables in the application (and not server variables) The twelve-factor app stores config in environment variables (often shortened to env vars or env). More info: https://12factor.net/config about why we should use environment variables in Fork CMS.

@StijnVrolijk

This comment has been minimized.

Copy link
Contributor Author

commented Jun 26, 2019

@jeroendesloovere I've just implemented environment variables in exactly the same way Symfony does, see https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/4.2/config/bootstrap.php

The code I added to autoload.php is basically the same.

Also, here's an excerpt from https://symfony.com/doc/current/components/dotenv.html:

Sensitive information and environment-dependent settings should be defined as environment variables (as recommended for twelve-factor applications). Using a .env file to store those environment variables eases development and CI management by keeping them in one "standard" place and agnostic of the technology stack you are using (Nginx vs PHP built-in server for instance).

@carakas carakas requested a review from jeroendesloovere Jun 26, 2019

@carakas

This comment has been minimized.

@carakas

carakas approved these changes Jul 3, 2019

@carakas carakas merged commit a833612 into master Jul 3, 2019

5 checks passed

Scrutinizer Analysis: No new issues – Tests: passed
Details
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/styleci/push The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@carakas carakas deleted the symfony-dotenv branch Jul 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.