Contao Agenturtag 2018

Peter Adelmann, trilobit GmbH

Contao Agenturtag 2018

Contao 4
Deployment
mit mage in der Praxis

Das habe ich mit euch vor...

Wer bin ich?

In eigener Sache

Wer bin ich

Definition
Was ist ein Deployment

Definition

Deployment

Deployment ist die gezielte Übertragung von Daten, Software oder Software-Updates an alle mit dieser Software arbeitenden Rechner.
Es geht dabei darum, dass alle Rechner mit der gleichen, aktuellen Software arbeiten und so ihre Funktionen erfüllen.

https://www.itwissen.info/

www
Wieso? Weshalb? Warum?

www

Wieso mehrere Instanzen?

Etwas bearbeiten, ohne den Live-Betrieb zu stören!

Aber was stört?

www

Wann ist eine x'te Instanz sinnvoll?

Deployment I
Vorgehensweisen

Deployment

Copykill

Deployment

Copy that!

Deployment

History Repeating!

Was tun, wenn z.B. in der anderen Instanz inzwischen gepflegt wird? Die Lösung - eventuell

Deployment II
Teilbereiche

Deployment

Teilbereiche

weitere Dateien

User-Generated-Content

Datenbank

Das Problem mit den IDs

Installation

... und hier kümmert sich mage

Magallanes
mage, die Theorie

Magallanes

Entwicklung

Magallanes ist ein Deployment-Tool, das mit PHP erstellt wurde für PHP-Anwendungen. Es ist einfach zu verwenden und zu verwalten.

https://www.magephp.com/

Magallanes

Entwicklung

Magallanes

Installation

Installation via composer:
  1. composer require andres-montanez/magallanes

Magallanes

Aufruf

Um das aktuelle Projekt zu deployen reicht folgender Aufruf:
  1. php bin/mage deploy production

Magallanes

Konfiguration

Basis, Umgebung

Konfiguration

magephp:
    log_dir: var/logs/mage

    environments:
        staging:
            user: ssh-12345-test

            host_path: /mein/hosting/var/www/myapp

        releases: 3

        exclude:
            - .idea
            - .mage.yml
            - app/config/parameters.yml
            - var/cache
            - var/logs
            - files

        hosts:
            - myapp_SSHKeyBasedAuthentication
        

Packen, entpacken

Konfiguration

tar_create: cfz
tar_extract: xfz
        

pre-deploy

Konfiguration

pre-deploy:
    - exec: {
        cmd: 'mysqldump
            --tables contao_myapp_local --add-drop-table --set-charset=UTF8
            -h192.168.0.42 -uwww -pwww > dump.sql',
        desc: 'Dumping database' }

    - exec: {
        cmd: 'rsync --delete
            -avzP files/
            -e ssh myapp:/mein/hosting/var/www/myapp/shared/files/',
        desc: 'Sync files ./files' }
        

on-deploy

Konfiguration

on-deploy:
    - fs/link: { from: '../../../../shared/app/config/parameters.yml',
                 to: 'app/config/parameters.yml' }

    - fs/link: { from: '../../../shared/var/logs',
                 to: 'var/logs' }

    - fs/link: { from: '../../shared/files',
                 to: 'files' }
        

on-release

Konfiguration

on-release:
    - exec: {
        cmd: 'cd ../../ && chmod -R 750 *',
        desc: 'Update file/folder rights' }
        

post-release

Konfiguration

post-release:
    - exec: {
        cmd: 'mysql
            -umyAppDbUser -pmyAppDbPassword -hmysql5.myapp.de
            contao_myapp_staging < dump.sql',
        desc: 'Importing database' }

    - exec: {
        cmd: 'rm -f dump.sql',
        desc: 'Removing database dump'}

    - exec: {
        cmd: 'php composer.phar run-script post-update-cmd',
        desc: 'Post update commands' }
        

post-deploy

Konfiguration

post-deploy:
    - exec: {
        cmd: 'rm -f dump.sql',
        desc: 'Removing database dump from local filesystem'}

    - exec: {
        cmd: 'xdg-open http://myapp.de/',
        desc: 'Check host'}
        

Magallanes

Server

/var/www/app/

    - current → 20180315121200

    - releases
        - 20170115121200
        - 20180215121200
        - 20180315121200

    -shared
        - app
            - config
                parameters.yml

        - files

        - var
            - logs
        

Magallanes

Server

Magallanes

Befehle

Applikation deployen
  1. php bin/mage deploy production
Liste der aktuellen Releases
  1. php bin/mage releases:list production
Rollback zu einem bestimmten Release
  1. php bin/mage releases:rollback production 20180215121200

Magallanes

... und noch vieles mehr ...

Siehe Dokumnetation auf https://www.magephp.com/

Magallanes
Praxisbeispiel

Praxisbeispiel

cat2018.mineralwa.de

 

trilobit GmbH

 

Peter Adelmann

Links

trilobit GmbH