Description
What happened (or feature request):
Updated issue summary
There are a couple issues surrounding the nginx configuration for sites. First, our current approach of mounting the docroot specifically does not work for sites requiring code or assets residing above the docroot. Second, we currently provide no way to alter the nginx configuration to meet the needs of a given site.
We should implement functionality the dynamically updates the docroot path for nginx when the container starts. We should also provide and document a way for users to provide their own nginx configurations.
Original issue summary
Feature Request. This is my proposed solution to #189, #59, and #60.
Currently, we provide no way to change the nginx configuration for the web container to satisfy individual site's configuration requirements. This can be troublesome, as these specific configuration requirements could prevent a site from working as expected, or possibly even from working at all.
What you expected to happen:
I think we can reasonably address these concerns by providing templating of the nginx web configuration, and by providing configuration options in config.yaml for what I see as the largest concerns: Specifying docroot (already in place), public files directory, and private files directory locations. There are still situations we can't account for, such as if a module or plugin a site is using requires additional configurations. For these situations, I think we could provide an optional mechanism to replace the configuration file with one the user provides. This would be an option we provide enough documentation for an advanced user to make the configuration if necessary.
If we took this approach, I would see these as the specific tasks
- Add docker-gen to the web container
- Convert the existing nginx configuration to a template, making variables of the server root (docroot), public upload directory (for public image styles rules), private upload directory (for rules forbidding direct access)
- Define the template path provided to docker-gen as an environment variable, allowing a user to override by specifying path to their own file. Document usage in customizing/extending doc page.
- Add a prompt to ddev config to ask the user's public upload directory. (wordpress + drupal; this is a fairly common feature of other CMS as well)
- Add a prompt to ddev config to ask the user's private upload directory (drupal only at this time; there are other platforms like Typo3 that provide private directories, and wp has plugins that can restrict access. This config could potentially be leveraged for these down the road)
Activity
beeradb commentedon Jun 2, 2017
small nitpick, is dockergen the best tool there? Seems like maybe this should just be a go binary that templates? dockergen is typically used to respond to changes in docker (like a new site coming online in the nginx-proxy), but it seems like in this case we’re just templating based on environment vars?
tannerjfco commentedon Jun 2, 2017
The primary motivation behind using docker-gen would be that it is a tool that we already have some familiarity with from the nginx router. There are other templating tools available, another go one i'm aware of off-hand is https://github.com/hairyhenderson/gomplate. I'm not strongly tied to docker-gen if there's a better tool for this.
beeradb commentedon Jun 2, 2017
There's also just the standard template package, https://golang.org/pkg/text/template/. We probably need to consider users in anything we do, though. i.e. how easy would it be for them to modify or replace a template?
rickmanelius commentedon Jun 6, 2017
Related to #7.
tannerjfco commentedon Jun 7, 2017
We can use another tool, or make our own binary that templates files, but I don't see a strong case for doing so when we have a tool we are already familiar with. docker-gen is a file generator that renders templates using docker container meta-data. It can actively watch for changes to respond to, but it doesn't need to. To me, it seems like this is a valid use case for docker-gen, though it is a much simpler use case.
The templating is intended to address the more crucial config changes we would need to make the nginx config work for most sites. When it comes to users modifying the template, I would consider this a more advanced use case we document. We would provide a link to the template file from the container, with instructions on how to replace the file with your own. That file could then be modified with the user's required configurations. I think following this approach, there shouldn't be a strong need for users to learn/understand go templating, though we can still link off to the godoc for those that desire it.
rickmanelius commentedon Jun 8, 2017
@rfay @beeradb @tannerjfco and I had a conference call to discuss. The TL;DR is that we have consensus / buy-in to proceed with this as our pattern to address current issues (public and private directories, mounting a parent directory in nginx) and figure issues (php.ini tweaks, settings.php modifications, etc).
This is actionable.
rickmanelius commentedon Jun 8, 2017
One admin/clean-up item. The issue summary should be updated to include specific testing criteria.
tannerjfco commentedon Jun 12, 2017
I ended up changing direction on this a fair bit. Put simply, docker-gen is not the right tool for this job. It can do it, but it requires more complexity than the minimal implementation I was hoping to achieve, and more complexity than this task warrants. I evaluated similar alternatives, but couldn't find one of sufficient quality that met our needs.
I also gave some more thought to public/private files, and I am thinking that we should maybe just address this need the same way we would address other custom nginx configuration requirements, which would be for the user to define their own configuration in their own file. I'm wary to provide our own configuration and processing for these, as it really is addressing concerns that are specific to a small share of Drupal sites running on an nginx web server.
The PR I'll be posting will provide a solution to replace the docroot in the nginx config, and add documentation for overriding configuration files (namely nginx) in the web container.
[-]Template the nginx configuration for web container, add config options for public/private file directories[/-][+]Update nginx docroot dynamically on container start, provide option for custom nginx config[/+]tannerjfco commentedon Jun 14, 2017
Fixed in #314