.gitlab-ci.yml 2.83 KB
Newer Older
Andreas Böttger's avatar
Andreas Böttger committed
1
variables:
Andreas Böttger's avatar
Andreas Böttger committed
2
    REVIEW_IMAGE: docker.rz.tu-harburg.de:5000/docker/nginx--review-apps:latest
Andreas Böttger's avatar
Andreas Böttger committed
3 4
    BUILD_IMAGE: docker.rz.tu-harburg.de:5000/docker/gitbook-itbh-glr:latest
    
Andreas Böttger's avatar
Andreas Böttger committed
5
    DOCKER_CONTAINER_NAME: ${CI_PROJECT_PATH_SLUG}-${CI_ENVIRONMENT_SLUG}
Andreas Böttger's avatar
Andreas Böttger committed
6 7 8 9
    
before_script:
    - sudo docker pull ${BUILD_IMAGE}
    - sudo docker pull ${REVIEW_IMAGE}
Andreas Böttger's avatar
Andreas Böttger committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

stages:
    - review
    - deploy
    
pdf:
    stage: review
    only:
        - branches
    when: manual
    retry: 2
    tags:
        - development
    script:
        - pwd
Andreas Böttger's avatar
Andreas Böttger committed
25
        - mkdir -p book_pdf; sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} pdf ./ ./book_pdf/book.pdf
Andreas Böttger's avatar
Andreas Böttger committed
26 27 28 29 30 31 32 33 34 35
    artifacts:
        name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
        paths:
            - book_pdf
    
review:start:
    stage: review
    retry: 2
    script:
        - pwd
Andreas Böttger's avatar
Andreas Böttger committed
36
        - sudo docker run --detach --rm --env VIRTUAL_HOST=${CI_ENVIRONMENT_SLUG} --name ${DOCKER_CONTAINER_NAME} ${REVIEW_IMAGE} || true
Andreas Böttger's avatar
Andreas Böttger committed
37
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} build
Andreas Böttger's avatar
Andreas Böttger committed
38
        - sudo docker cp ./_book/. ${DOCKER_CONTAINER_NAME}:/usr/share/nginx/html
Andreas Böttger's avatar
Andreas Böttger committed
39
        - if [ ! -z "${REVIEW_CREDENTIALS}" ]; then mkdir -p ./nginx && echo "${REVIEW_CREDENTIALS}" > ./nginx/credentials && sudo docker cp ./nginx/credentials ${DOCKER_CONTAINER_NAME}:/etc/nginx/htpasswd/credentials; rm -f ./nginx/credentials; fi
Andreas Böttger's avatar
Andreas Böttger committed
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
    environment:
        name: review/${CI_COMMIT_REF_NAME}
        url: http://${CI_ENVIRONMENT_SLUG}.collaborating.tuhh.de
        on_stop: review:stop
    only:
        - branches
    tags:
        - development
        - ssg
    except:
        - master

review:stop:
    stage: review
    variables:
        GIT_STRATEGY: none
    script:
        - sudo docker stop ${DOCKER_CONTAINER_NAME}
    when: manual
    environment:
        name: review/${CI_COMMIT_REF_NAME}
        action: stop
    only:
        - branches
    tags:
        - development
        - ssg
    except:
        - master
    
.deploy:
    stage: deploy
    only:
        - master
    retry: 2
    tags:
        - production
    script:
        - pwd
Andreas Böttger's avatar
Andreas Böttger committed
79 80 81
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} install
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} build
        - mkdir -p book_pdf; sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} pdf ./ ./book_pdf/book.pdf
Andreas Böttger's avatar
Andreas Böttger committed
82 83 84 85 86 87 88 89
        - 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
        - sshpass -p "$SSH_PASSWD" scp -P "$SSH_PORT" -r book_pdf $SSH_USER@$HOST_NAME:/usr/share/nginx/html/production
    environment:
        name: production
        #url: http://$HOST_NAME$COLON$HTTP_PORT/production/
        #url: https://$PROXY_HOST_NAME/$BASE_PATH/
        url: https://$PROXY_HOST_NAME/$CI_PROJECT_PATH/