Docksal: Create a drupal-composer/drupal-project based example repo for Drupal 8

Created on 12 Apr 2017  路  29Comments  路  Source: docksal/docksal

馃彿documentation

All 29 comments

I've already done something similar. Would you be interested?

@JensvdHeydt sure

I've got a Docksal powered Drupal 8 Composer Installation here: https://github.com/davekopecek/drupal8composer

It uses a shared volume to persist package manager cache as suggested in https://github.com/docksal/docksal/issues/231

@lmakarov drawing your attention that composer based Drupal installation is NOT an official way to install Drupal.
There is a long comment (sprite commented 9 November 2017 at 17:55) describing differences between that commonly used composer script and vanilla Drupal here: https://www.drupal.org/forum/support/installing-drupal/2017-11-08/where-to-install-drupal-8-with-composer

I renamed this issues to add more clarity.

Out of the box, Drupal core does ship with compose.json and using Composer IS the official way of managing dependencies in D8. Not so much for installing D8, though.

https://github.com/drupal-composer/drupal-project has a goal of making it "easier" to install D8 using Composer from scratch. It is indeed an unofficial (and opinionated) way on how Drupal codebase should be structured. And yes - it is suited more for advanced developers than novice and general public.

@lmakarov I have an example of a developer who installed Drupal in Docksal via composer. After the installation he had to downgrade doctrine/annotations from 1.5 to 1.4 (composer require doctrine/annotations:1.4) as he was having issues otherwise. I don't have details on the nature of the issues he was experiencing, just mentioning it here.

To be even more precise he used Drupal Console rather than plain composer (drupal site:new) but it runs the same composer command

composer create-project drupal-composer/drupal-project:8.x-dev docroot --prefer-dist --no-progress --no-interaction

Here's repo structure Acquia recommends for Drupal 8 sites:
https://docs.acquia.com/article/composer-migrate-existing-d8-site-composer-managed-build

And this is their top level composer.json template:
https://github.com/acquia/acquia-ra-composer/blob/master/composer.json

That looks to be less invasive and opinionated compared to drupal-composer/drupal-project.

@lmakarov I don't know sprite on drupal.org. However the main difference that she pointed out is that the webroot is in the web folder. In following her advice to search for her posts (which I found rather difficult to do) I found that she filed an issue on 27 Oct 2017 Titled "Menu Item Role Access - doesn't include composer installation support". This issue was closed as it seems sprite did not at that time understand how to add the drupal composer repository to her composer project so she could add the module. The module maintainer closed the issue for this reason.
So, I am not sure if those posts should be considered the official Drupal.org line about using composer to install Drupal 8. Take what you read with a grain of salt (consider the source). And as I said before I do not know the source. Just looking at post that the source made recently.

Drupal still does not have an official composer install path. I think we should close this issue until Drupal gets one.

The other option is to use the most used, which are docroot and web. Use one and link the other one back to it. That way both can be used. Not sure if you can keep it configurable like the Docksal webroot is.

@frederickjh not sure what you mean.

@achekulaev In re-reading this thread and the info in the links, I think that we were using the word path in two different ways. I think that you meant that Drupal has not put forth a best practice way of using Composer with Drupal 8.

I was thinking of path as a file path. One of the big differences I see with a composer work flow is where is the webroot. Most seem to think, as I do, that this should not be the same as the project root, but should be a folder inside it.
Some use the folder name of docroot others use web. I myself prefer docroot but create a symlink to docroot called web. If I happen to install a Drupal project with Composer that uses web as the folder name I create a symlink to it called docroot.

Using the drupal-composer/drupal-project is listed as Option A on the 'Using Composer to Manage Drupal Site Dependencies', so it would seem that it is at least one of the recommended ways to do a drupal composer based install.

It's also what you get when you install Drupal Commerce from scratch using their command:
composer create-project drupalcommerce/project-base mystore --stability dev

My repo is list above is pretty straightforward, it simply leaves docroot empty and uses composer to pull all the files into docroot in init-site

````
composer_install ()
{

echo "Install drupal with composer..."
composer global require hirak/prestissimo
composer create-project drupal-composer/drupal-project:8.x-dev docroot --stability dev --no-interaction
composer require cweagans/composer-patches

}
The webroot is set in docksal.env:
DOCROOT=docroot/web
````

Pull the repo, run init, get coffee, go...

@davekopecek thanks! This is very useful info!

P.S. hirak/prestissimo is pre-installed in all cli:2.x images and cweagans/composer-patches seems to be a part of drupal-composer/drupal-project:8.x-dev

@lmakarov

So we need to reference Option A on Using Composer to Manage Drupal Site Dependencies page https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies for Drupal recommended composer repo.

Installing Drupal 8 into an empty directory with the latest dev fin would look like this:

cd target-directory
# Initialize Docksal project
mkdir .docksal
# Download Drupal 8
fin run-cli composer create-project drupal-composer/drupal-project:8.x-dev . --stability dev --no-interaction
# Set DOCROOT
fin config set DOCROOT=web
# Start
fin project start

The project is now accessible by its URL where Drupal Install runs.

They would need to configure database during install.

database configuration

Blog post might be the best documentation in this case. I drafted one @lmakarov

@achekulaev is there any reason not to just put the default DB settings in settings.local.php before running the install? The Drupal installer would see these.

@frederickjh

  1. settings.local.php load section is commented out in settings.php by default and need to be uncommented first
  2. Because of the above and because this way of installing Drupal contains no files provided by Docksal (so user would need to generate those on the fly with cli commands):

I guess this

Use host: db, user: user, pass: user, database: default.
<screenshot.png>

is more clear than this:

To setup database run

1. grep "..." | sed "s/monstrous/command to uncomment lines in settings.php/"
   sed "s/or even/several of them/"

2. echo "<? php
# Database settings
$databases['default']['default'] = array (
  'database' => 'default',
  'username' => 'user,
  'password' => 'user',
  'host' => 'db',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
  'collation' => 'utf8mb4_general_ci',
);" > "$PROJECT_ROOT/$DOCROOT/sites/default/settings.local.php"

and user will still have to follow install.php to setup many other values.

I was originally thinking about an example project repo (like docksal/drupal8), similar to what @davekopecek did in davekopecek/drupal8composer. This will provide a fully automated day-to-day working example, similar to what you would be working with on a real project.

Manually installing Drupal 8 with Composer from ground 0 (https://github.com/docksal/docksal/issues/174#issuecomment-389296414) is a good example as well and showcases the power of the fin run-cli command.

We should have both and cover them in a blog post. The manual example should also go into the Composer docs section (https://docs.docksal.io/en/master/tools/composer), which we don't have yet :)

@lmakarov @achekulaev set up an example project over here

https://github.com/docksal/example-drupal8-composer

Using the Drupal Project. If this is ok with you both we just need to get the repo added in as an option now.

@sean-e-dietrich please remove example from the repo name. We should remove it everywhere actually.

@achekulaev renamed it https://github.com/docksal/boilerplate-drupal8-composer I remember us saying something similar of the nature unless you want me to just remove that and make it drupal8-composer

@sean-e-dietrich there is more to local settings than just the database connection string. They should also go into local.settings.php, instead of directly into settings.php

I think, storing a local.settings.php template in .docksal/config is the way to go for composer based Drupal 8 installations. See here

@lmakarov added a settings.php and settings.local.php file with configuration for the project as recommended.

Looks good to me!

Should we replace the existing Drupal8 project with the composer version? or should we add in a new version for people to select? I'm thinking we should replace the existing Drupal8 project.

Let's keep both, as both are valid options (and a matter of personal preference in regards to how to organize your code and repo). The existing has all dependencies commit in the repo and thus takes considerably less time to pull/build.

We should not replace existing one. Composer version takes forever to install.

Closed via dd34645b682cda6ea44bec0667a63723921a4342

Was this page helpful?
0 / 5 - 0 ratings