Fork me on GitHub

Herr Knedel/Gitlab semineri: Gitllab boru hattı aracılığıyla statik bir WordPress kopyasını nasıl dağıtabilirim?

Created Sun, 16 Feb 2020 00:00:00 +0000 Modified Sat, 01 Oct 2022 10:41:11 +0000 Schwierigkeitsgrad: Nicht zu leicht und nicht zu schwer

301 Words

Statik web siteleri daha hızlı yüklenir ve daha az saldırı yüzeyi sunar. Gitlab Pipline aracılığıyla bir CMS sayfasını nasıl dönüştürebileceğinizi gösteriyorum. İlk olarak, wget aracılığıyla statik bir kopya oluşturan bir derleme aşaması oluşturuyorum.

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

Sonuç veya statik eser 24 hafta boyunca arşivlenir ve boru hattı aracılığıyla herhangi bir zamanda dağıtılabilir.

Bir sonraki adımda, sonuç dağıtılabilir:

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/

Tamamdır! Bir kez daha tüm boru hattını (.gitlab_ci.yml) ekte bulabilirsiniz

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/