Giter Club home page Giter Club logo

civicrm-buildkit-docker's Introduction

WMF CiviCRM buildkit on Docker

This is taken from https://github.com/michaelmcandrew/civicrm-buildkit-docker and with middling success I have tried to acheive the following changes

Change Status Primary reason Upstreamable
Add Redis image there - not wired in WMF uses it Recommended as more performant
use MariaDB rather than mysql working WMF uses it Recommended as more OpenSource
Use WMF buildkit working WMF has a dependency that requires composer 1 Not recommended - resolve T267881 instead
Fix the integrity of the civicrm-buildkit repo directory working The upstream version moves things around such that the git repo is not 'pure' Recommended - for anyone who cares about maintaining buildkit too this matters
Fix the build directory to be outside buildkit working This is part of making the buildkit directory a proper repo again Recommend upstreaming
Fix the civicrm-buildkit directory to be a bind rather than a volume Tried & failed :-( This allows code to be managed on the client system - useful in dev Recommended
Fix civix to run from git repo code rather than phar Not attempted yet Assists with developing civix Recommended
Run civibuild commands at the end of the docker-compose Tried and failed Gives WMF staff same site set up Not recommended

WMF recommendation

The follow attempts to get phpstorm xdebug & phpunit set up as well as docker The docker part works well - phpstorm tbd if it's transferable or we just need more screenshots & tips.

PHP storm preparation if you get the plugins right first it might help

  1. docker-compose - make sure the path does not have snap in it
  • you must install docker through the method on the website as the snap version doesn't work right with phpunit
  1. don't install the python plugin - can break phpunit
  • here is my installed list BashSupport IntellijIRC PHPUnit code coverage com.jetbrains.codeWithMe com.jetbrains.php com.jetbrains.php.drupal com.jetbrains.php.framework com.jetbrains.plugins.ini4idea com.kalessil.phpStorm.phpInspectionsEA com.neon.intellij.plugins.gitlab com.urswolfer.intellij.plugin.gerrit de.espend.idea.php.annotation de.espend.idea.php.phpunit org.jetbrains.plugins.phpstorm-docker org.jetbrains.plugins.phpstorm-remote-interpreter

To get set up ...

docker-compose up -d
docker-compose exec -u buildkit civicrm civibuild create wmff --admin-pass admin
docker-compose exec -u buildkit civicrm civibuild create dmaster --admin-pass admin
cp -r civicrm/idea/wmff/dotidea build/wmff/.idea
cp -r civicrm/idea/dmaster/dotidea build/dmaster/web/sites/all/modules/civicrm/.idea

This creates a useful exec alias - note it uses the path I have (ie. with the dev - we should script to be dynamic)

echo "alias bkb='docker-compose --file $HOME/dev/civicrm-buildkit-docker/docker-compose.yml exec -u buildkit civicrm bash'" >> ~/.bash_aliases && source ~/.bash_aliases
echo "alias bkd='docker-compose --file $HOME/dev/civicrm-buildkit-docker/docker-compose.yml down'" >> ~/.bash_aliases && source ~/.bash_aliases && source ~/.bash_aliases
echo "alias bku='docker-compose --file $HOME/dev/civicrm-buildkit-docker/docker-compose.yml up -d'" >> ~/.bash_aliases && source ~/.bash_aliases && source ~/.bash_aliases

You will then have 2 sites (user name & password is demo/demo or admin/admin) http://wmff.localhost:7979 http://dmaster.localhost:7979 mysql will work on mysql -uroot -h127.0.0.1 -pbuildkit -P33306 the databases should be configured in the IDE you should be able to access sites using aliases with drush ie drush @wmff up drush @dmaster up Note the projects are intended to be

  1. opened from wmff dir for wmf project
  2. opened from civicrm modules dir for dmaster site/civicrm project

PHPstorm screenshots docker-compose

On the dmaster (civicrm) project you need to edit the template for phpunit tests such that it has the preferred interpreter and enviroment variables. phpunit

The interpreter is configured to look in wmff as there is no phpunit in dmaster phpunit-cli

On the dmaster (civicrm) project you need to disable stopping when the path is not mapped or outside the project xdebug-civi

The trick to getting it debugging to work in this repo that is NOT the webroot is somewhat explained in https://www.jetbrains.com/help/phpstorm/creating-a-php-debug-server-configuration.html

  • in short you need an in-place a server config and a deployment config is not enough - possibly the server config IS enough - I created a deployment config & then imported to server config.

The deployment config looks like this - note the path is on the server deploy config

And the mapping screen is configured like this mapping deploy

The import from deployment is via this button import button

looks like import from deploy

Gotchas

  • unexpected references to /opt/project when running tests could be because of the python plugin being installed. This dir (on the container) holds some phpunit files - but not the test files
  • references to the php result printer during tests could be the phpversion - possibly the wrong one is picked up. The snap version of docker compose can be a culprit here. Delete files from /opt/project/ on the docker container. Make sure docker-composer path is not snap.

Below is from origin forked repo.

CiviCRM buildkit on Docker

CiviCRM buildkit on Docker is primarily built for development. It may also be useful for hosting. Contributions welcome.

The CiviCRM Dockerfile (civicrm/Dockerfile) in this repo is published on Docker hub at https://hub.docker.com/r/michaelmcandrew/civicrm/. It is designed to work with a MySQL compatible container. You may wish to use it with other containers like phpmyadmin and maildev.

The docker-compose.yml file in this repository is a good starting point for Docker development. Advanced users may wish to create their own docker-compose.yml.

Requirements

  • Docker
  • Docker compose

Unfortunately CiviCRM buildkit docker isn't currently working on the Docker Desktop for Windows - see issue #52.

Getting started

  1. Clone this repository

  2. From the repository root, run docker-compose up -d to start the containers

  3. Create a dmaster demo site with docker-compose exec -u buildkit civicrm civibuild create dmaster

    • The build will run for some time. If successful, it will conclude with output similar to the following:

      - CMS_ROOT: /buildkit/build/dmaster
      - CMS_URL: http://dmaster.localhost:7979
      - CMS_DB_DSN: mysql://dmastercms_rftpp:Z8ADa62aJjf6n7IX@mysql:3306/dmastercms_rftpp?new_link=true
      - CIVI_DB_DSN: mysql://dmasterciv_6o62j:zhp2ftwJuw5W4WpG@mysql:3306/dmasterciv_6o62j?new_link=true
      - TEST_DB_DSN: mysql://dmastertes_gdc1v:eGCi5IT2bIkKv4EZ@mysql:3306/dmastertes_gdc1v?new_link=true
      - ADMIN_USER: admin
      - ADMIN_PASS: ##########
      - DEMO_USER: demo
      - DEMO_PASS: demo
      
    • Make note of the admin and demo credentials for future use. These credentials may also be found in the build directory, e.g. the credentials for dmaster are in build/dmaster.sh.

    • For more help with civibuild's create command, see the buildkit documentation

  4. Navigate to your new CiviCRM development site at http://dmaster.localhost:7979

Note: for less surprises, consider using a stable release.

Usage

CLI commands

Buildkit cli commands can be run from the host with:

docker-compose exec -u buildkit civicrm <COMMAND>

Alternatively, you can login to the container and run commands from there with:

docker-compose exec -u buildkit civicrm bash

Note: to avoid permissions issues, ensure that you connect to the containers as the buildkit user, not as root.

The /buildkit/build mount

The build directory of this repository is mounted into the civicrm container at /buildkit/build. Builds created in the container are visible here, so files can be edited directly on the host.

The /extra mount

We also mount an the extra directory of this repository at /extra for ad hoc use.

Site URLs

By default, new builds created with this Docker image are created at http://[SITE_NAME].localhost:7979. This makes it simple to create multiple builds in the same container.

Other URLs can be passed to the civibuild command, however, you will need to ensure any domains are resolved appropriately, e.g. by adding entries to the /etc/hosts file.

phpMyAdmin

phpMyAdmin is available for database admin at http://localhost:8081.

Development email

Navigate to http://localhost:8082 to view all email sent from the civicrm container.

Background: by default, buildkit disables outbound mail. We delete civicrm-buildkit/app/civicrm.settings.d/100-mail.php which re-enables outbound mail. We install msmtp on the civicrm container and configure it to deliver all mail to the maildev container.

Aliases

docker-compose commands get quite verbose. You may want to create aliases as follows:

alias bku='docker-compose --file $HOME/civicrm-buildkit-docker/docker-compose.yml up -d'
alias bkc='docker-compose --file $HOME/civicrm-buildkit-docker/docker-compose.yml exec -u buildkit civicrm'
alias bkb='docker-compose --file $HOME/civicrm-buildkit-docker/docker-compose.yml exec -u buildkit civicrm bash'
alias bk='docker-compose --file $HOME/civicrm-buildkit-docker/docker-compose.yml'

You can then:

  • bring up the containers with bku
  • run build and admin tools with bkc, for example bkc civibuild create dmaster.
  • start bash in the civicrm container with bkb.
  • run any other docker compose command with bk, e.g. bk down

Note: the above aliases assume you have downloaded this repo to $HOME/civicrm-buildkit-docker. Please adjust as appropriate if you have downloaded it somewhere else.

Using different versions of PHP

See publish/README.md for instructions on how to build CiviCRM containers that use different versions of PHP.

UID and GID conflicts

Bind mounts are fussy when it comes to user ids and group ids. If the user on your host machine has a different UID and GID to the buildkit user in the container (which is 1000 by default), you can create a custom build (see below) that passes BUILDKIT_UID and BUILDKIT_GID as arguments.

Custom builds

This repository comes with a docker-compose-build.yml that can be used for custom builds. Custom builds are useful if you want to pass particular arguments to the build. For example, you can define the UID and GID of the buildkit user (see below).

You can create a custom build with a custom UID for the buildkit user as follows:

  1. Overwrite docker-compose.yml with docker-compose-build.yml.
  2. Change the BUILDKIT_UID argument to match your user id if necessary (echo $UID should give you your user id).
  3. run docker-compose up -d --build.

Getting help

Feel free to ask any questions you have in the docker chatroom (mentioning @michaelmcandrew if you feel like it), or file an issue in the github issue queue.

Upgrading

New docker images are periodically released on Docker Hub at https://hub.docker.com/r/michaelmcandrew/civicrm/. You can upgrade to the latest version as follows:

  1. Download the latest image with docker pull michaelmcandrew/civicrm.
  2. Run docker-compose up -d will rebuild your containers with the latest image.

Note: we mount /buildkit as a volume so that any changes you make to the civicrm container (and your bash history, etc.) persist across restarts. This volume is mounted over the /buildkit directory that comes with the container. You will need to delete this volume (it gets recreated automatically based on the contents of the container) if you want to access the /buildkit directory that comes with the upgraded container. You can do that all follows:

From the civicrm-buildkit-docker directory:

  1. Stop your containers docker-compose down.
  2. Identify the /buildkit volume with docker volume ls. It will have a 'volume name' along the lines of civicrmbuildkitdocker_buildkit.
  3. Remove the volume with docker volume rm [VOLUME NAME].
  4. Restart the containers with docker-compose up -d.

Architecture

We stick with the defaults and follow best practice whenever possible. Sometimes CiviCRM best practice and Docker best practice are at odds. In these situations we are often forced to do things the CiviCRM way. When this happens, we make a note in the 'cloud native' project of the steps we could take to make CiviCRM more Docker friendly (e.g. environment variables to configure SMTP).

The docker-compose.yml defines the following containers:

  • civicrm (serves the sites; contains build and admin tools like civibuild, cv, etc.)
  • mysql
  • phpmyadmin for easier MySQL admin
  • maildev to catch outbound email

It seems like might make sense to integrate this repository with civicrm-buildkit at some point. I don't think that would be too hard to do.

More general discussion about CiviCRM and Docker is welcome in CivCRM's 'cloud-native' project.

Credits

CiviCRM Buildkit Docker is written by Michael McAndrew from Third Sector Design who you can contact for help, support and further development.

Contributing

Contributions to this repository are very welcome. Feel free to submit a pull request for minor improvements. For larger changes, please create an issue first.

See also

License

This extension is licensed under AGPL-3.0.

civicrm-buildkit-docker's People

Contributors

eileenmcnaughton avatar jaapjansma avatar jasonhildebrand avatar johannawallther avatar michaelmcandrew avatar wmortada avatar

Watchers

 avatar

Forkers

mepps

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.