Automatisches Deployment

Hallo zusammen,
ich versuche gerade ein automatisiertes Deployment aufzusetzen:

  • Lokal mit dockware/essentials mit entsprechendem shopware/production Template zusätzlich im GIT
  • Lokales GitLab mit GitLabRunner
  • entsprechende gitlab-ci.yml und Deployer
  • Production-Server ohne NPM

Ich entwickle alles lokal über Dockware und nutze die Standard gitignore ds shopware/production-Template. Ziel ist es Shopware und alle Plugins/Themes über Composer zu verwalten. Im Gitlab-Runner wird das Projekt geklont, alle Abhängigkeiten per composer installiert, das ganze dann per Deployer auf den Server geladen und dort noch verschiedene Kommandos ausgeführt (theme:compile, cache:clear/warmup,…).

Das ganze funktioniert eigentlich auch soweit - bis auf den Storefront/Administration-Build. In der offiziellen Doku Deployment with Deployer - Shopware Developer wird „bin/build-js.sh“ über Deployer auf dem Production-Server ausgeführt. Dort habe ich aber a) kein NPM, b) ist das ja gar nicht sinnvoll.

Ich könnte „bin/build-js.sh“ in der gitlab-ci.yml vor „dep deploy production“ aufruden. Im Gitlab-Runner (Docker-Container) aber habe ich keine Datenbank. Zwar könnte ich die „var/plugins.json“ lokal generieren und in Git einchecken. Dennoch ruft „bin/build-js.sh“ ja immer das Kommando „bundle:dump“ im Voraus auf.

Führe ich „bin/build-js.sh“ lokal in Dockware aus, müsste ich die entsprechenden Ordner „public/bundles“ (und vermutlich „plugins/themes“) in GIT einchecken, um sie auf den Server zu bekommen.

Oder wie ist der beste/sauberste Weg, um nur das nötigste im GIT-Repository zu haben und ein vernünftiges, automatisiertes Deployment ohne NPM auf dem Production-Server zu erhalten?

Anbei meine gitlab-ci.yml und deployer.php - in denen jetzt eigentlich „nur noch“ das Kommando „bin/build-js.sh“ fehlt. (Shopware-Projekt liegt im GIT-Repository im Order „src“)

gitlab-ci.yml

variables:
    GIT_STRATEGY: clone

stages:
    - deploy

.configureSSHAgent: &configureSSHAgent |-
    eval $(ssh-agent -s)
    echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    mkdir -p ~/.ssh
    ssh-keyscan $DEPLOYMENT_SERVER >> ~/.ssh/known_hosts
    chmod 700 ~/.ssh

Build and Deploy:
    stage: deploy
    image: shopware/development:latest
    only:
        - master
    before_script:
        - *configureSSHAgent
        - curl -LO https://deployer.org/deployer.phar
        - mv deployer.phar /usr/local/bin/dep
        - chmod +x /usr/local/bin/dep
    script:
        - cd src
        - composer self-update --2
        - composer install --no-interaction --optimize-autoloader --no-suggest
        - composer install -d vendor/shopware/recovery --no-interaction --optimize-autoloader --no-suggest
        - dep deploy production

deploy.php

<?php

namespace Deployer;

require_once 'recipe/common.php';

set('application', 'Shopware 6');
set('allow_anonymous_stats', false);
set('default_timeout', 3600); 

host('SERVER')
    ->stage('production')
    ->user('USER')
    ->set('deploy_path', 'PATH')
    ->set('writable_mode', 'chmod');

set('shared_files', [
    '.env',
]);

set('shared_dirs', [
    'custom/plugins',
    'config/jwt',
    'files',
    'var/log',
    'public/media',
    'public/thumbnail',
    'public/sitemap',
]);

set('writable_dirs', [
    'custom/plugins',
    'config/jwt',
    'files',
    'public/bundles',
    'public/css',
    'public/fonts',
    'public/js',
    'public/media',
    'public/sitemap',
    'public/theme',
    'public/thumbnail',
    'var',
]);

task('deploy:update_code', static function () {
    upload('src/', '{{release_path}}');
});

task('sw:touch_install_lock', static function () {
    run('cd {{release_path}} && touch install.lock');
});

task('sw:theme:compile', static function () {
    run('cd {{release_path}} && bin/console theme:compile');
});

task('sw:cache:clear', static function () {
    run('cd {{release_path}} && bin/console cache:clear');
});

task('sw:cache:warmup', static function () {
    run('cd {{release_path}} && bin/console cache:warmup');
    run('cd {{release_path}} && bin/console http:cache:warm:up');
});

task('sw:database:migrate', static function () {
    run('cd {{release_path}} && bin/console database:migrate --all');
});

task('sw:deploy', [
    'sw:touch_install_lock',
    'sw:database:migrate',
    'sw:theme:compile',
    'sw:cache:clear',
]);

task('deploy', [
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:update_code',
    'deploy:shared',
    'sw:deploy',
    'deploy:writable',
    'deploy:clear_paths',
    'sw:cache:warmup',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
    'success',
])->desc('Deploy your project');

after('deploy:failed', 'deploy:unlock');