.gitlab-ci.yml 6.79 KB
Newer Older
Andreas Böttger's avatar
Andreas Böttger committed
1
image: docker.rz.tu-harburg.de:5000/rzt/images/gitbook:node
Axel Dürkop's avatar
Axel Dürkop committed
2 3

stages:
4 5 6
    - setup
    - test
    - build
Axel Dürkop's avatar
Axel Dürkop committed
7 8
    - review
    - deploy
9 10 11 12 13 14 15 16 17 18 19 20
    - clean
    - linkchecker

before_script:
    # https://docs.gitlab.com/ee/ci/ssh_keys/README.html
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh

setup:
    stage: setup
    cache:
        key: "$CI_COMMIT_REF_SLUG"
Axel Dürkop's avatar
Axel Dürkop committed
21
        paths:
22
            - node_modules
Axel Dürkop's avatar
Axel Dürkop committed
23
    script:
24
        - gitbook install
Axel Dürkop's avatar
Axel Dürkop committed
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

test:
  stage: test
  script:
    #- if [ -f book.json ]; then jq -r --arg base_path "/${CI_PROJECT_PATH}/~${CI_COMMIT_REF_NAME}/" '.base_path |= $base_path' book.json | sponge book.json; fi
    #- if [ -f book.json ]; then jq -r --arg pluginsConfig__downloadpdf_base "/${CI_PROJECT_PATH}/~${CI_COMMIT_REF_NAME}/book_pdf/book.pdf?/" '.pluginsConfig.downloadpdf.base |= $pluginsConfig__downloadpdf_base' book.json | sponge book.json; fi
    #- if [ -f book.json ]; then cat book.json; fi

    #- if [ -f book.json ]; then jq -r --arg base_path "/${CI_PROJECT_PATH}/" '.base_path |= $base_path' book.json | sponge book.json; fi
    #- if [ -f book.json ]; then jq -r --arg pluginsConfig__downloadpdf_base "/${CI_PROJECT_PATH}/book_pdf/book.pdf?/" '.pluginsConfig.downloadpdf.base |= $pluginsConfig__downloadpdf_base' book.json | sponge book.json; fi
    #- if [ -f book.json ]; then cat book.json; fi
    
    - exit 0
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules
    policy: pull
  except:
  - master

pdf:
  stage: build
  script:
    - gitbook install
    - mkdir -p book_pdf
    - gitbook pdf ./ ./book_pdf/book.pdf
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules
      - book_pdf
  artifacts:
      name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
      paths:
          - book_pdf

pages:branches:
  stage: build
  script:
    - if [ -f book.json ]; then jq -r --arg base_path "/${CI_PROJECT_PATH}/~${CI_COMMIT_REF_NAME}/" '.base_path |= $base_path' book.json | sponge book.json; fi
    - if [ -f book.json ]; then jq -r --arg pluginsConfig__downloadpdf_base "/${CI_PROJECT_PATH}/~${CI_COMMIT_REF_NAME}/book_pdf/book.pdf?/" '.pluginsConfig.downloadpdf.base |= $pluginsConfig__downloadpdf_base' book.json | sponge book.json; fi
    - 'if [ -f book.json ]; then cat book.json; fi'
    - gitbook install
    - gitbook build
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules
      - _book
  artifacts:
    paths:
    - _book
  except:
  - master

pages:master:
  stage: build
  script:
    - if [ -f book.json ]; then jq -r --arg base_path "/${CI_PROJECT_PATH}/" '.base_path |= $base_path' book.json | sponge book.json; fi
    - if [ -f book.json ]; then jq -r --arg pluginsConfig__downloadpdf_base "/${CI_PROJECT_PATH}/book_pdf/book.pdf?/" '.pluginsConfig.downloadpdf.base |= $pluginsConfig__downloadpdf_base' book.json | sponge book.json; fi
    - 'if [ -f book.json ]; then cat book.json; fi'
    - gitbook install
    - gitbook build
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules
      - _book
  artifacts:
    paths:
    - _book
  only:
  - master

review:start:
  stage: review
  script:
    - 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 _book/* "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}":"/usr/share/nginx/html/~${CI_COMMIT_REF_NAME}"
    - if [ -d book_pdf ]; then ssh -p "${REVIEW_SSH_PORT}" "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}" "mkdir -p /usr/share/nginx/html/~${CI_COMMIT_REF_NAME}/book_pdf"; fi
    - if [ -d book_pdf ]; then scp -P "${REVIEW_SSH_PORT}" -r book_pdf/* "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}":"/usr/share/nginx/html/~${CI_COMMIT_REF_NAME}/book_pdf"; fi
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - _book
      - book_pdf
    policy: pull
  except:
  - master
  environment:
    name: $CI_COMMIT_REF_NAME
    url: https://${REVIEW_PROXY_HOST_NAME}/${REVIEW_BASE_DIR}/~${CI_COMMIT_REF_NAME}/
    on_stop: review:stop
  
Andreas Böttger's avatar
Andreas Böttger committed
125
review:stop:
126 127 128 129 130 131 132 133 134 135 136 137 138
  stage: review
  script:
  - 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}"
  when: manual
  except:
  - master
  environment:
    name: $CI_COMMIT_REF_NAME
    action: stop
Andreas Böttger's avatar
Andreas Böttger committed
139
    
Axel Dürkop's avatar
Axel Dürkop committed
140 141 142 143
deploy:
    stage: deploy
    only:
        - master
144 145
    except:
        - schedules
Axel Dürkop's avatar
Axel Dürkop committed
146
    script:
147 148 149 150 151 152 153 154 155 156 157 158 159 160
        - 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 _book/* "${SSH_USER}"@"${HOST_NAME}":"/usr/share/nginx/html"
        - if [ -d book_pdf ]; then ssh -p "${SSH_PORT}" "${SSH_USER}"@"${HOST_NAME}" "mkdir -p /usr/share/nginx/html/book_pdf"; fi
        - if [ -d book_pdf ]; then scp -P "${SSH_PORT}" -r book_pdf/* "${SSH_USER}"@"${HOST_NAME}":"/usr/share/nginx/html/book_pdf"; fi
    cache:
        key: "$CI_COMMIT_REF_SLUG"
        paths:
          - _book
          - book_pdf
        policy: pull   
Axel Dürkop's avatar
Axel Dürkop committed
161
    environment:
162
        name: $CI_COMMIT_REF_NAME
Andreas Böttger's avatar
Andreas Böttger committed
163
        #url: http://$HOST_NAME$COLON$HTTP_PORT/production/
Andreas Böttger's avatar
Andreas Böttger committed
164
        #url: https://$PROXY_HOST_NAME/$BASE_PATH/
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
        url: https://$PROXY_HOST_NAME/${BASE_DIR}/
        #url: https://$PROXY_HOST_NAME/
        
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:
    - master
  environment:
    name: $CI_COMMIT_REF_NAME
    action: stop
    
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