静态网站加载速度更快,提供的攻击面更小。我告诉你如何通过Gitlab Pipline转换一个CMS页面。首先,我创建了一个构建阶段,通过wget生成一个静态副本。
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
结果或静态人工制品被存档24周,并可在任何时候通过管道部署。
在下一步,可以对结果进行部署。
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/
完成了!再次附上整个管道(.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/