Repository navigation
Description
Feature request:
As a developer, I wish to easily access the ports for my app services.
What you expected to happen:
Currently, we have to type ddev describe to see ports for our connected services and database information. As a developer, I would like my tooling to easily know these ports for custom commands or a custom bootstrap process of my CMS on the host.
- When I run
ddev start, my service ports are mapped to.ddev/ports.json - When I run
ddev stopmy service port maps are removed - When I run a CLI tool on my host, the CMS can be bootstrapped by services using port defined in
.ddev/ports.json
This would allow Solr, MySQL/Maria, Elastic, Redis support on host command line. I picked JSON because it's most easy thing to serialize/unserialize across languages.
So regardless if WP-CLI, Drush, Console, whatever. Each CMS can support a host settings.
I would like to have a generated ports.json in the .ddev folder. This would resemble the following:
{
mysql: 32768
mailhog: 8025
}
Each time the command is run and containers are brought up, this is updated.
This would allow me to easily customize settings to read the port from my host and allow execution of tooling on my host, instead of ddev exec.
This is beneficial so that I can run Blackfire.io profiling and Xdebug on my commands.
Why ports.json? Because my current workflow involves something like this
$cmd = "docker inspect --format='{{(index (index .NetworkSettings.Ports \"3306/tcp\") 0).HostPort}}' {{ container_name }}";
$port = trim(shell_exec($cmd));
$host = '{{ project_domain }}';
define('DB_HOST', "$host:$port");
That means each time the settings are loaded it executes a docker inspect which isn't performant and requires specific container naming. But since ddev controls the containers we can trust the file will be built properly
I picked JSON because it is the most common format that can be serialized/unserialized across languages (without external libraries.)
Anything else do we need to know:
Related source links or issues:
This was inspired by / relates to #454
My WordPress setup: https://github.com/mglaman/platform-docker/tree/develop/resources/stacks/wordpress
My Drupal setup: https://github.com/mglaman/platform-docker/tree/develop/resources/stacks/drupal8
Please use a complexity rating of 1-5 (5 is high) for a feature request. (High complexity implies more PR planning)
3
Activity
mglaman commentedon Feb 28, 2018
The Drupal configuration currently has
This should be renamed to
host.settings.phpand loaded wheneverDEPLOY_NAMEis missing or anyDDEV*environment variable.mglaman commentedon Feb 28, 2018
However CreateSettingsFile is only called on import db... not when ddev config runs.
rickmanelius commentedon Mar 10, 2018
I had a discussion with @mglaman at Midcamp. There are two segments to this feature.
The first should be an easy lift. The second has some implications across CMSes. Let me know if that would hit your use case. I'm assuming it's likely that end-users will need to modify DB settings file per project to make this work. However, I'm open to discuss in more detail to see how viable the second part is.
rfay commentedon Jul 16, 2018
ddev describe -jalready has output that shows published_port for mysql, is that adequate for this?:mglaman commentedon Jul 18, 2018
It does. Currently I have
But the idea would be to not run shell_exec each time.
I guess via hooks I could echo that to a JSON file and just load that instead.
rfay commentedon Jul 18, 2018
Your hook would have to clean up the file when you did an 'rm', because it would then be the wrong port (likely) on start.
mglaman commentedon Jul 20, 2018
Well each start would reset the file.
rickmanelius commentedon Jul 20, 2018
I’m long overdue to drive this one to AC. I’ll commit to COB Monday.
rickmanelius commentedon Jul 23, 2018
I believe this is a related request by @tmotyl asking for stable ports for mysqlworkbench. The same could be achievable if the ports were accessible. See #941
rickmanelius commentedon Jul 23, 2018
So this is an initial set of thoughts that may sane or not. But I see a few different ways this could be achieved in order to meet the goals during various use cases.
Problem Statement:
ddev describe -j, there is frustration in having to search and replace these values out while on the 1) host command line, 2) container command line or 3) CMS/application. The concept of always generating a .ddev/ports.json file allows access by all three.ddev ports, which would take the current project and generate environment variables for each. This could be akin to PROJECTNAME_PORT_MYSQL. A user would runddev port && mysql -u username -ppassword -hlocalhost --port=$PROJECTNAME_PORT_MYSQLPlease ignore any syntax errors. The point is more of trying to determine a way to make this programmable and fixed from a usage perpsective while allowing ports to change to avoid collisions.
rfay commentedon Apr 8, 2020
ddev describeandddev describe -jas of v1.14 also report the ports (http and https) of 3rd party services. Closing as I think this does the job.