Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Drupal and Open shift (and php)

8 676 vues

Publié le

Steven presents with Openshift at DrupalCon Prague

Publié dans : Technologie
  • Soyez le premier à commenter

Drupal and Open shift (and php)

  6. 6. DRUPAL8DRUPAL8 Needs PHP 5.3.5 OpenShift Online runs RHEL 6.4 RHEL 6.4 has PHP 5.3.3
  7. 7. BUILDINGACARTRIDGEBUILDINGACARTRIDGE If it runs on RHEL or Fedora, it will run on OpenShift IUS provides PHP 5.3 and PHP 5.4 cartridges for RHEL Let's make a cartridge from those RPMS
  8. 8. RPMSTOCARTRIDGERPMSTOCARTRIDGE Download them Use rpm2cpio to grab the binaries and files is my script to do this from IUS repos Add in the appropriate manifest and hooks Here are some examples of scripts from the PHP 5.4 cartridge https://github.com/smerrill/php-the-ripper
  9. 9. RUNNINGAVENDOREDPHPRUNNINGAVENDOREDPHP The toughest part: the path will change every time php and php-fpm must be in $PATH Point to php.ini with $PHPRC Point to other .ini files with $PHP_INI_SCAN_DIR PHP and HTTP libraries live in $LD_LIBRARY_PATH
  10. 10. CARTRIDGESCRIPTSCARTRIDGESCRIPTS BIN/SETUPBIN/SETUP The setup script is responsible for creating and/or configuring the files that were copied from the cartridge repository into the gear’s directory. Setup must also be reentrant and will be called on every incompatible upgrade. Any logic you want to occur only once should be added to install.
  11. 11. bin/setup #!/bin/bash -eu case "$1" in -v|--version) version="$2" esac # Set the version if it is unset. [ -z "$version" ] && version=5.4.16 # Copy the version specific files up to php directory shopt -s dotglob mkdir -p $OPENSHIFT_PHP_DIR/configuration/etc/ cp -Hr $OPENSHIFT_PHP_DIR/versions/shared/configuration/etc/* $OPENSHIFT_PHP_DIR/configuration/etc/ # Create additional directories required by PHP mkdir -p $OPENSHIFT_PHP_DIR/phplib/pear/{docs,ext,php,cache,cfg,data,download,temp,tests,www} mkdir -p $OPENSHIFT_PHP_DIR/{logs,run,tmp,sessions}
  12. 12. CARTRIDGESCRIPTSCARTRIDGESCRIPTS BIN/INSTALLBIN/INSTALL The install script is responsible for creating and/or configuring the files that were copied from the cartridge repository into the gear’s directory. install will only be called on the initial install of a cartridge.
  13. 13. bin/install #!/bin/bash -eu case "$1" in -v|--version) version="$2" esac # Set the version if it is unset. [ -z "$version" ] && version=5.4.16 echo "$version" > "$OPENSHIFT_PHP_DIR/env/OPENSHIFT_PHP_VERSION" ln -s /usr/lib64/httpd/modules $OPENSHIFT_PHP_DIR/modules ln -s /etc/httpd/conf/magic $OPENSHIFT_PHP_DIR/conf/magic
  14. 14. bin/install, continued # PEAR setup rm -f $OPENSHIFT_HOMEDIR/.pearrc pear config-create "$OPENSHIFT_PHP_DIR"/phplib/pear/ "$OPENSHIFT_HOMEDIR"/.pearrc pear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set php_ini "$OPENSHIFT_PHP_DIR"/configuration/etc/php.ini pear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set auto_discover 1 # @TODO: Make the version a variable? pear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set php_bin "$OPENSHIFT_PHP_DIR"/usr/php/5.4.16-1/usr/bin/php pear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set bin_dir "$OPENSHIFT_PHP_DIR"/usr/php/5.4.16-1/usr/bin pear -c "$OPENSHIFT_HOMEDIR"/.pearrc upgrade --force pear
  15. 15. SETTINGENVIRONMENTALVARIABLESSETTINGENVIRONMENTALVARIABLES Cartridges can set environmental variables $OPENSHIFT_$CARTRIDGE_PATH_ELEMENT adds items to $PATH For PHP, this will be $OPENSHIFT_PHP_PATH_ELEMENT Processed as .erb templates
  16. 16. env/OPENSHIFT_PHP_PATH_ELEMENT.erb <%= ENV['OPENSHIFT_PHP_DIR'] %>usr/php/5.4.16-1/usr/bin
  17. 17. env/LD_LIBRARY_PATH.erb <%= ENV['OPENSHIFT_PHP_DIR'] %>usr/php/5.4.16-1/usr/lib64
  18. 18. WEBCARTRIDGESWEBCARTRIDGES Cartridges that accepts HTTP requests Every application has one and only one web cartridge Bind to the application to a specified port and host In our PHP 5.4 cartridge, PHP-FPM starts and Apache binds
  19. 19. CARTRIDGESCRIPTSCARTRIDGESCRIPTS BIN/CONTROLBIN/CONTROL update-configuration, pre-build, build, deploy post-deploy, start, stop, status reload, restart, threaddump, tidy, pre-snapshot, post-snapshot pre-restore, post-restore The control script allows OpenShift or user to control the state of the cartridge.
  20. 20. bin/control case "$1" in start) apache start && fpm start ;; stop) stop ;; restart) apache restart && fpm restart ;; reload|graceful) apache graceful "Restarting gracefully" ;; status) status ;; configtest) configtest ;; tidy) tidy ;; build) build ;; deploy) exit 0 ;; # Nothing to deploy on template PHP cartridge *) exit 0 esac exit $?
  21. 21. bin/control, continued function apache() { client_message "$2 Apache server" [ "$1" != "stop" ] && update_httpd_passenv $HTTPD_CFG_FILE /usr/sbin/httpd -C "Include $HTTPD_CFG_DIR/*.conf" -f $HTTPD_CFG_FILE -k $1 return $? }
  22. 22. bin/control, continued function fpm() { case "$1" in start) client_message "Starting PHP-FPM" if [ -f "$FPM_PID_FILE" ]; then client_message "PHP-FPM is already running." return 0 fi LD_LIBRARY_PATH=$OPENSHIFT_PHP_DIR/usr/php/5.4.16-1/usr/lib64 PHP_INI_SCAN_DIR=$OPENSHIFT_PHP_DIR/usr/php/5.4.16-1/etc/php.d PHPRC=$OPENSHIFT_PHP_DIR/configuration/etc/php.ini $OPENSHIFT_PHP_DIR/usr/php/5.4.16-1/usr/sbin/php-fpm --fpm-config $OPENSHIFT_PHP_DIR/configuration/etc/php-fpm.conf --pid $FPM_PID_FILE return $? ;;
  23. 23. bin/control, continued stop) client_message "Stopping PHP-FPM" if [ -f "$FPM_PID_FILE" ]; then fpm_pid=`cat "$FPM_PID_FILE" 2> /dev/null` kill $fpm_pid return_status=$? rm -f $FPM_PID_FILE return $return_status fi ;; restart) fpm stop && fpm start ;; esac }
  24. 24. RUNNINGYOURRUNNINGYOUR CARTRIDGESONOPENSHIFTCARTRIDGESONOPENSHIFT The OpenShift CDK (Catridge Development Kit) Example: The cartridge reflector "Reflects" a cartridge from GitHub and adds the download link to the GitHub zipball cartreflect-claytondev.rhcloud.com/reflect?github= Example: https://github.com/smarterclayton/openshift-cdk-cart http://rediscart-claytondev.rhcloud.com/ https://cartreflect-claytondev.rhcloud.com /reflect?github=phase2/openshift-php-fpm
  25. 25. LINKSLINKS https://github.com/phase2/openshift-php-fpm https://github.com/phase2/drupal-quickstart https://www.openshift.com/quickstarts/drupal- 8-quickstart http://openshift.github.io/documentation /oo_deployment_guide_puppet.html http://openshift.github.io/documentation /oo_cartridge_developers_guide.html
  26. 26. DĚKUJIVÁM!DĚKUJIVÁM! VIELENDANK!VIELENDANK! @stevenmerrill smerrill on freenode https://github.com/smerrill https://phase2technology.com