Shopware 6: Automatisiertes Security-Update mit GitLab

Eine wilde GitLab-Pipeline, die sicherlich noch mehr getestet werden sollte

Diese Pipeline erstellt automatisch einen Merge Request mit einem Update des Shopware Security Plugins, basierend auf einem Tag.

Voraussetzungen

  • GitLab
  • Shopware 6 Composer-Setup

Variablen

  • SSH_DEPLOY_PRIVATE_KEY
    • Der private Schlüssel eines erstellten Schlüsselpaars muss in dieser Variable gespeichert werden
    • Der öffentliche Schlüssel muss unter „Settings > Repository > Deploy Key“ eingetragen werden
      • Nicht vergessen, Schreibrechte zu vergeben
  • SSH_KNOWN_HOSTS

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
stages:
  - security

securityUpdate:
  stage: security
  rules:
    - if: '$CI_COMMIT_TAG =~ /security-.*/'
  image: "kellerkinder/pipeline-image:8.0"
  before_script:
    - eval $(ssh-agent -s)
    - echo "${SSH_DEPLOY_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh && > ~/.ssh/known_hosts
    - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - chmod 700 ~/.ssh
    - git config user.name "security"
    - git config user.email "ci@example"
    - git remote remove origin || true
    - git remote add origin "git@gitlab.com:path/repo.git"
  script:
    - cd ${CI_PROJECT_DIR} && composer install --no-interaction --optimize-autoloader
    - composer update store.shopware.com/swagplatformsecurity
    - git checkout -b feature/security-patch-$(date +%F)
    - git add -A
    - |
      if git diff --cached --quiet; then
        echo "Kein Security-Update verfügbar – nichts zu committen."
        exit 0
      fi
    - git commit -m "Security Update $(date +%F)"
    - git push --set-upstream origin feature/security-patch-$(date +%F)

Beispiel-Tag

security-YYMMDD

Erstellt mit Hugo
Theme Stack gestaltet von Jimmy