Skip to content

Commit 8c6d485

Browse files
apotekadamzimmermannmarkdorison
authored
Resolve mariadb for mysql contextually (#164)
Co-authored-by: Adam Zimmermann <adam@chromatichq.com> Co-authored-by: Mark Dorison <mark@chromatichq.com>
1 parent c984eac commit 8c6d485

File tree

7 files changed

+389
-15
lines changed

7 files changed

+389
-15
lines changed

.ddev/config.yaml

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
name: usher
2+
type: php
3+
docroot: ""
4+
php_version: "8.2"
5+
webserver_type: nginx-fpm
6+
xdebug_enabled: false
7+
additional_hostnames: []
8+
additional_fqdns: []
9+
use_dns_when_possible: true
10+
composer_version: "2"
11+
web_environment: []
12+
nodejs_version: "18"
13+
omit_containers:
14+
- db
15+
16+
# Key features of ddev's config.yaml:
17+
18+
# name: <projectname> # Name of the project, automatically provides
19+
# http://projectname.ddev.site and https://projectname.ddev.site
20+
21+
# type: <projecttype> # drupal6/7/8, backdrop, typo3, wordpress, php
22+
23+
# docroot: <relative_path> # Relative path to the directory containing index.php.
24+
25+
# php_version: "8.1" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"
26+
27+
# You can explicitly specify the webimage but this
28+
# is not recommended, as the images are often closely tied to ddev's' behavior,
29+
# so this can break upgrades.
30+
31+
# webimage: <docker_image> # nginx/php docker image.
32+
33+
# database:
34+
# type: <dbtype> # mysql, mariadb, postgres
35+
# version: <version> # database version, like "10.4" or "8.0"
36+
# mariadb versions can be 5.5-10.8 and 10.11, mysql versions can be 5.5-8.0
37+
# postgres versions can be 9-15.
38+
39+
# router_http_port: <port> # Port to be used for http (defaults to global configuration, usually 80)
40+
# router_https_port: <port> # Port for https (defaults to global configuration, usually 443)
41+
42+
# xdebug_enabled: false # Set to true to enable xdebug and "ddev start" or "ddev restart"
43+
# Note that for most people the commands
44+
# "ddev xdebug" to enable xdebug and "ddev xdebug off" to disable it work better,
45+
# as leaving xdebug enabled all the time is a big performance hit.
46+
47+
# xhprof_enabled: false # Set to true to enable xhprof and "ddev start" or "ddev restart"
48+
# Note that for most people the commands
49+
# "ddev xhprof" to enable xhprof and "ddev xhprof off" to disable it work better,
50+
# as leaving xhprof enabled all the time is a big performance hit.
51+
52+
# webserver_type: nginx-fpm, apache-fpm, or nginx-gunicorn
53+
54+
# timezone: Europe/Berlin
55+
# This is the timezone used in the containers and by PHP;
56+
# it can be set to any valid timezone,
57+
# see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
58+
# For example Europe/Dublin or MST7MDT
59+
60+
# composer_root: <relative_path>
61+
# Relative path to the composer root directory from the project root. This is
62+
# the directory which contains the composer.json and where all Composer related
63+
# commands are executed.
64+
65+
# composer_version: "2"
66+
# You can set it to "" or "2" (default) for Composer v2 or "1" for Composer v1
67+
# to use the latest major version available at the time your container is built.
68+
# It is also possible to use each other Composer version channel. This includes:
69+
# - 2.2 (latest Composer LTS version)
70+
# - stable
71+
# - preview
72+
# - snapshot
73+
# Alternatively, an explicit Composer version may be specified, for example "2.2.18".
74+
# To reinstall Composer after the image was built, run "ddev debug refresh".
75+
76+
# nodejs_version: "18"
77+
# change from the default system Node.js version to another supported version, like 14, 16, 18, 20.
78+
# Note that you can use 'ddev nvm' or nvm inside the web container to provide nearly any
79+
# Node.js version, including v6, etc.
80+
81+
# additional_hostnames:
82+
# - somename
83+
# - someothername
84+
# would provide http and https URLs for "somename.ddev.site"
85+
# and "someothername.ddev.site".
86+
87+
# additional_fqdns:
88+
# - example.com
89+
# - sub1.example.com
90+
# would provide http and https URLs for "example.com" and "sub1.example.com"
91+
# Please take care with this because it can cause great confusion.
92+
93+
# upload_dirs: "custom/upload/dir"
94+
#
95+
# upload_dirs:
96+
# - custom/upload/dir
97+
# - ../private
98+
#
99+
# would set the destination paths for ddev import-files to <docroot>/custom/upload/dir
100+
# When mutagen is enabled this path is bind-mounted so that all the files
101+
# in the upload_dirs don't have to be synced into mutagen.
102+
103+
# disable_upload_dirs_warning: false
104+
# If true, turns off the normal warning that says
105+
# "You have Mutagen enabled and your 'php' project type doesn't have upload_dirs set"
106+
107+
# working_dir:
108+
# web: /var/www/html
109+
# db: /home
110+
# would set the default working directory for the web and db services.
111+
# These values specify the destination directory for ddev ssh and the
112+
# directory in which commands passed into ddev exec are run.
113+
114+
# omit_containers: [db, ddev-ssh-agent]
115+
# Currently only these containers are supported. Some containers can also be
116+
# omitted globally in the ~/.ddev/global_config.yaml. Note that if you omit
117+
# the "db" container, several standard features of ddev that access the
118+
# database container will be unusable. In the global configuration it is also
119+
# possible to omit ddev-router, but not here.
120+
121+
# performance_mode: "global"
122+
# DDEV offers performance optimization strategies to improve the filesystem
123+
# performance depending on your host system. Should be configured globally.
124+
#
125+
# If set, will override the global config. Possible values are:
126+
# - "global": uses the value from the global config.
127+
# - "none": disables performance optimization for this project.
128+
# - "mutagen": enables Mutagen for this project.
129+
# - "nfs": enables NFS for this project.
130+
#
131+
# See https://ddev.readthedocs.io/en/latest/users/install/performance/#nfs
132+
# See https://ddev.readthedocs.io/en/latest/users/install/performance/#mutagen
133+
134+
# fail_on_hook_fail: False
135+
# Decide whether 'ddev start' should be interrupted by a failing hook
136+
137+
# host_https_port: "59002"
138+
# The host port binding for https can be explicitly specified. It is
139+
# dynamic unless otherwise specified.
140+
# This is not used by most people, most people use the *router* instead
141+
# of the localhost port.
142+
143+
# host_webserver_port: "59001"
144+
# The host port binding for the ddev-webserver can be explicitly specified. It is
145+
# dynamic unless otherwise specified.
146+
# This is not used by most people, most people use the *router* instead
147+
# of the localhost port.
148+
149+
# host_db_port: "59002"
150+
# The host port binding for the ddev-dbserver can be explicitly specified. It is dynamic
151+
# unless explicitly specified.
152+
153+
# mailhog_port: "8025"
154+
# mailhog_https_port: "8026"
155+
# The MailHog ports can be changed from the default 8025 and 8026
156+
157+
# host_mailhog_port: "8025"
158+
# The mailhog port is not normally bound on the host at all, instead being routed
159+
# through ddev-router, but it can be bound directly to localhost if specified here.
160+
161+
# webimage_extra_packages: [php7.4-tidy, php-bcmath]
162+
# Extra Debian packages that are needed in the webimage can be added here
163+
164+
# dbimage_extra_packages: [telnet,netcat]
165+
# Extra Debian packages that are needed in the dbimage can be added here
166+
167+
# use_dns_when_possible: true
168+
# If the host has internet access and the domain configured can
169+
# successfully be looked up, DNS will be used for hostname resolution
170+
# instead of editing /etc/hosts
171+
# Defaults to true
172+
173+
# project_tld: ddev.site
174+
# The top-level domain used for project URLs
175+
# The default "ddev.site" allows DNS lookup via a wildcard
176+
# If you prefer you can change this to "ddev.local" to preserve
177+
# pre-v1.9 behavior.
178+
179+
# ngrok_args: --basic-auth username:pass1234
180+
# Provide extra flags to the "ngrok http" command, see
181+
# https://ngrok.com/docs/ngrok-agent/config or run "ngrok http -h"
182+
183+
# disable_settings_management: false
184+
# If true, ddev will not create CMS-specific settings files like
185+
# Drupal's settings.php/settings.ddev.php or TYPO3's AdditionalConfiguration.php
186+
# In this case the user must provide all such settings.
187+
188+
# You can inject environment variables into the web container with:
189+
# web_environment:
190+
# - SOMEENV=somevalue
191+
# - SOMEOTHERENV=someothervalue
192+
193+
# no_project_mount: false
194+
# (Experimental) If true, ddev will not mount the project into the web container;
195+
# the user is responsible for mounting it manually or via a script.
196+
# This is to enable experimentation with alternate file mounting strategies.
197+
# For advanced users only!
198+
199+
# bind_all_interfaces: false
200+
# If true, host ports will be bound on all network interfaces,
201+
# not just the localhost interface. This means that ports
202+
# will be available on the local network if the host firewall
203+
# allows it.
204+
205+
# default_container_timeout: 120
206+
# The default time that ddev waits for all containers to become ready can be increased from
207+
# the default 120. This helps in importing huge databases, for example.
208+
209+
#web_extra_exposed_ports:
210+
#- name: nodejs
211+
# container_port: 3000
212+
# http_port: 2999
213+
# https_port: 3000
214+
#- name: something
215+
# container_port: 4000
216+
# https_port: 4000
217+
# http_port: 3999
218+
# Allows a set of extra ports to be exposed via ddev-router
219+
# Fill in all three fields even if you don’t intend to use the https_port!
220+
# If you don’t add https_port, then it defaults to 0 and ddev-router will fail to start.
221+
#
222+
# The port behavior on the ddev-webserver must be arranged separately, for example
223+
# using web_extra_daemons.
224+
# For example, with a web app on port 3000 inside the container, this config would
225+
# expose that web app on https://<project>.ddev.site:9999 and http://<project>.ddev.site:9998
226+
# web_extra_exposed_ports:
227+
# - name: myapp
228+
# container_port: 3000
229+
# http_port: 9998
230+
# https_port: 9999
231+
232+
#web_extra_daemons:
233+
#- name: "http-1"
234+
# command: "/var/www/html/node_modules/.bin/http-server -p 3000"
235+
# directory: /var/www/html
236+
#- name: "http-2"
237+
# command: "/var/www/html/node_modules/.bin/http-server /var/www/html/sub -p 3000"
238+
# directory: /var/www/html
239+
240+
# override_config: false
241+
# By default, config.*.yaml files are *merged* into the configuration
242+
# But this means that some things can't be overridden
243+
# For example, if you have 'nfs_mount_enabled: true'' you can't override it with a merge
244+
# and you can't erase existing hooks or all environment variables.
245+
# However, with "override_config: true" in a particular config.*.yaml file,
246+
# 'nfs_mount_enabled: false' can override the existing values, and
247+
# hooks:
248+
# post-start: []
249+
# or
250+
# web_environment: []
251+
# or
252+
# additional_hostnames: []
253+
# can have their intended affect. 'override_config' affects only behavior of the
254+
# config.*.yaml file it exists in.
255+
256+
# Many ddev commands can be extended to run tasks before or after the
257+
# ddev command is executed, for example "post-start", "post-import-db",
258+
# "pre-composer", "post-composer"
259+
# See https://ddev.readthedocs.io/en/stable/users/extend/custom-commands/ for more
260+
# information on the commands that can be extended and the tasks you can define
261+
# for them. Example:
262+
#hooks:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
composer.lock
33
.idea
4+
.DS_Store

.lando.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: usher
2+
recipe: symfony
3+
config:
4+
php: '8.1'
5+
webroot: .
6+
7+
tooling:
8+
robo:
9+
service: appserver

RoboFile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
* Robo commands available to developers.
1313
*/
1414
class RoboFile extends Tasks {
15+
use Usher\Robo\Task\Discovery\Tasks;
1516
}

src/Robo/Plugin/Commands/DevelopmentModeBaseCommands.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
use DrupalFinder\DrupalFinder;
66
use Robo\Exception\TaskException;
77
use Robo\Result;
8-
use Robo\Robo;
8+
use Robo\ResultData;
99
use Robo\Tasks;
10-
use Symfony\Component\Yaml\Exception\ParseException;
1110
use Symfony\Component\Yaml\Yaml;
1211
use Usher\Robo\Plugin\Enums\LocalDevEnvironmentTypes;
1312
use Usher\Robo\Plugin\Traits\DatabaseDownloadTrait;
1413
use Usher\Robo\Plugin\Traits\DrupalVersionTrait;
1514
use Usher\Robo\Plugin\Traits\SitesConfigTrait;
15+
use Usher\Robo\Task\Discovery\Alternatives;
1616

1717
/**
1818
* Robo commands related to changing development modes.
@@ -30,21 +30,21 @@ class DevelopmentModeBaseCommands extends Tasks
3030
*
3131
* @var string
3232
*/
33-
protected $drupalRoot;
33+
protected string $drupalRoot;
3434

3535
/**
3636
* Composer vendor directory.
3737
*
3838
* @var string
3939
*/
40-
protected $vendorDirectory;
40+
protected string $vendorDirectory;
4141

4242
/**
4343
* Path to front-end development services path.
4444
*
4545
* @var string
4646
*/
47-
protected $devServicesPath;
47+
protected string $devServicesPath;
4848

4949
/**
5050
* Class constructor.
@@ -123,43 +123,57 @@ public function databaseRefreshLando(string $siteName = 'default'): Result
123123
/**
124124
* Refresh database on Tugboat.
125125
*/
126-
public function databaseRefreshTugboat(): Result
126+
public function databaseRefreshTugboat(): ResultData
127127
{
128128
$this->io()->title('refresh tugboat databases.');
129-
$result = null;
129+
$resultData = new ResultData();
130+
130131
foreach (array_keys($this->getAllSitesConfig()) as $siteName) {
132+
$dbPath = '';
131133
try {
132134
$dbPath = $this->databaseDownload($siteName);
133-
} catch (TaskException) {
135+
} catch (TaskException $e) {
134136
$this->yell("$siteName: No database configured. Download/import skipped.");
137+
$resultData->append($e->getMessage());
135138
// @todo: Should we run a site-install by default?
136139
continue;
137140
}
138-
if (!is_string($dbPath) || strlen($dbPath) == 0) {
141+
if (!is_string($dbPath) || $dbPath === '') {
139142
$this->yell("'$siteName' database path not found.");
143+
$resultData->append("'$siteName' database path not found.");
140144
continue;
141145
}
142146
$dbName = $siteName === 'default' ? 'tugboat' : $siteName;
143-
$result = $this->taskExec('mysql')
147+
$taskResult = $this->task(Alternatives::class, 'mariadb', 'mysql')->run();
148+
if (!$taskResult->wasSuccessful()) {
149+
$resultData->append($taskResult);
150+
continue;
151+
}
152+
$dbDriver = $taskResult->getData()['path'];
153+
$taskResult = $this->taskExec($dbDriver)
144154
->option('-h', 'mariadb')
145155
->option('-u', 'tugboat')
146156
->option('-ptugboat')
147157
->option('-e', "drop database if exists $dbName; create database $dbName;")
148158
->run();
149-
159+
$resultData->append($taskResult);
150160
$this->io()->section("import $siteName database.");
151-
$result = $this->taskExec("zcat $dbPath | mysql -h mariadb -u tugboat -ptugboat $dbName")
161+
$taskResult = $this->taskExec("zcat $dbPath | $dbDriver -h mariadb -u tugboat -ptugboat $dbName")
152162
->run();
153-
$result = $this->taskExec('rm')->args($dbPath)->run();
163+
$resultData->append($taskResult);
164+
$taskResult = $this->taskExec('rm')->args($dbPath)->run();
165+
$resultData->append($taskResult);
154166

155167
if (!$this->drupalVersionIsD7($this->drupalRoot)) {
156-
$result = $this->taskExec("$this->vendorDirectory/bin/drush")
168+
$taskResult = $this->taskExec("$this->vendorDirectory/bin/drush")
157169
->arg('cache:rebuild')
158170
->dir("$this->drupalRoot/sites/$siteName")
159171
->run();
172+
$resultData->append($taskResult);
160173
}
161174
}
162-
return $result;
175+
176+
return $resultData;
163177
}
164178

165179
/**

0 commit comments

Comments
 (0)