.gitlab-ci.yml 11.3 KB
Newer Older
Andreas Böttger's avatar
Andreas Böttger committed
1
variables:
Andreas Böttger's avatar
Andreas Böttger committed
2 3 4
    CONTAINER_REGISTRY: collaborating.tuhh.de:5005
    CONTAINER_TEST_IMAGE: ${CONTAINER_REGISTRY}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}:${CI_COMMIT_REF_SLUG}
    CONTAINER_RELEASE_IMAGE: ${CONTAINER_REGISTRY}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}:latest
Andreas Böttger's avatar
Andreas Böttger committed
5
    BASE_IMAGE: ${CONTAINER_REGISTRY}/itbh/hopon/hopon-docker
Andreas Böttger's avatar
Andreas Böttger committed
6
    DOCKER_FILE_PATH: .
Andreas Böttger's avatar
Andreas Böttger committed
7
    
Andreas Böttger's avatar
Andreas Böttger committed
8 9 10 11 12 13
.before_script_template:
    before_script:  &before_script_definition
        - cp ./docker/docker-compose.reviews ./docker/docker-compose.yml
        - docker-compose -p ${CI_PROJECT_PATH_SLUG}-${CI_ENVIRONMENT_SLUG} -f ./docker/docker-compose.yml config
        - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CONTAINER_REGISTRY}
        - docker pull ${BASE_IMAGE}
Andreas Böttger's avatar
Andreas Böttger committed
14 15 16 17 18 19 20 21 22


.before_script_pages_template:
    before_script:  &before_script_pages_definition


stages:
    - tests
    - clone
Andreas Böttger's avatar
Andreas Böttger committed
23
    - pdf
Andreas Böttger's avatar
Andreas Böttger committed
24 25 26 27
    - pages
    - review
    - deploy
    - live
Andreas Böttger's avatar
Andreas Böttger committed
28
    - linkchecker
Andreas Böttger's avatar
Andreas Böttger committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

tests:
    stage: tests
    tags:
        - floki_development
    #before_script: *before_script_definition
    script:
        - exit 0

clone_pages:
    stage: clone
    tags:
        - floki_development
    artifacts:
        name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
        expire_in: 1 week
        paths:
            - _raw/book
            - _raw/study-book
    script:         
49
        - |
Andreas Böttger's avatar
Andreas Böttger committed
50
            set -x
51
            ssh-agent bash -c '
Andreas Böttger's avatar
Andreas Böttger committed
52 53
                set -x
                set -e
54
                ssh-add ~/.ssh/id_rsa_hopon-studybuch;
Andreas Böttger's avatar
Andreas Böttger committed
55
                ssh-keygen -l -E md5 -f ~/.ssh/id_rsa_hopon-studybuch
56 57 58 59 60 61 62
                git clone -b master git@collaborating.tuhh.de:itbh/hopon/study-book.git ./_raw/study-book; 
                if [ -n "${STUDY_BOOK_BRANCH}" ]; then 
                    git -C ./_raw/study-book checkout "${STUDY_BOOK_BRANCH}"; 
                elif git -C ./_raw/study-book ls-remote --heads --exit-code origin "${CI_COMMIT_REF_NAME}"; then 
                    git -C ./_raw/study-book checkout "${CI_COMMIT_REF_NAME}";
                fi
            '
Andreas Böttger's avatar
Andreas Böttger committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        - git -C ./_raw/study-book branch | cat
        - |
            set -x
            ssh-agent bash -c '
                set -x
                set -e
                ssh-add ~/.ssh/id_rsa_hopon-buch;
                ssh-keygen -l -E md5 -f ~/.ssh/id_rsa_hopon-buch
                git clone -b master git@collaborating.tuhh.de:itbh/hopon/book.git ./_raw/book;
                if [ -n "${BOOK_BRANCH}" ]; then 
                    git -C ./_raw/book checkout "${BOOK_BRANCH}"; 
                elif git -C ./_raw/book ls-remote --heads --exit-code origin "${CI_COMMIT_REF_NAME}"; then 
                    git -C ./_raw/book checkout "${CI_COMMIT_REF_NAME}";
                fi
            '
        - git -C ./_raw/book branch | cat
Andreas Böttger's avatar
Andreas Böttger committed
79
        
Andreas Böttger's avatar
Andreas Böttger committed
80
# Zuerst die PDFs, da im Job `pages` die URLs der Abbildungen geändert werden
Andreas Böttger's avatar
Andreas Böttger committed
81
build_pdf:
Andreas Böttger's avatar
Andreas Böttger committed
82 83 84 85 86 87
    image: docker.rz.tu-harburg.de:5000/docker/gitbook:node
    stage: pdf
    script:
        - gitbook install
        - |
            (
Andreas Böttger's avatar
Andreas Böttger committed
88
                set -x
Andreas Böttger's avatar
Andreas Böttger committed
89 90 91 92 93 94 95 96
                cd ./_raw/book;
                gitbook install;
                gitbook pdf ./ ../book.pdf
            )
        - mkdir -p ./templates/reader/book_pdf
        - mv ./_raw/book*.pdf ./templates/reader/book_pdf
        - |
            (
Andreas Böttger's avatar
Andreas Böttger committed
97
                set -x
Andreas Böttger's avatar
Andreas Böttger committed
98 99 100 101 102 103 104 105 106 107 108 109
                cd ./_raw/study-book;
                gitbook install;
                gitbook pdf ./ ../studybook.pdf
            )
        - mkdir -p ./templates/studyreader/studybook_pdf
        - mv ./_raw/studybook*.pdf ./templates/studyreader/studybook_pdf
    artifacts:
        name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
        expire_in: 1 week
        paths:
            - ./templates/reader/book_pdf
            - ./templates/studyreader/studybook_pdf
Andreas Böttger's avatar
Andreas Böttger committed
110

Andreas Böttger's avatar
Andreas Böttger committed
111 112 113 114 115 116 117 118 119
build_pages:
    image: docker.rz.tu-harburg.de:5000/docker/gitbook:node
    stage: pages
    artifacts:
        name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
        expire_in: 1 week
        paths:
            - ./templates/reader
            - ./templates/studyreader
Axel Dürkop's avatar
Axel Dürkop committed
120
    script:
Andreas Böttger's avatar
Andreas Böttger committed
121
        - |
Andreas Böttger's avatar
Andreas Böttger committed
122 123 124 125 126 127 128 129 130
            (
                # Language Verzeichnisse ermitteln und in den Pfad der Abbildungen integrieren
                set -x
                (grep -rlP '\.\.\/abb\/' ./_raw/study-book || true) | while read -r line; do
                    # NUR vier Sprachen werden berücksichtigt: de, en, fa, ar
                    if [ -n "$line" ]; then 
                        lang="$(echo "$line" | perl -pe 's!.*\/(de|en|fa|ar)\/.*!\1!g')"
                        export lang
                        echo "Processing $line"
Andreas Böttger's avatar
Andreas Böttger committed
131
                        perl -i -pe 's!(\().*?\.\.\/(abb)!$1/static/studyreader/$ENV{"lang"}/$2!gm' "$line"
Andreas Böttger's avatar
Andreas Böttger committed
132 133 134
                    fi
                done
            )
Andreas Böttger's avatar
Andreas Böttger committed
135 136
        - |
            (
Andreas Böttger's avatar
Andreas Böttger committed
137
                set -x
Andreas Böttger's avatar
Andreas Böttger committed
138
                cd ./_raw/study-book
Andreas Böttger's avatar
Andreas Böttger committed
139
                if [ -f book.json ]; then
Andreas Böttger's avatar
Andreas Böttger committed
140
                    jq -r --arg base_path "/${CI_PROJECT_PATH}/~${CI_COMMIT_REF_NAME}/" '.base_path |= $base_path' book.json | sponge book.json
Andreas Böttger's avatar
Andreas Böttger committed
141 142
                fi;
                if [ -f book.json ]; then
Andreas Böttger's avatar
Andreas Böttger committed
143 144 145 146 147
                    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
Andreas Böttger's avatar
Andreas Böttger committed
148
                (
Andreas Böttger's avatar
Andreas Böttger committed
149 150 151
                    set -x
                    (grep -rlP '\.\.\/static\/' . || true) | while read -r line; do 
                        # NUR vier Sprachen werden berücksichtigt: de, en, fa, ar
Andreas Böttger's avatar
Andreas Böttger committed
152
                        if [ -n "$line" ]; then
Andreas Böttger's avatar
Andreas Böttger committed
153 154
                        #    lang="$(echo "$line" | perl -pe 's!.*\/(de|en|fa|ar)\/.*!\1!g')";
                        #    export lang
Andreas Böttger's avatar
Andreas Böttger committed
155 156 157 158 159
                            echo "Processing $line"
                            perl -i -pe 's!\.\.(/static)!$1!gm' "$line"
                        fi
                    done
                )
Andreas Böttger's avatar
Andreas Böttger committed
160
            )            
Andreas Böttger's avatar
Andreas Böttger committed
161 162 163
        - rm -rf ./templates/studyreader
        - mv ./_raw/study-book/_book ./templates/studyreader
        - |
Andreas Böttger's avatar
Andreas Böttger committed
164 165 166 167 168 169 170 171 172
            (
                # Language Verzeichnisse ermitteln und in den Pfad der Abbildungen integrieren
                set -x
                (grep -rlP '\.\.\/abb\/' ./_raw/book || true) | while read -r line; do
                    # NUR vier Sprachen werden berücksichtigt: de, en, fa, ar
                    if [ -n "$line" ]; then 
                        lang="$(echo "$line" | perl -pe 's!.*\/(de|en|fa|ar)\/.*!\1!g')"
                        export lang
                        echo "Processing $line"
Andreas Böttger's avatar
Andreas Böttger committed
173
                        perl -i -pe 's!(\().*?\.\.\/(abb)!$1/static/reader/$ENV{"lang"}/$2!gm' "$line"
Andreas Böttger's avatar
Andreas Böttger committed
174 175 176
                    fi
                done
            )
Andreas Böttger's avatar
Andreas Böttger committed
177 178
        - |
            (
Andreas Böttger's avatar
Andreas Böttger committed
179
                set -x
Andreas Böttger's avatar
Andreas Böttger committed
180
                cd ./_raw/book;
Andreas Böttger's avatar
Andreas Böttger committed
181
                if [ -f book.json ]; then
Andreas Böttger's avatar
Andreas Böttger committed
182
                    jq -r --arg base_path "/${CI_PROJECT_PATH}/~${CI_COMMIT_REF_NAME}/" '.base_path |= $base_path' book.json | sponge book.json
Andreas Böttger's avatar
Andreas Böttger committed
183 184
                fi;
                if [ -f book.json ]; then
Andreas Böttger's avatar
Andreas Böttger committed
185
                    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
Andreas Böttger's avatar
Andreas Böttger committed
186
                fi;
Andreas Böttger's avatar
Andreas Böttger committed
187 188
                if [ -f book.json ]; then cat book.json; fi
                gitbook install
Andreas Böttger's avatar
Andreas Böttger committed
189
                gitbook build
Andreas Böttger's avatar
Andreas Böttger committed
190
                (
Andreas Böttger's avatar
Andreas Böttger committed
191 192 193
                    set -x
                    (grep -rlP '\.\.\/static\/' . || true) | while read -r line; do 
                        # NUR vier Sprachen werden berücksichtigt: de, en, fa, ar
Andreas Böttger's avatar
Andreas Böttger committed
194
                        if [ -n "$line" ]; then
Andreas Böttger's avatar
Andreas Böttger committed
195 196
                        #    lang="$(echo "$line" | perl -pe 's!.*\/(de|en|fa|ar)\/.*!\1!g')";
                        #    export lang
Andreas Böttger's avatar
Andreas Böttger committed
197 198 199 200 201
                            echo "Processing $line"
                            perl -i -pe 's!\.\.(/static)!$1!gm' "$line"
                        fi
                    done
                )
Andreas Böttger's avatar
Andreas Böttger committed
202 203 204
            )
        - rm -rf ./templates/reader
        - mv ./_raw/book/_book ./templates/reader
Axel Dürkop's avatar
Axel Dürkop committed
205

Andreas Böttger's avatar
Andreas Böttger committed
206 207
start_review:
    stage: review
Andreas Böttger's avatar
Andreas Böttger committed
208
    before_script: *before_script_definition
Andreas Böttger's avatar
Andreas Böttger committed
209
    script:
Andreas Böttger's avatar
Andreas Böttger committed
210 211 212 213 214 215
        # Project specific
        - export SECRET_KEY=$(openssl rand -base64 12)
        - export HOST_IP=$(gethostip -d $(hostname --fqdn))
        - docker-compose -p ${CI_PROJECT_PATH_SLUG}-${CI_ENVIRONMENT_SLUG} -f ./docker/docker-compose.yml build --no-cache --force-rm
        - docker-compose -p ${CI_PROJECT_PATH_SLUG}-${CI_ENVIRONMENT_SLUG} -f ./docker/docker-compose.yml down
        - docker-compose -p ${CI_PROJECT_PATH_SLUG}-${CI_ENVIRONMENT_SLUG} -f ./docker/docker-compose.yml up -d
Andreas Böttger's avatar
Andreas Böttger committed
216 217 218 219 220 221 222
        - mkdir -p ./_linkchecker
        - echo "https://${CI_PROJECT_ID}-${CI_ENVIRONMENT_SLUG}.hpn.rz.tuhh.de/" >./_linkchecker/url
    artifacts:
        name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
        expire_in: 1 week
        paths:
            - ./_linkchecker
Andreas Böttger's avatar
Andreas Böttger committed
223
    environment:
Andreas Böttger's avatar
Andreas Böttger committed
224
        name: ${CI_COMMIT_REF_NAME}
Andreas Böttger's avatar
Andreas Böttger committed
225
        url: https://${CI_PROJECT_ID}-${CI_ENVIRONMENT_SLUG}.hpn.rz.tuhh.de/
Andreas Böttger's avatar
Andreas Böttger committed
226 227 228 229
        on_stop: stop_review
    only:
        - branches
    tags:
Andreas Böttger's avatar
Andreas Böttger committed
230
        - floki_development
Andreas Böttger's avatar
Andreas Böttger committed
231 232
    except:
        - master
Axel Dürkop's avatar
Axel Dürkop committed
233

Andreas Böttger's avatar
Andreas Böttger committed
234 235 236 237 238
stop_review:
    stage: review
    variables:
        GIT_STRATEGY: none
    script:
239
        - cp ./docker/docker-compose.reviews ./docker/docker-compose.yml
Andreas Böttger's avatar
Andreas Böttger committed
240
        - docker-compose -p ${CI_PROJECT_PATH_SLUG}-${CI_ENVIRONMENT_SLUG} -f ./docker/docker-compose.yml down
Andreas Böttger's avatar
Andreas Böttger committed
241 242
    when: manual
    environment:
Andreas Böttger's avatar
Andreas Böttger committed
243
        name: ${CI_COMMIT_REF_NAME}
Andreas Böttger's avatar
Andreas Böttger committed
244 245 246 247
        action: stop
    only:
        - branches
    tags:
Andreas Böttger's avatar
Andreas Böttger committed
248
        - floki_development
Andreas Böttger's avatar
Andreas Böttger committed
249 250
    except:
        - master
Axel Dürkop's avatar
Axel Dürkop committed
251

Andreas Böttger's avatar
Andreas Böttger committed
252
deploy_registry:
Andreas Böttger's avatar
Andreas Böttger committed
253
    stage: deploy
Andreas Böttger's avatar
Andreas Böttger committed
254
    before_script: *before_script_definition
Andreas Böttger's avatar
Andreas Böttger committed
255
    script:
Andreas Böttger's avatar
Andreas Böttger committed
256 257
        - docker build --no-cache --pull -t ${CONTAINER_RELEASE_IMAGE} ${DOCKER_FILE_PATH}
        - docker push ${CONTAINER_RELEASE_IMAGE}
Andreas Böttger's avatar
Andreas Böttger committed
258
    tags:
Andreas Böttger's avatar
Andreas Böttger committed
259
        - floki_build
Andreas Böttger's avatar
Andreas Böttger committed
260
    only:
Andreas Böttger's avatar
Andreas Böttger committed
261
        - master
Andreas Böttger's avatar
Andreas Böttger committed
262

Andreas Böttger's avatar
Andreas Böttger committed
263
deploy_live:
Andreas Böttger's avatar
Andreas Böttger committed
264
    stage: live
Andreas Böttger's avatar
Andreas Böttger committed
265
    script:
Andreas Böttger's avatar
Andreas Böttger committed
266
        - echo ${CONTAINER_RELEASE_IMAGE}
Andreas Böttger's avatar
Andreas Böttger committed
267 268
        - ssh flint.rz.tu-harburg.de -p 22 "sudo docker pull ${CONTAINER_RELEASE_IMAGE}"
        - ssh flint.rz.tu-harburg.de -p 22 "sudo systemctl restart docker-itbh--hop-on--fahrplan"
Andreas Böttger's avatar
Andreas Böttger committed
269 270 271 272 273 274 275
    tags:
        - deploy
    environment:
        name: production
        url: https://hopon-newcomers.com
    only:
        - master
Andreas Böttger's avatar
Andreas Böttger committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
    when: manual

linkchecker:intern:
    stage: linkchecker
    except:
        - master
    when: manual
    image:
        name: linkchecker/linkchecker
        entrypoint: [""]
    script:
        - echo "PLEASE be patient, the application may take a few minutes before it is available."
        - cat ./_linkchecker/url
        - linkchecker --recursion-level 10 --threads 10 --no-status --no-robots --no-warnings --ignore-url 'https://fonts.gstatic.com/{0,1}$' $(cat ./_linkchecker/url)
        
linkchecker:all:
    stage: linkchecker
    except:
        - master
    when: manual
    image:
        name: linkchecker/linkchecker
        entrypoint: [""]
    script:
        - echo "PLEASE be patient, the application may take a few minutes before it is available."
        - cat ./_linkchecker/url
        - linkchecker --recursion-level 10 --threads 10 --no-status --no-robots --no-warnings --check-extern --ignore-url 'https://fonts.gstatic.com/{0,1}$' $(cat ./_linkchecker/url)