GithubHelp home page GithubHelp logo

geerlingguy / drupal-for-kubernetes Goto Github PK

View Code? Open in Web Editor NEW
160.0 11.0 51.0 1.23 MB

Drupal Example Site for Kubernetes

Home Page: http://www.pidramble.com

License: GNU General Public License v2.0

Dockerfile 1.66% PHP 84.24% CSS 7.71% Shell 1.06% Twig 5.33%
drupal kubernetes docker container drupal-8

drupal-for-kubernetes's Introduction

Drupal Example Site for Kubernetes

CI

The purpose of this Drupal codebase is to demonstrate a Drupal project and configuration set up for deployment into Kubernetes or an otherwise scalable containerized environment.

The project is used in tandem with the Raspberry Pi Dramble, an open source Kubernetes cluster tailor made for Drupal meant to run on a cluster of Raspberry Pis.

Documentation

Please read through the project documentation for details about how this project was created, how it's structured for easy development and deployment into production container environments, and how you can create your own Drupal project like it.

Local setup

  1. Build the site's docker image from the Dockerfile:

    docker build -t geerlingguy/drupal-for-kubernetes .
    
  2. Run the local development environment:

    docker-compose up -d
    

    (Wait for the environment to come up—you can monitor the logs with docker-compose logs -f).

  3. Once the container is running, install Dependencies and install Drupal. You can either access http://localhost/ and install using the UI, or install via Drush:

    # Install dependencies.
    docker-compose exec drupal composer install
    
    # Install Drupal.
    docker-compose exec drupal bash -c 'drush site:install minimal --db-url="mysql://drupal:$DRUPAL_DATABASE_PASSWORD@$DRUPAL_DATABASE_HOST/drupal" --site-name="Drupal Example Site for Kubernetes" --existing-config -y'
    
  4. Visit http://localhost/ in your browser, and login as admin using the password Drush printed in the 'Installation complete' message.

Note: If you have PHP and Composer installed on your host computer, you can run the composer install command there instead of through the Docker container for a bit of a speedup. Also note that if you're using Docker for Mac or Windows, it can take a couple minutes after composer install completes for all the filesystem changes to be present inside the Docker container!

Managing Configuration

After making any configuration changes on the website, you can export the configuration to disk so it can be preserved in the codebase and deployed to the production site:

docker-compose exec drupal bash -c 'drush config:export -y'

For more on the way this project's configuration changes are handled, and the general site development process, see the project documentation.

Exporting Content

After making any content changes on the website, you can export the changes to disk so it is preserved in the codebase and installable on the production site:

docker-compose exec drupal bash -c 'drush dcer --folder=modules/custom/pidramble_default_content/content/ node 1'

For more on the way this project's content changes are handled, see the pidramble_default_content README.

Upgrading Core (and Contrib)

  1. Set up the site like normal, make sure it's installed.
  2. Run docker-compose exec drupal composer update (to update everything).
  3. Run docker-compose exec drupal bash -c 'drush updb -y'
  4. Run docker-compose exec drupal bash -c 'drush config:export -y'
  5. Commit any changes and push them.

License

MIT license.

Author Information

Created in 2019 by Jeff Geerling, author of Ansible for DevOps and Ansible for Kubernetes.

drupal-for-kubernetes's People

Contributors

dependabot[bot] avatar geerlingguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drupal-for-kubernetes's Issues

Add personal Fathom Analytics integration

I don't want to use GA with my sites, but I would fancy using my private Fathom Analytics instance to see what kind of traffic / sources are hitting the Pi Dramble website.

So I would like to create a block (maybe a custom block or an exported block like the footer) which is only enabled if a particular environment variable (e.g. PIDRAMBLE_ANALYTICS_ENABLED) is 'true'.

Analytics code:

<!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
<script>
(function(f, a, t, h, o, m){
	a[h]=a[h]||function(){
		(a[h].q=a[h].q||[]).push(arguments)
	};
	o=f.createElement('script'),
	m=f.getElementsByTagName('script')[0];
	o.async=1; o.src=t; o.id='fathom-script';
	m.parentNode.insertBefore(o,m)
})(document, window, '//analytics.midwesternmac.com/tracker.js', 'fathom');
fathom('set', 'siteId', 'KMISI');
fathom('trackPageview');
</script>
<!-- / Fathom -->

Drupal's default config sync directory is in public files, docs are wrong

Now run the following command to tell Drupal to dump its current configuration into your 'config sync' directory (which happens to be configured in [project root]/config/sync by default):

From: https://github.com/geerlingguy/drupal-for-kubernetes/blob/master/docs/configure-and-reproduce.md

This confused me; instead you need to override the sync directory in your settings.php file. See https://www.drupal.org/docs/8/configuration-management/changing-the-storage-location-of-the-sync-directory for more details.

Ensure main images on Home and About pages are local

Over in geerlingguy/raspberry-pi-dramble#145, I'm testing the cluster in wire-gapped mode (no Internet access), and for obvious reasons, the images which load from GitHub are 404'ing.

So at least for the images on the Home and About pages, they should be stored in the site's theme images/assets, and be referenced in the content loading from that path, so the images will load even without a connection to github.com.

Composer install hits errors with scaffold files

After the Drupal 9 upgrade (see video: https://www.youtube.com/watch?v=nLoJ2L0AzDY), I noticed that when running composer install I'm getting the following:

Class DrupalProject\composer\ScriptHandler is not autoloadable, can not call post-install-cmd script

To get the site upgraded in a 2-hour timespan, I kinda cut a few corners tossing out some old composer.json cruft, and I seem to have broken some of the stuff that the drupal-project/composer-template had originally injected into the Composer config (like the ScriptHandler... might not even be needed anymore?).

Move articles into News section, create new front page content explaining Pi Dramble

As the title says:

  • Create and export new 'News' view page with menu link after Home, before Wiki
  • Remove Frontpage view from the frontpage
  • Create a new home page (Basic page node) with at least one 'hero' picture of the 2019 edition of the Pi Dramble and some copy that explains what it is, why it is, and where to go for code / more.

config/sync system.site.yml

Curious have you used this on deployments? Seems the issue when using this config/sync is:

Screenshot 2024-01-12 at 10 02 45 AM

not sure if ignoring that single file would work in .dockerignore or how to best to handle using this build on local development as well as once deployed... obviously the uuid changes, not sure best way to handle for updating on a local, dev, prod setup for this code base.

Thoughts?

Build basic theme for Pi Dramble website

I've always wanted to do this, but never had the hour to do it.

Basically, have a super simple single-column layout theme, with title and logo, then menu links, then content, then footer. Make it mobile-first, accessibility-first, etc.

Add a fun 404 page

At a minimum, maybe stick a fun picture of a raspberry pi, or something else related.

Update Wiki content as needed for new cluster setup

  • Change mentions of 5 or 6 nodes to 4 Pis default, with the ability to easily (well, sorta) scale to 200+ Pis.
  • Change any mentions of the full cluster specs (in README and elsewhere) to adapt it to 4 Pis as the baseline.
  • Create a new Kubernetes-centric architecture diagram for the following Wiki page: http://www.pidramble.com/wiki/setup/provision
  • Update pages which still describe the old cluster setup/architecture to use the new process (and move any redundant info out of the Pi Dramble project README).

Finish adding the rest of the site content from the Pi Dramble site

Right now I have most of the main content, but I have not yet migrated all the Wiki contents.

In this new Drupal site I will not be enabling the Wiki/Books module/content type, so I will reproduce all the Wiki pages as Basic pages. I might also need to do a little HTML wrangling to make sure all the content fits.

Finally, I would also like to make sure the separate Wiki menu comes across, so I think I'll reproduce that in code as well (similar to how I did the main menu, but with hierarchy... could be a little complex!).

Add default content for completely reproducible website

As the title says; basically add the default_content module, then add default nodes and a default admin user so I can have the entire site (including nodes) be reproducible inside the repository.

This may or may not be the best idea—otherwise I could create the content in a CSV or something and use Migrate to import after install...

Redirect non-www to www

The old site had this in the nginx config, I think. On the new site, it's using Apache, so it should be in .htaccess. Which means we need to override .htaccess and add it to the drupal-scaffold excludes section (I think).

Add detail shot to About page

Right now the About page is a little bland. I have a spiffy side/front shot I took last night that would be good for the About page (and differentiate it still from the Home page).

Travis CI build is failing after #10

Issue #10 seems to have caused Travis CI to start failing:

$ docker-compose exec drupal bash -c 'vendor/bin/drush site:install minimal --db-url="mysql://drupal:$DRUPAL_DATABASE_PASSWORD@$DRUPAL_DATABASE_HOST/drupal" --site-name="Drupal Example Site for Kubernetes" --existing-config -y'
 // You are about to DROP all tables in your 'drupal' database. Do you want to  
 // continue?: yes.                                                             
 [notice] Starting Drupal installation. This takes a while.
In install.core.inc line 536:
                                                                               
  <ul>                                                                         
  <li>To start over, you must empty your existing database and copy <em>defau  
  lt.settings.php</em> over <em>settings.php</em>.</li>                        
  <li>To upgrade an existing installation, proceed to the <a href="default/up  
  date.php">update script</a>.</li>                                            
  <li>View your <a href="http://:default">existing site</a>.</li>              
  </ul>                                                                        
                                                                               

See: https://travis-ci.com/geerlingguy/drupal-for-kubernetes/builds/101235781#L655

Upgrade to Drupal 9

Considering Drupal 9's launch is tomorrow... and this site is about as simple as they come, I think I could probably get it upgraded quickly enough to warrant getting it done tonight, assuming I have the time while also prepping for tomorrow's Ansible 101 live stream.

This was live streamed on June 3, 2020: https://www.youtube.com/watch?v=nLoJ2L0AzDY

Checklist

  • Use Composer to upgrade to 9.0.0 (once it's released)
  • Export configuration
  • Reinstall locally to ensure that actually works
  • Push code, tag it
  • (On separate display) bump version in drupal-pi/config.yml and save it
  • Update any references in the codebase and site markup to 'Drupal 9' where it references 'Drupal 8'
  • Deploy by running the drupal-pi playbook!
  • (On separate display) reinstall Drupal once the container is built

This example seems for drupal on containers not Kubenetes?

Hi,

I want to run Drupal on Kubernetes Pods. so landed on this example.
but I see you have added docker-compose file with instructions to use docker containers to run the application.

there seems to be no Orchestration tool configured? I don't see any K8s config files or instructions.

Could you please let us know if this is stored some where? or may change the naming to correct purpose if not?

Thanks in advance.

CI Failing due to Composer Plugin issues

Getting errors like:

#12 5.136  88/88 [============================] 100%
#12 5.136   - Installing composer/installers (v1.12.0): Extracting archive
#12 5.567 
#12 5.570 In PluginManager.php line 744:
#12 5.570                                                                                
#12 5.570   cweagans/composer-patches contains a Composer plugin which is blocked by yo  
#12 5.570   ur allow-plugins config. You may add it to the list if you consider it safe  
#12 5.570   .                                                                            
#12 5.570   You can run "composer config --no-plugins allow-plugins.cweagans/composer-p  
#12 5.570   atches [true|false]" to enable it (true) or disable it explicitly and suppr  
#12 5.570   ess this exception (false)                                                   
#12 5.570   See https://getcomposer.org/allow-plugins                                    
#12 5.570

Need to add config to composer.json:

    "config": {
        "sort-packages": true,
        "allow-plugins": {
            "composer/installers": true,
            "cweagans/composer-patches": true,
            "drupal/core-composer-scaffold": true,
            "zaporylie/composer-drupal-optimizations": true
        }
    },

Ran commands to add it:

composer config --no-plugins allow-plugins.composer/installers true
composer config --no-plugins allow-plugins.cweagans/composer-patches true
composer config --no-plugins allow-plugins.drupal/core-composer-scaffold true
composer config --no-plugins allow-plugins.zaporylie/composer-drupal-optimizations true

error php

Hello I have the following error.
Do you know how to solve it because I did not find.
I use PHP8.1 fpm on debian 11
Thank you in advance for your answers.

Wed Jun 29 10:36:01.159405 2022] [proxy_fcgi:error] [pid 21923:tid 140473356224256] [client 172.16.1.254:62631] AH01071: Got error 'PHP message: PHP Deprecated: Return type of Drupal\Core\Render\Markup::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/drupal/web/core/lib/Drupal/Component/Render/MarkupTrait.php on line 71PHP message: PHP Deprecated: Return type of Drupal\Core\Render\Markup::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/drupal/web/core/lib/Drupal/Component/Render/MarkupTrait.php on line 61'
[Wed Jun 29 10:36:01.232020 2022] [proxy_fcgi:error] [pid 21923:tid 140473339438848] [client 172.16.1.254:62631] AH01071: Got error 'PHP message: PHP Deprecated: Return type of Drupal\Core\Render\Markup::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/drupal/web/core/lib/Drupal/Component/Render/MarkupTrait.php on line 71PHP message: PHP Deprecated: Return type of Drupal\Core\Render\Markup::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/drupal/web/core/lib/Drupal/Component/Render/MarkupTrait.php on line 61', referer: http://xxx.xxx/

Cannot start service drupal: OCI runtime create failed

I'm trying to run this on Ubuntu 18.04 and getting this error. The docker build worked fine. Any tips?

$ docker-compose up -d
Starting drupal-for-kubernetes ... 
Starting drupal-for-kubernetes
Starting drupal-for-kubernetes ... error

ERROR: for drupal-for-kubernetes  Cannot start service drupal: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"docker-entrypoint.sh\": executable file not found in $PATH": unknown

ERROR: for drupal  Cannot start service drupal: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"docker-entrypoint.sh\": executable file not found in $PATH": unknown
ERROR: Encountered errors while bringing up the project.

Impossible to remove the pidramble_default_content module

I tried to remove the custom module : drush pm:uninstall pidramble_default_content

The error is:
[error] Error: Call to a member function delete() on null in pidramble_default_content_uninstall() (line 26 of /var/www/html/web/modules/custom/pidramble_default_content/pidramble_default_content.install) #0 [internal function]: pidramble_default_content_uninstall(false)
#1 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(392): call_user_func_array('pidramble_defau...', Array)
#2 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleInstaller.php(433): Drupal\Core\Extension\ModuleHandler->invoke('pidramble_defau...', 'uninstall', Array)
#3 /var/www/html/web/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(91): Drupal\Core\Extension\ModuleInstaller->uninstall(Array, true)
#4 /var/www/html/vendor/drush/drush/src/Drupal/Commands/pm/PmCommands.php(116): Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall(Array, true)
#5 [internal function]: Drush\Drupal\Commands\pm\PmCommands->uninstall(Array, Array)
#6 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#7 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#8 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#9 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/vendor/symfony/console/Application.php(1005): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#17 /var/www/html/vendor/drush/drush/includes/preflight.inc(18): require('/var/www/html/v...')
#18 phar:///usr/local/bin/drush/bin/drush.php(141): drush_main()
#19 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#20 {main}.

Could you fix it? Thanks

Add production/Kubernetes `settings.php` for use with prod Docker image

It needs to have the following addition (in addition to anything else we want to override in settings.php):

$databases['default']['default'] = [
  'database' => getenv('DRUPAL_DATABASE_NAME'),
  'username' => getenv('DRUPAL_DATABASE_USERNAME'),
  'password' => getenv('DRUPAL_DATABASE_PASSWORD'),
  'prefix' => '',
  'host' => getenv('DRUPAL_DATABASE_HOST'),
  'port' => getenv('DRUPAL_DATABASE_PORT'),
  'namespace' => 'Drupal\Core\Database\Driver\mysql',
  'driver' => 'mysql',
];
$config_directories['sync'] = '../config/sync';
$settings['hash_salt'] = getenv('DRUPAL_HASH_SALT');

Is it possible to include setup as part of the Docker image or K8s manifest?

I would like to automate the Drupal setup as much as possible. This will include automating the setup wizard using drush. Not sure if that can be part of the Dockerfile or included in a K8s deployment object. The end goal is to have users looking at the site when they open the browser and not going through the setup.

How to install bcmath

bcmath is required for Drupal commerce. I tried to add RUN docker-php-ext-install bcmath but docker-php-ext-install is not found.

Kubernetes manifest files

I like the setup of this project, but how/where do you specify the kubernetes configuration files? I don't see them anywhere in this repo. Or are you using Helm or a Kubernetes operator? If you could share any of those files that would be nice!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.