Docker https://janezurevc.name/ en Drupal 8.2.0 and composer wonderland https://janezurevc.name/drupal-820-and-composer-wonderland <span>Drupal 8.2.0 and composer wonderland</span> <span><span lang="" about="https://janezurevc.name/users/slashrsm" typeof="schema:Person" property="schema:name" datatype="" xml:lang="">slashrsm</span></span> <span>Mon, 17.10.2016 - 10:22</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>Over the weekend I took some time to update this site to the latest and greatest Drupal. Update itself was pretty straightforward and it went without any problems (great work Drupal community!).</p> <p>More interesting part was something that I wanted to do for a while. Until now I was using old-school approach repo with all modules and other dependencies committed in it. Most of you probably already heard about the <a href="https://getcomposer.org">Composer</a>. Thanks to <a href="https://www.drupal.org/user/254778">Florian Weber (@webflo)</a> and other contributors it is now fairly easy to manage your Drupal projects with it. There is a <a href="https://github.com/drupal-composer/drupal-project">Composer template for Drupal projects</a> available which will give you everything you need to get started. It took me just a good hour to fully convert my project (I am no Composer expert). I found this approach very nice and convenient and will be using it for all my future projects.</p> <p>As part of this I also worked on a <a href="https://github.com/drupal-docker/nginx/pull/13">pull request</a> for <a href="https://hub.docker.com/u/drupaldocker/">Drupal docker</a> project that makes docroot location configurable, which is a requirement for Composer driven projects.</p> </div> <div class="field field--name-field-related field--type-entity-reference field--label-above"> <div class="field--label">Enjoyed this post? There is more!</div> <div class="field--items"> <div class="field--item"><a href="https://janezurevc.name/drupal-dev-environment-on-docker" hreflang="en">Drupal dev environment on Docker</a></div> <div class="field--item"><a href="https://janezurevc.name/janezurevc-name-runs-on-drupal-8" hreflang="en">janezurevc.name runs on Drupal 8!</a></div> <div class="field--item"><a href="https://janezurevc.name/call-for-drupal-8-media-ecosystem-co-maintainers" hreflang="en">Call for Drupal 8 media ecosystem co-maintainers</a></div> </div> </div> Mon, 17 Oct 2016 08:22:28 +0000 slashrsm 102 at https://janezurevc.name Drupal dev environment on Docker https://janezurevc.name/drupal-dev-environment-on-docker <span>Drupal dev environment on Docker</span> <span><span lang="" about="https://janezurevc.name/users/slashrsm" typeof="schema:Person" property="schema:name" datatype="" xml:lang="">slashrsm</span></span> <span>Thu, 06.10.2016 - 00:50</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>I've been using a Docker based development environment for about a year. The purpose of this post is to document how I do it and hopefully get some feedback from other Docker users.</p> <p>I will update this post as I evolve my approach and learn better ways of doing things.</p> <h2>Why would anyone do that?</h2> <p>Modern web applications can become very complex. Days when LAMP was enough to run them are a distant past. Nowadays we need much more; <a href="https://lucene.apache.org/solr/">Apache Solr</a> for running search, <a href="https://www.memcached.org/">Memcached</a> or <a href="https://redis.io">Redis</a> as a fast cache storage backend, reverse proxies like <a href="https://www.varnish-cache.org/">Varnish</a> and more. In order to make the development as similar as possible to the production environments we need most of those services. Installing all this services to the developer's workstation can be complicated and can eat a lot of resources. Docker solves both problems by allowing you to clearly describe your stack and share this definition among your team members. It also allows you to easily start and stop the entire stack with one command, which means that your services only run when you really need them.</p> <p>There is more... Ever needed to test your app on a different PHP version and tried to run two different versions of PHP in parallel? With docker you simply download the images that you need and change the one that is being used with a trivial change in your definition file.</p> <p>Ever wanted to try a new software, but you didn't want to install a ton of dependencies on your machine? With Docker you don't need to do that. Simply download an image from <a href="https://hub.docker.com/">Docker Hub</a>, give it a try and remove it when you don't need it any more.</p> <h2>Images</h2> <p>I am mostly relying on <a href="https://www.drupaldocker.org/">Drupal Docker</a> images, which are maintained by <a href="https://github.com/zaporylie">Jakub Piasecki</a> (big thanks!) with the help of other members of the community. Its goal is to provide Drupal-tailored set of images that will help anyone to get started quickly and save a lot of time building custom ones. There are of course a <a href="https://hub.docker.com/r/drupaldocker/php/">PHP</a> and <a href="https://hub.docker.com/r/drupaldocker/drush/">Drush</a> images, but there is more. You will find a <a href="https://hub.docker.com/r/drupaldocker/nginx/">Nginx</a>, <a href="https://hub.docker.com/r/drupaldocker/mysql/">MySQL</a> and <a href="https://hub.docker.com/r/drupaldocker/mariadb/">MariaDB</a> images with default configuration suitable for Drupal projects.</p> <p>Besides Drupal Docker I use the default <a href="https://redis.io/">Redis</a> image and <a href="https://hub.docker.com/r/wernight/phantomjs/">PhantomJS</a>, which is needed to run some types of tests.</p> <h2>Bringing it all together</h2> <p>Every project needs multiple containers to function properly. I am using <a href="https://docs.docker.com/compose/">Docker compose</a> to describe environment for every Drupal project I work on. Drupal compose is a tool tool that allows you to describe docker containers that you need and links between them. This is my standard <em>docker-compose.yml</em> file, which lives in the root of a given Drupal project:</p> <pre><code>maria: image: drupaldocker/mariadb:10 environment: MYSQL_ALLOW_EMPTY_PASSWORD: 'True' MYSQL_DATABASE: drupal ports: - 3306 web: image: drupaldocker/nginx:1 ports: - 80 volumes_from: - php links: - php php: image: drupaldocker/php-dev:7 links: - maria volumes: - ./docroot:/var/www/html drush: image: drupaldocker/drush:8 links: - maria - web - phantomjs volumes_from: - php solr: image: solr:5.5-alpine ports: - 8983 volumes: - ./modules/search_api_solr/solr-conf/5.x:/solr-conf/conf entrypoint: - docker-entrypoint.sh - solr-precreate - d8 - /solr-conf redis: image: redis:3-alpine phantomjs: image: wernight/phantomjs:2 volumes_from: - php links: - web entrypoint: phantomjs command: "--ssl-protocol=any --ignore-ssl-errors=true /var/www/html/vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768" </code></pre> <p>One thing that experienced Docker users will notice is the fact that I do not include Drupal codebase in the PHP image. I prefer to check it out on my local machine and mount it into the running container. This allows me to use IDE that is installed on the host machine while still being able to run my Drupal applications inside containers.</p> <p>With the compose file in place I can now control my environment from anywhere inside the checkout with a few simple commands:</p> <pre><code># To bring the environment up. docker-compose up -d # To stop it. docker-compose stop # To remove all containers (and their data). docker-compose rm # To see the status of all running containers. docker-compose ps </code></pre> <p>This approach works quite well, but I am aware that is not perfect. It would be very interesting to hear how others approach this (check the comments section below!).</p> <h2>Drush</h2> <p>Drush is a crucial part of any Drupal development workflow. I run it through a separate container, which shares volumes with the main PHP and is linked to the database container. In order to run it I do:</p> <pre><code>docker-compose run --rm drush drush </code></pre> <p>This will run the <em>drush</em> command inside <em>drush</em> container (see definition in the compose file above) and remove the container when done. The command is a bit too long to type it into the console every time so I created an alias for it:</p> <pre><code># To install drupal. dcdr site-install --account-name=admin --account-pass=admin # To enable the Entity browser module. dcdr en entity_browser </code></pre> <h2>Debugging with xdebug</h2> <p>It has become practically impossible to develope for Drupal without the step debugger. In order to enable this in my setup I use <a href="https://hub.docker.com/r/drupaldocker/php-dev/">PHP development images</a> that Drupal Docker provides and come with the <a href="https://xdebug.org/">Xdebug extension</a> pre-installed. Debugging http requests is as easy as enabling debugging for the requests and making sure that the IDE or text editor is listening to the incoming connections from Xdebug.</p> <p>It is also possible to debug drush requests by setting a few environment variables:</p> <pre><code>docker-compose run --rm drush sudo -u root XDEBUG_CONFIG="idekey=PHPSTORM_XDEBUG remote_host=172.17.0.1" php /root/.composer/vendor/bin/drush.php </code></pre> <p><em>PHPSTORM_XDEBUG</em> is the session id that my IDE listens for and <em>172.17.0.1</em> IP of the host machine from within the container. I have an alias for that too:</p> <pre><code># To debug migration of users. dcdrd migrate-import users </code></pre> <h2>Running tests</h2> <p>I run tests through the drush container. In order to run Simpletest I have to do the following:</p> <pre><code>docker-compose run --rm drush sudo -u www-data php ./core/scripts/run-tests.sh --color --directory modules/entity_browser </code></pre> <p>And to run PHPUnit:</p> <pre><code>docker-compose run --rm drush sudo -u www-data MINK_DRIVER_ARGS="[\"https:\/\/phantomjs:8510\"]" SIMPLETEST_DB="mysql://root@maria/drupal" ./vendor/bin/phpunit --verbose -c core modules/entity_browser </code></pre> <p>And yes, there are aliases for those too. See the pattern? :)</p> <h2>Conclusion</h2> <p>The described approach has been working quite well so far. I like Docker and I am planning to keep using it in the future. It is clear to me that my approach probably isn't the most standard and that there are probably better ways.</p> <p>Exactly for that reason I'd like to hear from you. Do you believe that your solution works better? Do you like to approach things differently? Let us know in the comments section below so we'll learn together!</p> </div> <div class="field field--name-field-related field--type-entity-reference field--label-above"> <div class="field--label">Enjoyed this post? There is more!</div> <div class="field--items"> <div class="field--item"><a href="https://janezurevc.name/janezurevc-name-runs-on-drupal-8" hreflang="en">janezurevc.name runs on Drupal 8!</a></div> <div class="field--item"><a href="https://janezurevc.name/call-for-drupal-8-media-ecosystem-co-maintainers" hreflang="en">Call for Drupal 8 media ecosystem co-maintainers</a></div> <div class="field--item"><a href="https://janezurevc.name/releases-of-various-drupal-8-media-modules" hreflang="en">Releases of various Drupal 8 media modules</a></div> </div> </div> Wed, 05 Oct 2016 22:50:36 +0000 slashrsm 101 at https://janezurevc.name