Save 37% off PRO during our Black Friday Sale! »

ddev Extended

ddev Extended

PHP Projekte auf Basis von DDEV erweitern und konfigurieren.

Bc302e4bfb9e897e01293bb1c54996aa?s=128

Christian Münch

November 11, 2020
Tweet

Transcript

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

    / muench.dev 1 1
  2. Beispiel Projekt Ziel: PHP Anwendung mit Zugriff auf ElasticSearch 2

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

    / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  4. 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" } 4 4
  5. index.php <?php require_once 'vendor/autoload.php'; phpinfo(); 5 5 Christian Münch /

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

    6 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  7. ❯ 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 7 7 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  8. PHP Projekt ddev composer install 8 8 Christian Münch /

    @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  9. ❯ 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 9 9
  10. 10 10

  11. 11 11

  12. Mac Performance ddev config --nfs-mount-enabled=true 12 12 Christian Münch /

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

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

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

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

    Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  17. 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) 17 17 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  18. 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 18 18 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  19. Homeadditions .ddev/homeadditions ~/.ddev/homeadditions . └── homeadditions ├── bash_aliases.example └── .bashrc

    19 19 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  20. 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" 20 20 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  21. 21 21

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

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

    / muench.dev Christian Münch / @cmuench / muench.dev
  24. !/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 & 24 24 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  25. Container Commands 25 25 Christian Münch / @cmuench / muench.dev

    Christian Münch / @cmuench / muench.dev
  26. 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 "$@" 26 26 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  27. 27 27

  28. 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 28 28 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  29. Verzeichnisstruktur .ddev ├── .ddev-docker-compose-base.yaml ├── .ddev-docker-compose-full.yaml ├── config.yaml ├── db-build

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

    muench.dev Christian Münch / @cmuench / muench.dev
  31. 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' 31 31
  32. version: '3.6' services: elasticsearch: ... web: depends_on: - elasticsearch links:

    - 'elasticsearch:elasticsearch' volumes: elasticsearch: name: '${DDEV_SITENAME}-elasticsearch' 32 32 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  33. ❯ 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 33 33 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  34. 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 ... 34 34 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  35. ❯ 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" } 35 35 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  36. <?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); } 36 36 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  37. Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench

    / muench.dev 37 37
  38. 38 38

  39. Command Hooks pre-<command> post-<command> Beispiel: pre-start post-import-db post-composer 39 39

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

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

    Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  42. ❯ 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 42 42
  43. 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 43 43 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  44. === 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 44 44 Christian Münch / @cmuench / muench.dev Christian Münch / @cmuench / muench.dev
  45. Vielen Dank! Fragen oder Livedemo? 45 45 Christian Münch /

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