.gitlab-ci.yml 5.04 KB
Newer Older
Axel Dürkop's avatar
Axel Dürkop committed
1
image: ruby:2.6
Andreas Böttger's avatar
Andreas Böttger committed
2

Andreas Böttger's avatar
Andreas Böttger committed
3 4 5
variables:
    JEKYLL_ENV: production
  
Andreas Böttger's avatar
Andreas Böttger committed
6
stages:
Andreas Böttger's avatar
Andreas Böttger committed
7 8
    - setup
    - test
Andreas Böttger's avatar
Andreas Böttger committed
9
    - pages
Andreas Böttger's avatar
Andreas Böttger committed
10 11
    - review
    - deploy
Andreas Böttger's avatar
Andreas Böttger committed
12
    - clean
Andreas Böttger's avatar
Andreas Böttger committed
13
    - linkchecker
Andreas Böttger's avatar
Andreas Böttger committed
14 15 16 17 18

before_script:
    # https://docs.gitlab.com/ee/ci/ssh_keys/README.html
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
Andreas Böttger's avatar
Andreas Böttger committed
19
    
Andreas Böttger's avatar
Andreas Böttger committed
20 21 22 23 24 25
    - export LC_ALL="C.UTF-8"; export LANG="en_US.UTF-8"; export LANGUAGE="en_US.UTF-8"
    - export BUNDLE_PATH="vendor/bundle"

prepare:
    stage: setup
    cache:
Andreas Böttger's avatar
Andreas Böttger committed
26
        key: "$CI_COMMIT_REF_SLUG"
Andreas Böttger's avatar
Andreas Böttger committed
27 28 29 30 31 32 33 34
        paths:
            - vendor/bundle
    script:
        - bundle install

test:
    stage: test
    script:
Andreas Böttger's avatar
Andreas Böttger committed
35
        - 'perl -i -pe ''s!.*baseurl:\s.*!baseurl: "$ENV{''REVIEW_BASE_DIR''}/~$ENV{''CI_COMMIT_REF_NAME''}/"\n!g'' _config.yml'
Andreas Böttger's avatar
Andreas Böttger committed
36
        - cat _config.yml
Andreas Böttger's avatar
Andreas Böttger committed
37
        - bundle install
Andreas Böttger's avatar
Andreas Böttger committed
38 39
        - bundle exec jekyll build -d test
    cache:
Andreas Böttger's avatar
Andreas Böttger committed
40
        key: "$CI_COMMIT_REF_SLUG"
Andreas Böttger's avatar
Andreas Böttger committed
41 42 43 44 45
        paths:
            - vendor/bundle
        policy: pull
    except:
        - master
Andreas Böttger's avatar
Andreas Böttger committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
        
review:pages:
    stage: pages
    script:
        - bundle install
        - 'perl -i -pe ''s!.*baseurl:\s.*!baseurl: "$ENV{''REVIEW_BASE_DIR''}/~$ENV{''CI_COMMIT_REF_NAME''}/"\n!g'' _config.yml'
        - cat _config.yml
        - bundle exec jekyll build -d public
    except:
        - master
    artifacts:
        paths:
            - public
    cache:
        key: "$CI_COMMIT_REF_SLUG"
        paths:
            - vendor/bundle
        policy: pull
        
Andreas Böttger's avatar
Andreas Böttger committed
65 66 67
review:start:
    stage: review
    script:
Andreas Böttger's avatar
Andreas Böttger committed
68 69 70 71 72 73
        - echo "$REVIEW_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
        - chmod 644 ~/.ssh/known_hosts
        - eval $(ssh-agent -s)
        - echo "$REVIEW_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - ssh -p "${REVIEW_SSH_PORT}" "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}" "mkdir -p /usr/share/nginx/html/~${CI_COMMIT_REF_NAME}"
        - scp -P "${REVIEW_SSH_PORT}" -r public/* "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}":"/usr/share/nginx/html/~${CI_COMMIT_REF_NAME}"
Andreas Böttger's avatar
Andreas Böttger committed
74 75
    except:
        - master
Andreas Böttger's avatar
Andreas Böttger committed
76 77
    environment:
        name: $CI_COMMIT_REF_NAME
Andreas Böttger's avatar
Andreas Böttger committed
78
        url: https://${REVIEW_PROXY_HOST_NAME}${REVIEW_BASE_DIR}~${CI_COMMIT_REF_NAME}/
Andreas Böttger's avatar
Andreas Böttger committed
79
        on_stop: review:stop
Andreas Böttger's avatar
Andreas Böttger committed
80

Andreas Böttger's avatar
Andreas Böttger committed
81
  
Andreas Böttger's avatar
Andreas Böttger committed
82 83 84
review:stop:
    stage: review
    script:
Andreas Böttger's avatar
Andreas Böttger committed
85 86 87 88 89
        - echo "$REVIEW_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
        - chmod 644 ~/.ssh/known_hosts
        - eval $(ssh-agent -s)
        - echo "$REVIEW_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - ssh -p "${REVIEW_SSH_PORT}" "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}" "rm -rf /usr/share/nginx/html/~${CI_COMMIT_REF_NAME}"
Andreas Böttger's avatar
Andreas Böttger committed
90
    when: manual
Andreas Böttger's avatar
Andreas Böttger committed
91 92
    except:
        - master
Andreas Böttger's avatar
Andreas Böttger committed
93
    environment:
Andreas Böttger's avatar
Andreas Böttger committed
94
        name: $CI_COMMIT_REF_NAME
Andreas Böttger's avatar
Andreas Böttger committed
95
        action: stop
Andreas Böttger's avatar
Andreas Böttger committed
96 97 98
        
pages:
    stage: pages
Andreas Böttger's avatar
Andreas Böttger committed
99
    only:
Andreas Böttger's avatar
Andreas Böttger committed
100 101 102
        - master
    script:
        - bundle install
Andreas Böttger's avatar
Andreas Böttger committed
103 104 105 106 107 108
        # Wenn `url: https://$PROXY_HOST_NAME/` verwendet wird,
        # dann wird `$ENV{''BASE_DIR''}/~$ENV{''CI_COMMIT_REF_NAME''}` NICHT
        # benötigt
        - 'perl -i -pe ''s!.*baseurl:\s.*!baseurl: "$ENV{''BASE_DIR''}"\n!g'' _config.yml'
        #- 'perl -i -pe ''s!.*baseurl:\s.*!baseurl: "/"\n!g'' _config.yml'
        - cat _config.yml
Andreas Böttger's avatar
Andreas Böttger committed
109
        - bundle exec jekyll build -d public
Andreas Böttger's avatar
Andreas Böttger committed
110 111 112
    artifacts:
        paths:
            - public
Andreas Böttger's avatar
Andreas Böttger committed
113
    cache:
Andreas Böttger's avatar
Andreas Böttger committed
114
        key: "$CI_COMMIT_REF_SLUG"
Andreas Böttger's avatar
Andreas Böttger committed
115 116
        paths:
            - vendor/bundle
Andreas Böttger's avatar
Andreas Böttger committed
117
        policy: pull
Andreas Böttger's avatar
Andreas Böttger committed
118

Andreas Böttger's avatar
Andreas Böttger committed
119
deploy:
Andreas Böttger's avatar
Andreas Böttger committed
120 121
    stage: deploy
    only:
Andreas Böttger's avatar
Andreas Böttger committed
122 123
        - master
    except:
Andreas Böttger's avatar
Andreas Böttger committed
124 125 126 127 128 129 130 131 132
        - schedules
    script:
        - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
        - chmod 644 ~/.ssh/known_hosts
        - eval $(ssh-agent -s)
        - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - ssh -p "${SSH_PORT}" "${SSH_USER}"@"${HOST_NAME}" "mkdir -p /usr/share/nginx/html"
        - scp -P "${SSH_PORT}" -r public/* "${SSH_USER}"@"${HOST_NAME}":"/usr/share/nginx/html"
    environment:
Andreas Böttger's avatar
Andreas Böttger committed
133 134 135 136
        name: $CI_COMMIT_REF_NAME
        url: https://$PROXY_HOST_NAME$BASE_DIR
        #url: https://$PROXY_HOST_NAME/
        
Andreas Böttger's avatar
Andreas Böttger committed
137 138 139 140 141 142 143 144 145 146
clean:
    stage: clean
    script:
        - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
        - chmod 644 ~/.ssh/known_hosts
        - eval $(ssh-agent -s)
        - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
        - ssh -p "${SSH_PORT}" "${SSH_USER}"@"${HOST_NAME}" "rm -rf /usr/share/nginx/html/*"
    when: manual
    only:
Andreas Böttger's avatar
Andreas Böttger committed
147
        - master
Andreas Böttger's avatar
Andreas Böttger committed
148 149 150
    environment:
        name: $CI_COMMIT_REF_NAME
        action: stop
Andreas Böttger's avatar
Andreas Böttger committed
151
        
Andreas Böttger's avatar
Andreas Böttger committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
linkchecker:intern:
  stage: linkchecker
  except:
    - master
  image:
    name: linkchecker/linkchecker
    entrypoint: [""]
  script:
    - linkchecker --recursion-level 10 --threads 10 --no-status --no-robots --no-warnings --ignore-url 'https://fonts.gstatic.com/{0,1}$' https://${REVIEW_PROXY_HOST_NAME}/${REVIEW_BASE_DIR}/~${CI_COMMIT_REF_NAME}/
  when: manual
    
linkchecker:all:
  stage: linkchecker
  except:
    - master
  image:
    name: linkchecker/linkchecker
    entrypoint: [""]
  script:
    - linkchecker --recursion-level 10 --threads 10 --no-status --no-robots --no-warnings --check-extern --ignore-url 'https://fonts.gstatic.com/{0,1}$' https://${REVIEW_PROXY_HOST_NAME}/${REVIEW_BASE_DIR}/~${CI_COMMIT_REF_NAME}/
  when: manual