.gitlab-ci.yml 3.62 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
    REVIEW_IMAGE: docker.rz.tu-harburg.de:5000/docker/nginx--review-apps:latest
    BUILD_IMAGE: docker.rz.tu-harburg.de:5000/docker/jekyll-hoou-glr:latest
Andreas Böttger's avatar
Andreas Böttger committed
4 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

stages:
    - review
    - deploy
    
review:start:
    stage: review
Andreas Böttger's avatar
Andreas Böttger committed
17
    retry: 2
Andreas Böttger's avatar
Andreas Böttger committed
18 19
    script:
        - pwd
Andreas Böttger's avatar
Andreas Böttger committed
20
        - 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
21 22
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} install
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} build
Andreas Böttger's avatar
Andreas Böttger committed
23
        - sudo docker cp ./_site/. ${DOCKER_CONTAINER_NAME}:/usr/share/nginx/html
Andreas Böttger's avatar
Andreas Böttger committed
24
        - 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
25 26 27 28 29 30 31 32 33
    environment:
        name: review/${CI_COMMIT_REF_NAME}
        url: http://${CI_ENVIRONMENT_SLUG}.collaborating.tuhh.de
        on_stop: review:stop
    only:
        - branches
    tags:
        - development
        - ssg
Andreas Böttger's avatar
Andreas Böttger committed
34 35
    except:
        - master
Andreas Böttger's avatar
Andreas Böttger committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

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
Andreas Böttger's avatar
Andreas Böttger committed
52 53
    except:
        - master
Andreas Böttger's avatar
Andreas Böttger committed
54 55

deploy:
Andreas Böttger's avatar
Andreas Böttger committed
56 57
    stage: deploy
    only:
Andreas Böttger's avatar
Andreas Böttger committed
58
        - master
Andreas Böttger's avatar
Andreas Böttger committed
59
    except:
Andreas Böttger's avatar
Andreas Böttger committed
60
        - schedules
Andreas Böttger's avatar
Andreas Böttger committed
61
    tags:
Andreas Böttger's avatar
Andreas Böttger committed
62
        - ssg
Andreas Böttger's avatar
Andreas Böttger committed
63 64 65 66
    script:
        - pwd
        # `_layouts/home.html` kann datumsabhängig mit einer Datei aus `backlogs` überschrieben werden
        - find backlog -regextype egrep -regex "backlog/[0-9]{8,8}_.*" | sort | awk -F'/|_' -v date=$(date +%Y%m%d) '{if ($2 <= date) {print("cp backlog/"$2"_home.html _layouts/home.html"); system("cp backlog/"$2"_home.html _layouts/home.html")}}'
Andreas Böttger's avatar
Andreas Böttger committed
67 68
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} install
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} build
Andreas Böttger's avatar
Andreas Böttger committed
69
        # Da `StrictHostKeyChecking no` verwendet wird, ist das Folgende ok :\
Andreas Böttger's avatar
Andreas Böttger committed
70
        - ssh-keygen -f "$HOME/.ssh/known_hosts" -R [@$HOST_NAME]:$SSH_PORT
Andreas Böttger's avatar
Andreas Böttger committed
71 72 73 74 75 76 77 78 79 80 81
        - 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 _site/* $SSH_USER@$HOST_NAME:/usr/share/nginx/html/production
    environment:
        name: production
        url: https://$PROXY_HOST_NAME/
        
deploy:on-schedule:
    stage: deploy
    only:
        - schedules
    tags:
Andreas Böttger's avatar
Andreas Böttger committed
82
        - ssg
Andreas Böttger's avatar
Andreas Böttger committed
83
    script:
Andreas Böttger's avatar
Andreas Böttger committed
84
        - pwd
Andreas Böttger's avatar
Andreas Böttger committed
85
        # `_layouts/home.html` kann datumsabhängig mit einer Datei aus `backlogs` überschrieben werden
Andreas Böttger's avatar
Andreas Böttger committed
86
        - find backlog -regextype egrep -regex "backlog/[0-9]{8,8}_.*" | sort | awk -F'/|_' -v date=$(date +%Y%m%d) '{if ($2 <= date) {print("cp backlog/"$2"_home.html _layouts/home.html"); system("cp backlog/"$2"_home.html _layouts/home.html")}}'
Andreas Böttger's avatar
Andreas Böttger committed
87 88
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} install
        - sudo docker run --rm -v $(pwd):/source ${BUILD_IMAGE} build
Andreas Böttger's avatar
Andreas Böttger committed
89 90 91 92
        - 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 _site/* $SSH_USER@$HOST_NAME:/usr/share/nginx/html/production
    environment:
        name: production
Andreas Böttger's avatar
Andreas Böttger committed
93
        url: https://$PROXY_HOST_NAME/