Gitlab-Seminar: Wie kann ich eine statische WordPress-Kopie über die Gitllab-Pipeline deployen?
Statische Webseiten laden schneller und bieten weniger Angriffsfläche. Ich zeigen Dir, wie Du Deine CMS-Seiten über Gitlab-Pipline konvertierst. Zunächst lege ich eine Build-Stage an, die eine statische Kopie via wget erzeugt.
build:
stage: build
when: always
only:
- master
script:
- mkdir static
- rm -r .git
- wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows http://wordpress-adresse/ -P static || true
artifacts:
paths:
- static/
expire_in: 24 week
Das Ergebnis bzw. statische Artefakt wird für 24 Woche archiviert und lässt sich jeder Zeit über die Pipeline deployen.

Im nächst Schritt kann das Ergebnis deployed werden:
live:
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
stage: deploy
when: always
only:
- master
script:
- scp {-P Port wenn nötig} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r static/path/to/src/* user@www.domain.com:/path/to/www.domain.de/public/
Fertig! Anbei noch einmal die ganze Pipeline (.gitlab_ci.yml)
stages:
- build
- deploy
build:
stage: build
when: always
only:
- master
script:
- mkdir static
- rm -r .git
- wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows http://wordpress-adresse/ -P static || true
artifacts:
paths:
- static/
expire_in: 24 week
live:
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
stage: deploy
when: always
only:
- master
script:
- scp {-P Port wenn nötig} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r static/path/to/src/* user@www.domain.com:/path/to/www.domain.de/public/