.gitlab-ci.yml 2.37 KB
Newer Older
Axel Dürkop's avatar
Axel Dürkop committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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
variables:
    COLON: ':'

stages:
    - build
    - review
    - deploy

build:
    stage: build
    only:
        - branches
    tags:
        - development
    script:
        - pwd
        - gitbook install
        - gitbook build
        # Quick and dirty hack: The creation of the PDF document does not always work. This seems to be a bug.
        - mkdir -p book_pdf; until gitbook pdf ./ ./book_pdf/book.pdf; do printf "$s\n" "failure, next try …"; done

    artifacts:
        name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
        paths:
            # Was hier nicht gelistet ist, landet auch nicht in der `review`-Phase
            - _book
            - book_pdf


start_review:
    stage: review
    script:
        - sshpass -p "$SSH_PASSWD" ssh -p "$SSH_PORT" $SSH_USER@$HOST_NAME "mkdir -p /usr/share/nginx/html/review/$CI_COMMIT_REF_NAME"
        - sshpass -p "$SSH_PASSWD" scp -P "$SSH_PORT" -r _book/* $SSH_USER@$HOST_NAME:/usr/share/nginx/html/review/$CI_COMMIT_REF_NAME
        - sshpass -p "$SSH_PASSWD" scp -P "$SSH_PORT" -r book_pdf $SSH_USER@$HOST_NAME:/usr/share/nginx/html/review/${CI_COMMIT_REF_NAME}
    environment:
        name: review/$CI_COMMIT_REF_NAME
        url: http://$HOST_NAME$COLON$HTTP_PORT/review/$CI_COMMIT_REF_NAME/
        #url: https://$PROXY_HOST_NAME/reviews/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/
        on_stop: stop_review
    only:
        - branches
    tags:
        - development
    except:
        - master

stop_review:
    stage: review
    variables:
        GIT_STRATEGY: none
    script:
        - sshpass -p "$SSH_PASSWD" ssh -p "$SSH_PORT" $SSH_USER@$HOST_NAME "rm -rf /usr/share/nginx/html/review/$CI_COMMIT_REF_NAME"
    when: manual
    environment:
        name: review/$CI_COMMIT_REF_NAME
        action: stop
    only:
        - branches
    tags:
        - development
    except:
        - master

deploy:
    stage: deploy
    only:
        - master
    tags:
        - production
    script:
        - sshpass -p "$SSH_PASSWD" ssh -p "$SSH_PORT" $SSH_USER@$HOST_NAME "mkdir -p /usr/share/nginx/html/production"
        - sshpass -p "$SSH_PASSWD" scp -P "$SSH_PORT" -r _book/* $SSH_USER@$HOST_NAME:/usr/share/nginx/html/production
Andreas Böttger's avatar
Andreas Böttger committed
74
        - sshpass -p "$SSH_PASSWD" scp -P "$SSH_PORT" -r book_pdf $SSH_USER@$HOST_NAME:/usr/share/nginx/html/production
Axel Dürkop's avatar
Axel Dürkop committed
75 76
    environment:
        name: production
Axel Dürkop's avatar
Axel Dürkop committed
77
        url: https://$PROXY_HOST_NAME/$CI_PROJECT_PATH/