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

PHPUGHH - Deployment with OS Packages

PHPUGHH - Deployment with OS Packages

Spontaneous talk held by Arne Blankerts and me at a meetup of Hamburg's PHP Usergroup. The slides are from 2015, as we didn't have time to prepare new ones :)

Sebastian Heuer

September 13, 2016
Tweet

More Decks by Sebastian Heuer

Other Decks in Technology

Transcript

  1. ARNE BLANKERTS SEBASTIAN HEUER “Deployment ist nun mal leider problematisch...”

    BASED ON A TRUE STORY PRESENTED IN FULL HD BY THEPHP.CC AND SEBASTIAN HEUER BASED ON THE EXPERIENCE OF ARNE BLANKERTS, STEFAN PRIEBSCH, SEBASTIAN BERGMANN AND SEBASTIAN HEUER EXAMPLE CODE TAKEN FROM GLOBETROTTER.DE PREMIERING AT CODE.TALKS 2015 IN HAMBURG
  2. Package: gt21-datapool Version: %%VERSION%% Maintainer: Sebastian Heuer <[email protected]> Description: GT21

    DataPool Section: all Priority: optional Depends: php5-fpm (>=5.3.6), gt21-lib Architecture: all
  3. <target name="init"> <property name="buildnumber" value="${env.BUILD_NUMBER}"/> <property name="packagename" value="gt21-datapool"/> <property name="packagedir"

    value="${basedir}/build/${packagename}"/> <property name="install_dir" value="/srv/gt21/datapool" /> </target>
  4. <target name="prepare_package_content" depends="init"> <copy todir="${packagedir}${install_dir}"> <fileset dir="${basedir}"> <exclude name="**/conf/datapool.yaml"/> <exclude

    name="**/build/**"/> <exclude name="**/tests/**"/> <exclude name="**/.git/**"/> <exclude name="*.xml*"/> </fileset> </copy> <copy tofile="${packagedir}/DEBIAN/control" file="${basedir}/conf/build/control"/> <copy todir="${packagedir}/DEBIAN" file="${basedir}/conf/build/postinst"/> <replace file="${packagedir}/DEBIAN/control" token="%%VERSION%%" value="${buildnumber}"/> <replace file="${packagedir}/DEBIAN/postinst" token="%%INSTALLDIR%%" value="${install_dir}"/> </target>
  5. %define _targetdir /var/www/php/application/ %define _sourcedir /some/where/deployment/x/ Summary: Application Package Name:

    application Version: 1.0.0 Release: vendor.1 [...] Provides: application-%{version}-%{release} BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch BuildRequires: ant Requires: php-cli, php-fpm, php-pdo, php-soap, php-mbstring, php-pdo_mysql %description Application release %prep
  6. %install [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT

    install -m 755 -d $RPM_BUILD_ROOT%{_targetdir}src cp -R '%{_sourcedir}src'/* $RPM_BUILD_ROOT%{_targetdir}src/ cp '%{_sourcedir}bootstrap.php' $RPM_BUILD_ROOT%{_targetdir}bootstrap.php %clean %files %defattr(-,root,root) %dir %{_targetdir}src %{_targetdir}src/* %{_targetdir}/bootstrap.php %post [...] %changelog [...]
  7. root@jenkins ~ $ mv rpmbuild/RPMS/noarch/application-1.0.0-vendor.1.noarch.rpm /var/www/repo root@jenkins ~ $ cd

    /var/www/repo && createrepo --update --deltas --num-deltas=3 . root@server ~ $ cat /etc/yum.repos.d/company-test.repo [company-test] name=company repo (testing) baseurl=http://jenkins/ gpgcheck=0 enabled=1 installonlypkgs=application installonly_limit=3 metadata_expire=60s
  8. WEBSERVER REDIS STOREFRONT MIDDLEWARE SEARCH STOREBACK DATAPOOL ERP & PIM

    1.0.0 LIVE: 1.0.0 1.1.0 STOREFRONT MIDDLEWARE SEARCH STOREBACK DATAPOOL
  9. WEBSERVER REDIS STOREFRONT MIDDLEWARE SEARCH STOREBACK DATAPOOL ERP & PIM

    1.0.0 1.1.0 LIVE: 1.1.0 STOREFRONT MIDDLEWARE SEARCH STOREBACK DATAPOOL
  10. <?php $redis = new Redis; $redis->connect('127.0.0.1', 6379); $redis->select(0); $runWithVersion =

    array_filter($redis->get('default_version')); require '/var/www/php/application/' . $runWithVersion[0] . '/bootstrap.php';
  11. <?php $keys = array(); if (isset($_COOKIE['PHPSESSID'])) { $keys[] = $_COOKIE['PHPSESSID']

    . '_version'; } $keys[] = 'default_version'; $redis = new Redis; $redis->connect('127.0.0.1', 6379); $redis->select(0); $runWithVersion = array_filter($redis->mGet($keys)); require '/var/www/php/application/' . $runWithVersion[0] . '/bootstrap.php';