Staattiset verkkosivustot latautuvat nopeammin ja tarjoavat vähemmän hyökkäyspintaa. Näytän, miten CMS-sivu muunnetaan Gitlab Pipline -palvelun kautta. Ensin luon rakennusvaiheen, joka luo staattisen kopion wgetin avulla.
uild:
stage: build
when: always
only:
- master
script:
- mkdir static
- rm -r .git
- wget -k -K -E -r -l 10 -p -N -F --restrict-file-names=windows -nH http://wordpress-adresse/ -P static >> /dev/null 2>&1 || true
- find . -type f -exec sed -i 's#http://wordpress-adresse/#\//m#g' {} + >> /dev/null 2>&1
artifacts:
paths:
- static/
expire_in: 24 week
Tulos tai staattinen artefakti arkistoidaan 24 viikon ajaksi, ja se voidaan ottaa käyttöön milloin tahansa putken kautta.
Seuraavassa vaiheessa tulos voidaan ottaa käyttöön:
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 -
stage: deploy
when: always
only:
- master
script:
- rsync -avuz -e 'ssh -p {-P Port wenn nötig} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' static/* user@www.domain.com:/path/to/www.domain.de/public/
Valmis! Ohessa jälleen kerran koko putki (.gitlab_ci.yml).
stages:
- build
- deploy
build:
stage: build
when: always
only:
- master
script:
- mkdir static
- rm -r .git
- wget -k -K -E -r -l 10 -p -N -F --restrict-file-names=windows -nH http://wordpress-adresse/ -P static >> /dev/null 2>&1 || true
- find . -type f -exec sed -i 's#http://wordpress-adresse/#\//m#g' {} + >> /dev/null 2>&1
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:
- rsync -avuz -e 'ssh -p {-P Port wenn nötig} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' static/* user@www.domain.com:/path/to/www.domain.de/public/