Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ddev Extended

ddev Extended

PHP Projekte auf Basis von DDEV erweitern und konfigurieren.

Bc302e4bfb9e897e01293bb1c54996aa?s=128

Christian Münch

November 11, 2020
Tweet

More Decks by Christian Münch

Other Decks in Technology

Transcript

  1. Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench

    / muench.dev 1 1
  2. Was ist ddev? https://ddev.readthedocs.io/en/stable/ DDEV is an open source tool

    that makes it dead simple to get local PHP development environments up and running within minutes. 2 2 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  3. Unter der Haube Docker docker-compose (also v2) go (kompiliert für

    Windows, Mac (auch M1), Linux) 3 3 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  4. Gut abgehangen Github Actions Buildkite Circleci Christian Münch / @cmuench

    / muench.dev Christian Münch / @cmuench / muench.dev 4 4
  5. Tests on physical hardware! https://twitter.com/rand yfay/status/147952388 5179543557 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev 5 5
  6. Einfache Installation ddev ist nur ein einzelnes Binary! Es gibt

    auch Pakete Homebrew Chocolatey Arch Linux (AUR) Bash Script für andere Distributionen https://ddev.readthedocs.io/en/stable/#installation 6 6 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  7. Du bekommst alles was du für die PHP Entwicklung brauchst!

    PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 Mailcatcher (mailhog) MySQL 5.6, 5.7, 8.0 / MariaDB 10.2, 10.3 / Postgres (ab 1.19) ... Composer 1 / Composer 2 Projekt-Typ spezifische Tools (n98-magerun FTW!) Blackfire, xhprof 7 7 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  8. Projekt-Typen Backdrop Drupal 6 / 7 / 8 / 9

    Laravel Magento (OpenMage) Magento 2 PHP (generisch) Shopware 6 TYPO3 Wordpress 8 8 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  9. Getestet! Github Actions Buildkite Circleci Christian Münch / @cmuench /

    muench.dev Christian Münch / @cmuench / muench.dev 9 9
  10. Tests auf physischer Hardware! https://twitter.com/rand yfay/status/147952388 5179543557 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev 10 10
  11. Architektur ddev-router (Reverse Proxy) Project 1 web db dba Project

    2 web db dba Custom Service 1 z.B. Elasticsearch Custom Service 2 z.b Redis ... ... 11 11 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  12. Beispiel Projekt Ziel: PHP Anwendung mit Zugriff auf ElasticSearch 12

    12 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  13. Verzeichnis . ├── composer.json └── index.php 13 13 Christian Münch

    / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  14. Minimale composer.json { "name": "muench-dev/example-project", "description": "ddev Example Project", "type":

    "project", "license": "MIT", "authors": [ { "name": "Christian Münch", "email": "christian@muench-worms.de" } ], "require": { "elasticsearch/elasticsearch": "^7.9" } } 14 14
  15. index.php <?php require_once 'vendor/autoload.php'; phpinfo(); 15 15 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  16. Let's go! ddev config --project-name=example-project --php-version=7.4 --project- ddev start 16

    16 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  17. ❯ ddev start Starting example-project... Pushed mkcert rootca certs to

    ddev-global-cache/mkcert Running Command=ip address show dev docker0 Building db Building web Creating ddev-example-project-db ... done Creating ddev-example-project-web ... done Creating ddev-example-project-dba ... done Creating ddev-router ... done Successfully started example-project Project can be reached at https://example-project.ddev.site https://127.0.0.1:32786 17 17 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  18. PHP Projekt ddev composer install 18 18 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  19. ❯ ddev composer install No lock file found. Updating dependencies

    instead of installing from lo Loading composer repositories with package information Updating dependencies Lock file operations: 5 installs, 0 updates, 0 removals - Locking elasticsearch/elasticsearch (v7.9.1) - Locking ezimuel/guzzlestreams (3.0.1) - Locking ezimuel/ringphp (1.1.2) - Locking psr/log (1.1.3) - Locking react/promise (v2.8.0) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 5 installs, 0 updates, 0 removals - Installing psr/log (1.1.3): Extracting archive - Installing react/promise (v2.8.0): Extracting archive - Installing ezimuel/guzzlestreams (3.0.1): Extracting archive - Installing ezimuel/ringphp (1.1.2): Extracting archive - Installing elasticsearch/elasticsearch (v7.9.1): Extracting archive 1 package suggestions were added by new dependencies, use `composer sug Generating autoload files 19 19
  20. 20 20

  21. 21 21

  22. PHP Ausführen ddev exec php -v ddev . php -v

    # shortcut 22 22 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  23. Mac Performance ddev config --nfs-mount-enabled=true 23 23 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  24. NFS ist für jeden angeschaltet! 24 24 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  25. Lösung anlegen einer lokalen Config Dateien /config.*.y*ml sind per .gitignore

    ausgeschlossen. 25 25 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  26. Beispiel config.local.yaml nfs_mount_enabled: false 26 26 Christian Münch / @cmuench

    / muench.dev Christian Münch / @cmuench / muench.dev
  27. Tipp: Bash Alias ddev-disable-nfs-mount-locally='echo "nfs_mount_enabled: false" >> .ddev/config.local.yaml' 27 27

    Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  28. NFS Problematiken NFS muss installiert sein -> Sonst kommen komische

    Fehlermeldungen NFS Installation je Betriebssystem unter schiedlich Unterschiedliche Partitionierung Unterschiedliche Benutzer-IDs Keine Inotify Events (Watch-Tasks z.B. grunt, webpack, Magento Cache Clean) 28 28 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  29. Inotify Proxy Diverse Lösungen erhältlich Bekanntes NPM Paket ist nur

    ein Wrapper für eine C-Lib und benötigt installierte Build-Tools. Kleiner, schneller, golang https://github.com/cmuench/inotify-proxy ddev Command: https://github.com/cmuench/inotify-proxy/wiki/ddev-inotify- Command 29 29 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  30. Mutagen Sync Zwei-Wege-Synchronisation Vorteil: Performance da alle Dateien im Container

    liegen Nachteil: Redundante Datenhaltung (Es werden nicht alle Dateien synchonisiert) Seit ddev 1.18 verfügbar. Beste Integration von Mutgagen in einem Dev-Tool die mir bekannt ist. 30 30 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  31. Mutagen aktivieren dev config --mutagen-enabled=true 31 31 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  32. 32 32

  33. Mutagen Finetuning Über Konfiguration: .ddev/mutagen/mutagen.yml 33 33 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  34. #ddev-generated sync: defaults: mode: "two-way-resolved" stageMode: "neighboring" ignore: paths: -

    "/.git" - "/.tarballs" - "/.ddev/db_snapshots" - "/.ddev/.importdb*" - ".DS_Store" - ".idea" # - "/var" # vcs like .git can be ignored for safety, but then some # composer operations may fail if they use dev versions/git. # vcs: true symlink: mode: "posix-raw" 34 34
  35. Homeadditions .ddev/homeadditions ~/.ddev/homeadditions . └── homeadditions ├── bash_aliases.example └── .bashrc

    35 35 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  36. Beispiel .bashrc export PS1="\[\e[32m\][\[\e[m\]\[\e[36m\]\[\e[m\]\[\e[32m\]\h\[\e[m\]:\ alias ls='ls --color=auto' alias ll='ls -la'

    alias cd-root="cd /var/www/html" 36 36 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  37. 37 37

  38. Verzeichnisse . ├── commands │ ├── db │ ├── host

    │ ├── solr │ └── web 38 38 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  39. Host Commands Beispiel: ~/.ddev/commands/host/ide 39 39 Christian Münch / @cmuench

    / muench.dev Christian Münch / @cmuench / muench.dev
  40. !/bin/bash #ddev-generated ## Description: Open project in IDE ## Usage:

    ide ## Example: "ddev ide" /opt/intellij-idea-ultimate-edition/bin/idea.sh ${DDEV_APPROOT} \ > /dev/null 2>&1 & 40 40 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  41. Container Commands 41 41 Christian Münch / @cmuench / muench.dev

    Christian Münch / @cmuench / muench.dev
  42. Magento Kommando #!/bin/bash #ddev-generated ## Description: Run magento CLI inside

    the web container ## Usage: magento [flags] [args] ## Example: "ddev magento list" or "ddev magento maintenance:enable" ## ProjectTypes: magento2 bin/magento "$@" 42 42 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  43. 43 43

  44. docker-compose Konfiguration docker-compose up -d docker-compose -f docker-compose.yaml up -d

    docker-compose -f foo.yaml -f bar.yaml -f zoz.yaml up -d 44 44 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  45. Verzeichnisstruktur .ddev ├── .ddev-docker-compose-base.yaml ├── .ddev-docker-compose-full.yaml ├── config.yaml ├── db-build

    │ └── Dockerfile.example └── web-build └── Dockerfile.example 45 45 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  46. Beispiel ElasticSearch ... 46 46 Christian Münch / @cmuench /

    muench.dev Christian Münch / @cmuench / muench.dev
  47. version: '3.6' services: elasticsearch: container_name: 'ddev-${DDEV_SITENAME}-elasticsearch' hostname: '${DDEV_SITENAME}-elasticsearch' image: elasticsearch:7.6.2

    ports: - '9200' - '9300' environment: - VIRTUAL_HOST=elasticsearch-$DDEV_HOSTNAME - HTTP_EXPOSE=9200 - discovery.type=single-node labels: com.ddev.site-name: '${DDEV_SITENAME}' com.ddev.approot: $DDEV_APPROOT volumes: - 'elasticsearch:/usr/share/elasticsearch/data' 47 47
  48. version: '3.6' services: elasticsearch: ... web: depends_on: - elasticsearch links:

    - 'elasticsearch:elasticsearch' volumes: elasticsearch: name: '${DDEV_SITENAME}-elasticsearch' 48 48 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  49. ❯ ddev start Starting example-project... Running Command=ip address show dev

    docker0 Creating volume "example-project-elasticsearch" with default driver Building db Building web Creating ddev-example-project-elasticsearch ... done Recreating ddev-example-project-db ... done Recreating ddev-example-project-dba ... done Recreating ddev-example-project-web ... done 49 49 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  50. ddev describe $> ddev describe ... Other Services -------------- MailHog

    (https): https://example-project.ddev.site:8026 MailHog: http://example-project.ddev.site:8025 phpMyAdmin (https): https://example-project.ddev.site:8037 phpMyAdmin: http://example-project.ddev.site:8036 elasticsearch: http://example-project.ddev.site:9200 ... 50 50 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  51. ❯ ddev exec "curl http://elasticsearch:9200" { "name" : "example-project-elasticsearch", "cluster_name"

    : "docker-cluster", "cluster_uuid" : "fX7_HMTxRiC_1KL4nbTqAg", "version" : { "number" : "7.6.2", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f", "build_date" : "2020-03-26T06:34:37.794943Z", "build_snapshot" : false, "lucene_version" : "8.4.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } 51 51 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  52. <?php require_once 'vendor/autoload.php'; use Elasticsearch\ClientBuilder; $params = [ 'hosts' =>

    [ 'elasticsearch:9200' ] ]; try { $client = ClientBuilder::fromConfig($params); $client->ping(); echo "ElasticSearch connection established"; } catch (Exception $exception) { echo $exception->getMessage(); exit(1); } 52 52 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  53. Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench

    / muench.dev 53 53
  54. 54 54

  55. Command Hooks pre- post- Beispiel: pre-start post-import-db post-composer 55 55

    Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  56. Tasks exec -> Im Container (genormte Umgebung) exec_host -> Auf

    dem Host (Achtung!) composer -> Führt ein Composer Kommando aus 56 56 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  57. config.yaml Anpassung hooks: post-start: - composer: install 57 57 Christian

    Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  58. ❯ ddev start Starting example-project... ... Executing post-start hook... ===

    Running task: Composer command 'install' in web container, output below Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Nothing to install, update or remove Generating autoload files ... Successfully started example-project 58 58
  59. Lokale config.yaml Überschreibungen .ddev/config.<irgendwas>.yaml Nicht im Team geteilt da über

    .gitignore ausgeschlossen. 59 59 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  60. Beispiel: fester DB Port echo "host_db_port: 33002" > .ddev/config.local.yaml 60

    60 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  61. Shell Scripte hooks: post-start: - exec: bash .ddev/step1_install_special_tools.sh - exec:

    bash .ddev/step2_setup_myapplication.sh # other container - exec: bash .ddev/do_some_db_stuff.sh service: db - exec: bin/elasticsearch-plugin install analysis-icu service: elasticsearch 61 61 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  62. === Running task: Exec command 'bin/elasticsearch-plugin install analysis-icu' in container/service

    'elasticsearch', output below -> Installing analysis-icu -> Downloading analysis-icu from elastic [=================================================] 100%?? -> Installed analysis-icu Successfully started example-project 62 62 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  63. Troubleshooting 63 63

  64. Typisches Problem: Router gibt Fehler aus Lösung: Projekte beim herunterfahren

    des Rechners mit ddev stop -a alle Projekte stoppen. 64 64 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  65. PHP Memory Limit / Composer ddev ssh COMPOSER_MEMORY_LIMIT=-1 php -d

    memory_limit=-1 \ /usr/local/bin/composer require magento/extension-b2b 65 65 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  66. Linux Systemd Automatisch Projekte mit Docker Service zusammen stoppen. sudo

    systemctl edit docker.service Im Editor folgendes Eintragen: [Service] ExecStop=sudo -u cmuench /usr/bin/ddev stop -a (username durch eigenen ersetzen) 66 66 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  67. Vielen Dank! Fragen oder Livedemo? 67 67 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  68. Appendinx 68 68 Christian Münch / @cmuench / muench.dev Christian

    Münch / @cmuench / muench.dev
  69. Magento 2 Demo Projekt https://github.com/netz98/ddev-magento-demo 69 69

  70. Wordpress installieren ddev config --project-type=wordpress ddev start ddev exec wp

    core download ddev exec 'wp core install --url=$DDEV_PRIMARY_URL --title="New WordPress" --admin_user=admin --admin_email=admin@example.com --prompt=admin_password' # frontend ddev launch # admin ddev launch wp-admin/ 70 70 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  71. Magento 2 installieren https://ddev.readthedocs.io/en/stable/users/cli- usage/#magento-2-quickstart ddev start ddev composer create

    --repository=https://repo.magento.com/ magento/project-community-edition ddev ssh bin/magento setup:install --base-url=https://ddev-magento2.ddev.site/ --cleanup-database --db-host=db --db-name=db --db-user=db --db-password=db --elasticsearch-host=elasticsearch --admin-firstname=Magento --admin-lastname=User --admin-email=user@example.com --admin-user=admin --admin-password=admin123 --language=en_US bin/magento deploy:mode:set developer bin/magento setup:di:compile bin/magento cache:flush 71 71 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev